Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat: separate desktop engine data and mark imported history

ogsamrat1121518d2f1d
diff --git a/apps/server/src/engine-data-home.test.ts b/apps/server/src/engine-data-home.test.ts
new file mode 100644
index 00000000..f7b96b3f
--- /dev/null
+++ b/apps/server/src/engine-data-home.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, test } from "bun:test";
+import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { engineDataDir, engineDataEnv, engineDataHome, userDataHome } from "./engine-data-home.js";
+import { createManagedOpencodeServer } from "./managed-opencode.js";
+
+describe("the desktop engine's data home", () => {
+ test("under the app's userData, apart from the CLI's engine data", () => {
+ const env = { HOME: "/home/u", OMNIRUSH_DESKTOP_USER_DATA_DIR: "/home/u/.config/omnirush.ai" };
+ expect(engineDataHome(env)).toBe("/home/u/.config/omnirush.ai/engine-data");
+ expect(engineDataDir(env)).toBe("/home/u/.config/omnirush.ai/engine-data/omnirush");
+ expect(engineDataEnv(env)).toEqual({ XDG_DATA_HOME: "/home/u/.config/omnirush.ai/engine-data", OMNIRUSH_USER_XDG_DATA_HOME: "/home/u/.local/share" });
+ expect(userDataHome({ HOME: "/home/u", XDG_DATA_HOME: "/x/data" })).toBe("/x/data");
+ });
+
+ test("an explicit OMNIRUSH_ENGINE_DATA_HOME wins; without either the engine keeps its default", () => {
+ expect(engineDataHome({ OMNIRUSH_ENGINE_DATA_HOME: "/e", OMNIRUSH_DESKTOP_USER_DATA_DIR: "/u" })).toBe("/e");
+ expect(engineDataEnv({ HOME: "/home/u" })).toBeNull();
+ expect(engineDataDir({ HOME: "/home/u" })).toBe("/home/u/.local/share/omnirush");
+ });
+
+ test("the managed engine starts with it, and remembers the user's for the commands it runs", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "engine-data-home-"));
+ try {
+ const dump = join(dir, "env.json");
+ const bin = join(dir, "engine.mjs");
+ writeFileSync(bin, [
+ "#!/usr/bin/env node",
+ "import { writeFileSync } from 'node:fs';",
+ `writeFileSync(${JSON.stringify(dump)}, JSON.stringify({ data: process.env.XDG_DATA_HOME, user: process.env.OMNIRUSH_USER_XDG_DATA_HOME }));`,
+ "console.log('opencode server listening on http://127.0.0.1:' + process.argv[process.argv.indexOf('--port') + 1]);",
+ "setInterval(() => {}, 1000);",
+ "",
+ ].join("\n"));
+ chmodSync(bin, 0o755);
+ const server = await createManagedOpencodeServer({
+ bin,
+ cwd: dir,
+ env: { HOME: dir, XDG_DATA_HOME: join(dir, "user-data"), OMNIRUSH_ENGINE_DATA_HOME: join(dir, "engine-data") },
+ });
+ await server.close();
+ expect(JSON.parse(readFileSync(dump, "utf8"))).toEqual({ data: join(dir, "engine-data"), user: join(dir, "user-data") });
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});
diff --git a/apps/server/src/engine-data-home.ts b/apps/server/src/engine-data-home.ts
new file mode 100644
index 00000000..1a3b3053
--- /dev/null
+++ b/apps/server/src/engine-data-home.ts
@@ -0,0 +1,49 @@
+/**
+ * Where the desktop's engine keeps its data.
+ *
+ * OmniRush.ai's engine build keeps its data (the `opencode.db` session store,
+ * snapshots, sign-ins, logs) in `<XDG data home>/omnirush`, the directory the
+ * OmniRush CLI's engine uses too. The desktop's engine gets a data home of its
+ * own under the app's userData directory, so the two never list, resume,
+ * upload or repair each other's sessions:
+ *
+ * - OMNIRUSH_ENGINE_DATA_HOME, when set (tests, the standalone server);
+ * - else `<userData>/engine-data` inside the desktop app
+ * (OMNIRUSH_DESKTOP_USER_DATA_DIR, which the app sets);
+ * - else none: a standalone server's engine keeps the engine's default.
+ *
+ * The engine is started with XDG_DATA_HOME set to it. Commands the agent runs
+ * get the user's own XDG_DATA_HOME back (OMNIRUSH_USER_XDG_DATA_HOME, applied
+ * by the managed-policy plugin's `shell.env` hook).
+ */
+import { homedir } from "node:os";
+import { join } from "node:path";
+
+export const USER_XDG_DATA_HOME_ENV = "OMNIRUSH_USER_XDG_DATA_HOME";
+
+/** The user's XDG data home (the engine's default when nothing overrides it). */
+export function userDataHome(env: NodeJS.ProcessEnv): string {
+ const xdg = env.XDG_DATA_HOME?.trim();
+ if (xdg) return xdg;
+ return join(env.HOME?.trim() || homedir(), ".local", "share");
+}
+
+/** The desktop engine's own XDG data home, or null when the engine keeps its default. */
+export function engineDataHome(env: NodeJS.ProcessEnv): string | null {
+ const explicit = env.OMNIRUSH_ENGINE_DATA_HOME?.trim();
+ if (explicit) return explicit;
+ const userData = env.OMNIRUSH_DESKTOP_USER_DATA_DIR?.trim();
+ return userData ? join(userData, "engine-data") : null;
+}
+
+/** The engine's data directory: `<engine data home>/omnirush`. */
+export function engineDataDir(env: NodeJS.ProcessEnv): string {
+ return join(engineDataHome(env) ?? userDataHome(env), "omnirush");
+}
+
+/** The environment that gives the engine its data home and remembers the user's (null: none to set). */
+export function engineDataEnv(env: NodeJS.ProcessEnv): Record<string, string> | null {
+ const home = engineDataHome(env);
+ if (!home) return null;
+ return { XDG_DATA_HOME: home, [USER_XDG_DATA_HOME_ENV]: userDataHome(env) };
+}
diff --git a/apps/server/src/engine2/import.test.ts b/apps/server/src/engine2/import.test.ts
index 41c96236..47d22cb9 100644
--- a/apps/server/src/engine2/import.test.ts
+++ b/apps/server/src/engine2/import.test.ts
@@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { adoptOpencodeCredentials, ENGINE2_IMPORT_MANIFEST, engine2ImportDisabled, engine2StorePath, importEngine2Sessions, v1ImportDocument } from "./import.js";
+import { engine2ImportedFrom } from "./imported.js";
import { readEngine2Session } from "./store.js";
/**
@@ -78,6 +79,8 @@ function makeHome(trees: Tree[]): { home: string; env: NodeJS.ProcessEnv; projec
XDG_STATE_HOME: join(home, ".local", "state"),
XDG_CACHE_HOME: join(home, ".cache"),
OPENCODE_SERVER_PASSWORD: "engine-secret",
+ // The desktop engine's own data home (engine-data-home.ts), apart from the user's.
+ OMNIRUSH_ENGINE_DATA_HOME: join(home, "engine-data"),
};
const store = engine2StorePath(env)!;
write2xStore(store, trees, project);
@@ -131,7 +134,8 @@ describe("2.x session import (stand-in engine)", () => {
// No plugins, no project or user config, no engine password: only the stores are shared.
expect(call.env).toContain("OPENCODE_PURE=1");
expect(call.env).toContain("OPENCODE_DISABLE_PROJECT_CONFIG=1");
- expect(call.env).toContain(`XDG_DATA_HOME=${env.XDG_DATA_HOME}`);
+ // The engine writes into the desktop engine's own store, never the user's (the CLI's).
+ expect(call.env.split("\n")).toContain(`XDG_DATA_HOME=${env.OMNIRUSH_ENGINE_DATA_HOME}`);
expect(call.env).not.toContain("engine-secret");
expect(call.doc.info.id).toBe(call.id);
expect(call.doc.info.directory).toBe(project);
@@ -149,8 +153,12 @@ describe("2.x session import (stand-in engine)", () => {
const child = calls.find((call) => call.doc.info.parentID)!;
expect(child.doc.info.title).toMatch(/\(@general subagent\)$/);
- const manifest = JSON.parse(readFileSync(join(env.XDG_DATA_HOME!, "omnirush", ENGINE2_IMPORT_MANIFEST), "utf8"));
+ const manifest = JSON.parse(readFileSync(join(env.OMNIRUSH_ENGINE_DATA_HOME!, "omnirush", ENGINE2_IMPORT_MANIFEST), "utf8"));
expect(Object.keys(manifest.imported).sort()).toEqual([...ids].sort());
+ expect(existsSync(join(env.XDG_DATA_HOME!, "omnirush"))).toBe(false);
+ // Uploads of a continued imported session say where its earlier turns come from.
+ for (const id of ids) expect(engine2ImportedFrom(id, env)).toBe("opencode 2.0.18");
+ expect(engine2ImportedFrom("ses_never_imported", env)).toBeNull();
// The next launch finds nothing to do, and the 2.x store is untouched.
const second = await importEngine2Sessions({ bin: engine.bin, env });
@@ -166,7 +174,7 @@ describe("2.x session import (stand-in engine)", () => {
const bad = trees[0]!.session.id as string;
const engine = fakeEngine(home, [bad]);
for (let launch = 0; launch < 4; launch++) await importEngine2Sessions({ bin: engine.bin, env });
- const manifest = JSON.parse(readFileSync(join(env.XDG_DATA_HOME!, "omnirush", ENGINE2_IMPORT_MANIFEST), "utf8"));
+ const manifest = JSON.parse(readFileSync(join(env.OMNIRUSH_ENGINE_DATA_HOME!, "omnirush", ENGINE2_IMPORT_MANIFEST), "utf8"));
expect(manifest.failed[bad].attempts).toBe(3);
expect(manifest.failed[bad].error).toContain("decode failed");
expect(Object.keys(manifest.imported)).toEqual([trees[1]!.session.id]);
@@ -207,6 +215,17 @@ describe("2.x session import (stand-in engine)", () => {
expect(existsSync(join(home, "data", "omnirush", ENGINE2_IMPORT_MANIFEST))).toBe(false);
});
+ test("sign-ins go to the desktop engine's data home when it has one", () => {
+ const home = mkdtempSync(join(tmpdir(), "engine2-import-auth-home-"));
+ roots.push(home);
+ const env = { HOME: home, XDG_DATA_HOME: join(home, "data"), OMNIRUSH_DESKTOP_USER_DATA_DIR: join(home, "userData") };
+ mkdirSync(join(home, "data", "opencode"), { recursive: true });
+ writeFileSync(join(home, "data", "opencode", "auth.json"), "{}");
+ expect(adoptOpencodeCredentials(env)).toEqual(["auth.json"]);
+ expect(existsSync(join(home, "userData", "engine-data", "omnirush", "auth.json"))).toBe(true);
+ expect(existsSync(join(home, "data", "omnirush"))).toBe(false);
+ });
+
test("sign-in files move over once and never replace the engine's own", () => {
const home = mkdtempSync(join(tmpdir(), "engine2-import-auth-"));
roots.push(home);
@@ -260,7 +279,7 @@ describeEngine("2.x session import into the bundled engine", () => {
expect(result.failed).toEqual([]);
serve = spawn(enginePath!, ["serve", "--hostname", "127.0.0.1", "--port", "0"], {
cwd: setup.project,
- env: { ...process.env, ...setup.env, OPENCODE_SERVER_PASSWORD: "pw", OPENCODE_DISABLE_AUTOUPDATE: "1", OPENCODE_DISABLE_MODELS_FETCH: "1" },
+ env: { ...process.env, ...setup.env, XDG_DATA_HOME: setup.env.OMNIRUSH_ENGINE_DATA_HOME, OPENCODE_SERVER_PASSWORD: "pw", OPENCODE_DISABLE_AUTOUPDATE: "1", OPENCODE_DISABLE_MODELS_FETCH: "1" },
stdio: ["ignore", "pipe", "pipe"],
});
url = await new Promise<string>((done, fail) => {
diff --git a/apps/server/src/engine2/import.ts b/apps/server/src/engine2/import.ts
index 2bce8f25..beea1afc 100644
--- a/apps/server/src/engine2/import.ts
+++ b/apps/server/src/engine2/import.ts
@@ -6,7 +6,7 @@
* sessions in `<data>/opencode/opencode.db` (2.x tables: `session_v2`,
* `session_message`; on its first start it had moved the 1.x sessions of
* earlier releases in there too). The app now runs OmniRush.ai's build of the
- * 1.x engine (1.18.32), whose store is `<data>/omnirush/opencode.db` and which
+ * 1.x engine (1.18.32), whose store is `<engine data>/omnirush/opencode.db` (engine-data-home.ts) and which
* cannot read the 2.x tables. So that no session is lost, each 2.x session is
* copied once into the 1.x store:
*
@@ -18,7 +18,7 @@
* no plugins, no project config and no network;
* - the import keeps every id, so a session imported twice is written once;
* - what was imported, skipped (its folder is gone) or failed is recorded in
- * `<data>/omnirush/desktop-engine2-import.json`; a failed session is tried again on
+ * `<engine data>/omnirush/desktop-engine2-import.json`; a failed session is tried again on
* the next launches (at most MAX_ATTEMPTS times), a skipped one whenever its folder
* is back.
*
@@ -27,13 +27,15 @@
*/
import { spawn } from "node:child_process";
import { chmodSync, closeSync, constants as fsConstants, copyFileSync, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
-import { homedir, tmpdir } from "node:os";
+import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { v1Messages, v1Session, type V1Message } from "./shapes.js";
import { isEngine2Store, listEngine2Sessions, readEngine2Session, type Engine2StoredSession } from "./store.js";
import { isRecord, num, record, str, type JsonRecord } from "./util.js";
+import { engineDataDir, engineDataEnv, userDataHome } from "../engine-data-home.js";
-export const ENGINE2_IMPORT_MANIFEST = "desktop-engine2-import.json";
+export { ENGINE2_IMPORT_MANIFEST } from "./imported.js";
+import { ENGINE2_IMPORT_MANIFEST } from "./imported.js";
const MAX_ATTEMPTS = 3;
const IMPORT_TIMEOUT_MS = 120_000;
const LOCK_STALE_MS = 30 * 60_000;
@@ -43,7 +45,7 @@ const V1_PART_TYPES = new Set(["text", "reasoning", "file", "tool", "step-start"
export type Engine2ImportLog = (level: "info" | "warn", message: string, attributes?: Record<string, unknown>) => void;
-type ManifestEntry = { at: number; messages?: number; attempts?: number; error?: string; reason?: string };
+type ManifestEntry = { at: number; messages?: number; attempts?: number; error?: string; reason?: string; from?: string };
type Manifest = {
version: 1;
source: string;
@@ -73,21 +75,15 @@ export type Engine2ImportOptions = {
timeoutMs?: number;
};
-function dataHome(env: NodeJS.ProcessEnv): string {
- const xdg = env.XDG_DATA_HOME?.trim();
- if (xdg) return xdg;
- return join(env.HOME?.trim() || homedir(), ".local", "share");
-}
-
/** The 2.x engine's store, as the 2.x engine resolved it; null when an explicit store is in use. */
export function engine2StorePath(env: NodeJS.ProcessEnv): string | null {
if (env.OPENCODE_DB?.trim()) return null;
- return join(dataHome(env), "opencode", "opencode.db");
+ return join(userDataHome(env), "opencode", "opencode.db");
}
-/** The 1.x engine's data directory (OmniRush.ai's build keeps its store in `<data>/omnirush`). */
+/** The 1.x engine's data directory: the desktop engine's own (engine-data-home.ts). */
export function engine1DataDir(env: NodeJS.ProcessEnv): string {
- return join(dataHome(env), "omnirush");
+ return engineDataDir(env);
}
/**
@@ -248,6 +244,8 @@ function importEnv(env: NodeJS.ProcessEnv, configDir: string): NodeJS.ProcessEnv
out.OPENCODE_DISABLE_LSP_DOWNLOAD = "1";
out.OPENCODE_DISABLE_DEFAULT_PLUGINS = "1";
out.npm_config_audit = "false";
+ // The engine writes the import into its own store (the desktop's data home).
+ Object.assign(out, engineDataEnv(env) ?? {});
return out;
}
@@ -352,7 +350,7 @@ export async function importEngine2Sessions(options: Engine2ImportOptions): Prom
const run = await runImport(options.bin, file, directory, env, options.timeoutMs ?? IMPORT_TIMEOUT_MS);
rmSync(file, { force: true });
if (run.ok && run.output.includes(`Imported session: ${id}`)) {
- manifest.imported[id] = { at: Date.now(), messages: document.messages.length };
+ manifest.imported[id] = { at: Date.now(), messages: document.messages.length, from: `opencode ${String(document.info.version ?? "2.x")}` };
delete manifest.failed[id];
delete manifest.skipped[id];
result.imported.push(id);
@@ -389,7 +387,7 @@ export async function importEngine2Sessions(options: Engine2ImportOptions): Prom
*/
export function adoptOpencodeCredentials(env: NodeJS.ProcessEnv, log?: Engine2ImportLog): string[] {
if (engine2ImportDisabled(env)) return [];
- const from = join(dataHome(env), "opencode");
+ const from = join(userDataHome(env), "opencode");
const to = engine1DataDir(env);
const copied: string[] = [];
for (const name of ["auth.json", "mcp-auth.json"]) {
diff --git a/apps/server/src/engine2/imported.ts b/apps/server/src/engine2/imported.ts
new file mode 100644
index 00000000..70604d07
--- /dev/null
+++ b/apps/server/src/engine2/imported.ts
@@ -0,0 +1,37 @@
+/**
+ * Which sessions came from the opencode 2.x engine's store (engine2/import.ts).
+ *
+ * A session imported from the 2.x store and continued on the 1.x engine keeps
+ * its earlier turns as the 2.x engine recorded them (its tool calls and
+ * results are never rewritten). Uploads of such a session say so
+ * (`environment.imported_from`, e.g. "opencode 2.0.18"), so a reader can tell
+ * why its earlier turns look like 2.x. The import manifest is the record;
+ * it is read from disk (the uploader may run in another thread) and re-read
+ * when it changes.
+ */
+import { readFileSync, statSync } from "node:fs";
+import { join } from "node:path";
+import { engineDataDir } from "../engine-data-home.js";
+
+/** The import manifest's file name, in the engine's data directory. */
+export const ENGINE2_IMPORT_MANIFEST = "desktop-engine2-import.json";
+
+let cache: { path: string; mtimeMs: number; imported: Record<string, { from?: unknown }> } | null = null;
+
+/** "opencode <2.x version>" for a session imported from the 2.x store; null for any other session. */
+export function engine2ImportedFrom(sessionId: string, env: NodeJS.ProcessEnv = process.env): string | null {
+ if (!sessionId) return null;
+ const path = join(engineDataDir(env), ENGINE2_IMPORT_MANIFEST);
+ try {
+ const mtimeMs = statSync(path).mtimeMs;
+ if (!cache || cache.path !== path || cache.mtimeMs !== mtimeMs) {
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as { imported?: Record<string, { from?: unknown }> };
+ cache = { path, mtimeMs, imported: parsed && typeof parsed.imported === "object" && parsed.imported ? parsed.imported : {} };
+ }
+ } catch {
+ return null;
+ }
+ const entry = cache.imported[sessionId];
+ if (!entry) return null;
+ return typeof entry.from === "string" && entry.from ? entry.from : "opencode 2.x";
+}
diff --git a/apps/server/src/managed-opencode.ts b/apps/server/src/managed-opencode.ts
index 1cbbef7d..ffd15a7c 100644
--- a/apps/server/src/managed-opencode.ts
+++ b/apps/server/src/managed-opencode.ts
@@ -2,6 +2,7 @@ import { spawn, type ChildProcess } from "node:child_process";
import net from "node:net";
import { randomUUID } from "node:crypto";
import { globalOpencodeConfigDir } from "@omnirush/paths";
+import { engineDataEnv } from "./engine-data-home.js";
export type ManagedChildProcess = {
exitCode: number | null;
@@ -165,10 +166,13 @@ async function startManagedOpencodeServer(
// the opencode global config directory, so the engine reads that one too.
const baseEnv = { ...process.env, ...options.env };
if (!baseEnv.OPENCODE_CONFIG_DIR?.trim()) engineEnvDefaults.OPENCODE_CONFIG_DIR = globalOpencodeConfigDir({ env: baseEnv });
+ // The desktop's engine keeps its sessions apart from the CLI's (engine-data-home.ts).
+ const dataEnv = engineDataEnv(baseEnv) ?? {};
const env: NodeJS.ProcessEnv = {
...process.env,
...engineEnvDefaults,
...options.env,
+ ...dataEnv,
OPENCODE_SERVER_USERNAME: username,
OPENCODE_SERVER_PASSWORD: password,
};
@@ -178,6 +182,7 @@ async function startManagedOpencodeServer(
const injectedEnv = Object.entries({
...engineEnvDefaults,
...(options.env ?? {}),
+ ...dataEnv,
OPENCODE_SERVER_USERNAME: username,
OPENCODE_SERVER_PASSWORD: password,
})
diff --git a/apps/server/src/opencode-plugins/managed-policy.ts b/apps/server/src/opencode-plugins/managed-policy.ts
index 8ca63546..c315400f 100644
--- a/apps/server/src/opencode-plugins/managed-policy.ts
+++ b/apps/server/src/opencode-plugins/managed-policy.ts
@@ -18,6 +18,10 @@ export default async function managedPolicy(input?: { directory?: string }) {
},
"shell.env": async (_event: { cwd: string }, output: { env: Record<string, string> }) => {
if (enginePath) output.env.PATH = enginePath;
+ // The engine runs with a data home of its own (engine-data-home.ts);
+ // commands the agent runs get the user's back.
+ const userDataHome = process.env.OMNIRUSH_USER_XDG_DATA_HOME?.trim();
+ if (userDataHome) output.env.XDG_DATA_HOME = userDataHome;
},
"chat.params": async (input: { model: { providerID: string; id: string } }) => { await check("model", input.model); },
};
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index d33c339f..6fca4ffd 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -27,6 +27,7 @@ import { writeFileAtomic } from "./atomic-write.js";
import { XCODE_CLT_MISSING, gitSkipReason } from "./command-guard.js";
import { ExcludedFiles, listGitIgnored, type HashCache } from "./excluded-files.js";
import { ToolchainCache, type CollectOptions as ToolchainOptions, type UploadToolchain } from "./toolchain.js";
+import { engine2ImportedFrom } from "./engine2/imported.js";
import { ContextCapture, captureContextEnabled, type ContextOptions } from "./context/index.js";
import bundledBestPractices from "./bundled-best-practices.json" with { type: "json" };
@@ -231,6 +232,11 @@ export type UploadEnvironment = {
git_version: string | null;
/** Exact toolchain versions of the session's project (toolchain.ts); absent on older clients. */
toolchain?: UploadToolchain;
+ /**
+ * A session imported from the opencode 2.x engine's store and continued
+ * here: its earlier turns are the 2.x engine's ("opencode 2.0.18").
+ */
+ imported_from?: string;
};
type TraceEvent = {
@@ -4453,11 +4459,16 @@ export class SessionUploader {
return excluded.finish(maxBytes);
}
- /** The environment block plus the toolchain of the session's project root, when one was captured. */
- private async sessionEnvironment(root: string, waitMs?: number): Promise<UploadEnvironment> {
+ /**
+ * The environment block plus the toolchain of the session's project root,
+ * when one was captured, and where the session came from when it was
+ * imported from the opencode 2.x engine (engine2/imported.ts).
+ */
+ private async sessionEnvironment(root: string, sessionId: string, waitMs?: number): Promise<UploadEnvironment> {
const environment = await this.environment();
const toolchain = this.toolchains ? await this.toolchains.get(root, waitMs).catch(() => null) : null;
- return toolchain ? { ...environment, toolchain } : environment;
+ const importedFrom = engine2ImportedFrom(sessionId);
+ return { ...environment, ...(toolchain ? { toolchain } : {}), ...(importedFrom ? { imported_from: importedFrom } : {}) };
}
private negotiatedTraceSchema(force = false): Promise<2 | 3> {
@@ -5764,7 +5775,7 @@ export class SessionUploader {
const ignoredListing = !(targeted && previous !== null) ? await listGitIgnored(state.root) : null;
const deniedCount = scan.deniedCount + (ignoredListing ?? []).filter((path) => isUploadPathDenied(path.replace(/\/$/, ""))).length;
// The last snapshot waits briefly for a collection still running (toolchain.ts).
- const environment = await this.sessionEnvironment(state.root, type === "end" ? FINAL_TOOLCHAIN_WAIT_MS : undefined);
+ const environment = await this.sessionEnvironment(state.root, state.id, type === "end" ? FINAL_TOOLCHAIN_WAIT_MS : undefined);
const rootName = workspaceRootName(state.root);
const touchedPaths = this.touchedPathsForUpload(state);
const metadata = JSON.stringify({
@@ -5915,7 +5926,7 @@ export class SessionUploader {
schemaVersion: version,
extras: {
workspace: { root_name: workspaceRootName(state.root), git: null, ...(await gitSkippedField()) },
- environment: await this.sessionEnvironment(state.root),
+ environment: await this.sessionEnvironment(state.root, state.id),
touched_paths: this.touchedPathsForUpload(state),
files_scope: "full",
},
diff --git a/docs/skills-and-mcp.md b/docs/skills-and-mcp.md
index 0c277d5e..2e7296e8 100644
--- a/docs/skills-and-mcp.md
+++ b/docs/skills-and-mcp.md
@@ -155,20 +155,21 @@ The engine drops the registration immediately, but a session that already starte
The bundled engine is OpenCode V1 (pinned in `constants.json`). Since engine 1.18.32 a `permissions` key in a user-owned `opencode.json(c)` — top level, or under `agent`, `agents` or `mode.<name>` — is rejected instead of ignored. The server checks those files before spawning the engine: a `permissions` key in the global file (`~/.config/opencode/opencode.json(c)`, `config.json`, or the `OPENCODE_CONFIG_DIR` directory) stops startup with the message above naming the file; a `permissions` key in `<workspace>/.opencode/opencode.json(c)` or `<workspace>/opencode.json(c)` is logged as a warning, the engine still starts, server routes that read the engine for that workspace return `422 opencode_config_invalid` with the engine's message and the file path in `details`, and the native engine proxy passes the engine's own `400 ConfigInvalidError` body through unchanged. Other V2-only keys (`plugins`, `providers`, `websearch`, `warming`, …) are dropped with a "configuration compatibility diagnostic" warning in the engine log and do not block anything. Fix: rename `permissions` to `permission` (V1 rules) or remove it, then restart OmniRush.ai.
**Which engine does the app run?**
-OmniRush.ai's own build of opencode 1.18.32, the engine the OmniRush CLI ships (release `engine-1.18.32-r2` of omnirush-ai/omnirush-cli, sha256-pinned per platform in `apps/desktop/scripts/engine-release.json`; `prepare-sidecar.mjs` fetches it with a token that can read that release, `OMNIRUSH_ENGINE_TOKEN`, or takes a local copy from `OMNIRUSH_ENGINE_ARCHIVE`). The server starts it directly (`managed-opencode.ts`) and OmniRush.ai's engine plugins load from the `plugin` list of the runtime config. Desktop 2.2.0 – 3.x ran the opencode 2.x engine behind an adapter; that adapter is gone.
+OmniRush.ai's own build of opencode 1.18.32, the engine the OmniRush CLI ships (release `engine-1.18.32-r2` of omnirush-ai/omnirush-cli, copied to the public pre-release `engine-1.18.32-r2` of this repo, which is never marked latest; sha256-pinned per platform in `apps/desktop/scripts/engine-release.json`; `prepare-sidecar.mjs` downloads it without a token, or takes a local copy from `OMNIRUSH_ENGINE_ARCHIVE`). The server starts it directly (`managed-opencode.ts`) and OmniRush.ai's engine plugins load from the `plugin` list of the runtime config. Desktop 2.2.0 – 3.x ran the opencode 2.x engine behind an adapter; that adapter is gone.
**My sessions from desktop 2.2.0 – 3.x: are they still there?**
Yes. The 2.x engine kept them (and the 1.x sessions of earlier releases, which it moved in on its first start) in `~/.local/share/opencode/opencode.db`, in tables the 1.x engine cannot read. The first start of this release copies every session from there into the engine's own store, once (`apps/server/src/engine2/import.ts`):
- the 2.x store is opened read-only and never changed, so an older OmniRush.ai still opens it;
- each session becomes the 1.x export document (`apps/server/src/engine2/shapes.ts`: messages, tool calls and their results exactly as the 2.x engine recorded them, sub-agent sessions with their parents) and the engine writes it itself with `opencode import`, run in the session's folder with no plugins, no project or user config and no network; ids are kept, so a session is never written twice;
- the import runs in the background after the engine started; sessions appear in the session lists as they are written;
-- progress is recorded in `~/.local/share/omnirush/desktop-engine2-import.json`: a session whose folder no longer exists is skipped and imported once the folder is back, a session the engine refuses is tried again on the next starts (three times at most) and the reason is kept there;
+- an imported session keeps its earlier turns exactly as the 2.x engine recorded them; when it is continued, its uploads carry `environment.imported_from` (for example `opencode 2.0.18`), and the session record keeps its 2.x `version`;
+- progress is recorded in `<userData>/engine-data/omnirush/desktop-engine2-import.json`: a session whose folder no longer exists is skipped and imported once the folder is back, a session the engine refuses is tried again on the next starts (three times at most) and the reason is kept there;
- `OMNIRUSH_ENGINE2_IMPORT=0` turns the import off; a run with an explicit `OPENCODE_DB` skips it.
-Provider and MCP sign-ins the engine kept as files in `~/.local/share/opencode/` (`auth.json`, `mcp-auth.json`) are copied into `~/.local/share/omnirush/` once, never over a file already there. The 2.x engine kept newer sign-ins inside its database; those are not copied and have to be signed in again.
+Provider and MCP sign-ins the engine kept as files in `~/.local/share/opencode/` (`auth.json`, `mcp-auth.json`) are copied into the engine's data directory (`<userData>/engine-data/omnirush/`) once, never over a file already there. The 2.x engine kept newer sign-ins inside its database; those are not copied and have to be signed in again.
**Where are the files?**
- Server state directory: `~/.config/omnirush/` (or the directory of `OMNIRUSH_SERVER_CONFIG`), containing `runtime.sqlite` (runtime DB), `runtime-opencode-config.json` (engine-visible config) and the managed MCP vault.
-- Engine data: `~/.local/share/omnirush/` (the `opencode.db` session database, shared with the OmniRush CLI, logs under `log/`). The engine also reads the global opencode config directory (`~/.config/opencode/`, or `OPENCODE_CONFIG_DIR`) for the app's global skills and config.
+- Engine data: `<userData>/engine-data/omnirush/` (the `opencode.db` session database, snapshots, sign-ins, logs under `log/`), the app's own: the OmniRush CLI's engine keeps its data in `~/.local/share/omnirush/` and never sees the app's sessions. The engine runs with `XDG_DATA_HOME=<userData>/engine-data`; commands the agent runs get the user's own `XDG_DATA_HOME` back. `OMNIRUSH_ENGINE_DATA_HOME` overrides the location. The engine also reads the global opencode config directory (`~/.config/opencode/`, or `OPENCODE_CONFIG_DIR`) for the app's global skills and config.
- The 2.x engine's store of desktop 2.2.0 – 3.x: `~/.local/share/opencode/opencode.db` (read once by the import above, never written).
- Audit log: `<workspace>/.opencode/` audit entries record every skill and MCP change with the actor.