A desktop coding agent with free access to frontier models.
TypeScript
fix: steadier project details in the app
ogsamrat890f8986b52e
diff --git a/apps/server/src/capture-context.test.ts b/apps/server/src/capture-context.test.tsindex bed233a7..92417f9d 100644--- a/apps/server/src/capture-context.test.ts+++ b/apps/server/src/capture-context.test.ts@@ -210,10 +210,10 @@ test.skipIf(process.platform !== "linux")("#19 snapshot: dev processes with scruconst server = net.createServer().listen(0, "127.0.0.1");await new Promise((resolve) => server.once("listening", resolve));const port = server.address().port;- const child = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", `--token=${GH_TOKEN}`, `--password`, PASSWORD, `AWS_SECRET_ACCESS_KEY=${AWS_SECRET}`], { stdio: "ignore" });+ const child = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", `--token=${GH_TOKEN}`, `--password`, PASSWORD, `AWS_SECRET_ACCESS_KEY=${AWS_SECRET}`], { stdio: "ignore", env: { ...process.env, OMNIRUSH_SESSION: "ses_snapshot_own" } });try {await new Promise((resolve) => setTimeout(resolve, 200));- const snapshot = await processes.processSnapshot("turn_start", 3, { privacy: privacy.currentPrivacy(), scrub: SCRUB });+ const snapshot = await processes.processSnapshot("turn_start", 3, { privacy: privacy.currentPrivacy(), scrub: SCRUB, scope: { rootPid: process.pid, folders: () => [], sessionId: "ses_snapshot_own" } });assert.equal(snapshot.phase, "turn_start");assert.equal(snapshot.turn, 3);const mine = snapshot.processes.find((entry) => entry.pid === child.pid);@@ -272,7 +272,8 @@ test("#19 in a box: the box's processes and listening ports, through its runner;assert.equal(snapshot.method, "box-ps+box-proc");assert.deepEqual(snapshot.processes.map((entry) => entry.pid).sort(), [40, 41], "the helper and every OmniRush probe (OMNIRUSH_LEDGER_OFF=1) left out");assert.ok(snapshot.processes.every((entry) => entry.scope === "session"));- assert.ok(snapshot.processes.find((entry) => entry.pid === 41)!.command.includes("--token=[REDACTED]"));+ // The box serves every chat of its project: no process there is known to be this session's, so none keeps its arguments.+ assert.ok(snapshot.processes.every((entry) => entry.command === ""));assert.equal(snapshot.processes.find((entry) => entry.pid === 41)!.cwd, "~/app/web", "the working folder, home as ~");assertNoSecrets(snapshot);const ports = snapshot.listening.map((entry) => [entry.port, "address" in entry ? entry.address : undefined, "pid" in entry ? entry.pid : undefined]);@@ -942,9 +943,13 @@ test("#19 privacy: only the session's process tree and processes in its foldersscrub: SCRUB,selfPid: 100,precomputed: { processes: table, listening },- scope: { rootPid: 100, folders: () => [project] },+ scope: { rootPid: 100, folders: () => [project], sessionId: "ses_mine" },cwdOf: async (pids) => new Map(pids.map((pid) => [pid, pid === 202 ? path.join(project, "web") : "/home/other/telegram-bot"])),+ // The shell call of this session (OMNIRUSH_SESSION in its environment); the folder's vite is nobody's known.+ sessionOf: async () => new Map([[102, "ses_mine"]]),});+ assert.equal(snapshot.processes.find((p) => p.pid === 103)!.command, "node server.js", "what the session's call started keeps its command");+ assert.equal(snapshot.processes.find((p) => p.pid === 202)!.command, "", "a process only working in the folder keeps no arguments");assert.deepEqual(snapshot.processes.map((p) => [p.pid, p.scope]), [[102, "session"], [103, "session"], [202, "folder"]]);assert.ok(snapshot.processes.find((p) => p.pid === 102).command.includes("--token=[REDACTED]"));assert.deepEqual(snapshot.listening, [@@ -958,11 +963,11 @@ test("#19 privacy: only the session's process tree and processes in its folders});test.skipIf(process.platform !== "linux")("#19 privacy, live (Linux): the snapshot lists this process's children, never another account's or an unrelated process", async () => {- const child = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", "child-marker"], { stdio: "ignore" });+ const child = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", "child-marker"], { stdio: "ignore", env: { ...process.env, OMNIRUSH_SESSION: "ses_live_own" } });const outsider = spawn("/bin/sh", ["-c", "exec sleep 20"], { stdio: "ignore", detached: true });try {await new Promise((resolve) => setTimeout(resolve, 200));- const snapshot = await processes.processSnapshot("turn_start", 1, { privacy: privacy.currentPrivacy(), scrub: SCRUB, scope: { rootPid: process.pid, folders: () => [] } });+ const snapshot = await processes.processSnapshot("turn_start", 1, { privacy: privacy.currentPrivacy(), scrub: SCRUB, scope: { rootPid: process.pid, folders: () => [], sessionId: "ses_live_own" } });assert.ok(snapshot.processes.some((p) => p.pid === child.pid && p.command.includes("child-marker")));const pids = new Set(snapshot.processes.map((p) => p.pid));const all = await processes.linuxProcesses();@@ -1114,3 +1119,52 @@ test.skipIf(!hasZstd)("uploader: the turn's last messages (the final flush, notconst tools = traceEventsOf(envelopes).filter((e) => e.type === "context.ephemeral_tool").map((e) => e.data);assert.deepEqual(tools.map((t) => [t.tool_call_id, t.package, t.version, t.resolved]), [["call-cow", "cowsay", "1.6.0", "exact"]]);});++test("#19 raw: another chat's prompt in an unrelated process's arguments never reaches this session; the session's own call keeps its full command line", { skip: process.platform !== "linux" }, async () => {+ const rules = await import("./context/redact-policy.js");+ const leak = `RAWLEAK-${(await import("node:crypto")).randomUUID()}`;+ const project = tmp("rawleak-proj");+ const other = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", "--prompt", leak], { stdio: "ignore", cwd: project, env: { ...process.env, OMNIRUSH_SESSION: "ses_other_chat" } });+ const loose = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", "--prompt", `${leak}-loose`], { stdio: "ignore", cwd: project, detached: true });+ const own = spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", `--token=${GH_TOKEN}`, "own-marker"], { stdio: "ignore", env: { ...process.env, OMNIRUSH_SESSION: "ses_raw_own" } });+ try {+ await new Promise((resolve) => setTimeout(resolve, 300));+ const snapshot = await rules.withRedactionPolicy("client-raw", () => processes.processSnapshot("turn_start", 1, {+ privacy: privacy.currentPrivacy(), scrub: SCRUB, scope: { rootPid: process.pid, folders: () => [project], sessionId: "ses_raw_own" },+ }));+ const stored = JSON.stringify(SCRUB.json(snapshot));+ assert.ok(!stored.includes(leak), "the other chat's prompt is nowhere in the session's data");+ assert.ok(snapshot.processes.some((p) => p.pid === other.pid && p.command === ""), "another chat's process: name and pid only");+ const mine = snapshot.processes.find((p) => p.pid === own.pid);+ assert.ok(mine && mine.command.includes(`--token=${GH_TOKEN} own-marker`), "the session's own call, its full command line as run");+ } finally {+ other.kill();+ loose.kill();+ own.kill();+ }+});++test("#19 raw: a process another session names stays out with its whole subtree, even when this session's own call started it", { skip: process.platform !== "linux" }, async () => {+ const rules = await import("./context/redact-policy.js");+ const uuid = (await import("node:crypto")).randomUUID();+ const secret = `OTHER-CHAT-SECRET-${uuid}`;+ const deeper = `OTHER-CHAT-DEEPER-${uuid}`;+ // The other chat's process starts an untagged child of its own (OMNIRUSH_SESSION removed).+ // The secrets travel in the environment (never captured), so no ancestor's own arguments carry them.+ const otherScript = `const { spawn } = require("child_process"); const env = { ...process.env }; delete env.OMNIRUSH_SESSION; spawn(process.execPath, ["-e", "setTimeout(()=>{}, 20000)", "--", "--prompt", process.env.NESTED_DEEPER], { env, stdio: "ignore" }); setTimeout(()=>{}, 20000);`;+ // This session's call starts a process tagged with another chat.+ const ownScript = `const { spawn } = require("child_process"); spawn(process.execPath, ["-e", process.env.NESTED_SCRIPT, "--", "--prompt", process.env.NESTED_SECRET], { env: { ...process.env, OMNIRUSH_SESSION: "ses_other_nested" }, stdio: "ignore" }); setTimeout(()=>{}, 20000);`;+ const own = spawn(process.execPath, ["-e", ownScript, "--", "own-nested-marker"], { stdio: "ignore", detached: true, env: { ...process.env, OMNIRUSH_SESSION: "ses_nested_own", NESTED_SCRIPT: otherScript, NESTED_SECRET: secret, NESTED_DEEPER: deeper } });+ try {+ await new Promise((resolve) => setTimeout(resolve, 600));+ const snapshot = await rules.withRedactionPolicy("client-raw", () => processes.processSnapshot("turn_start", 1, {+ privacy: privacy.currentPrivacy(), scrub: SCRUB, scope: { rootPid: process.pid, folders: () => [], sessionId: "ses_nested_own" },+ }));+ const stored = JSON.stringify(SCRUB.json(snapshot));+ assert.ok(stored.includes("own-nested-marker"), "the session's own call keeps its command line");+ assert.ok(!stored.includes(secret), "a child another session names keeps no arguments");+ assert.ok(!stored.includes(deeper), "nor does anything below it");+ } finally {+ try { process.kill(-own.pid); } catch { /* gone */ }+ }+});diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256index e4526c87..f421b44f 100644--- a/apps/server/src/context/PARITY.sha256+++ b/apps/server/src/context/PARITY.sha256@@ -3,7 +3,7 @@b7d4fad94c133cb4303db934a5bb8e84dcb09dcc6720dc9cc7245d7c8205fa11 commands.tse13f86577014b52affc4c2336630eedcac277b974939c6741119a62b7fda439b ephemeral.ts5f89ff17f225ac47700d31f34c358591c8fbde794a45c156d607e5a675a2ba73 exec.ts-0daba6d1987b801109966c8c0ed92759ea20b92bcbbf9ec2f9d2866342d28561 index.ts+d7756e84693b3cbee2c118fd4680a764e463ab479f8d83f43c4922234661a479 index.ts57c97292c7ca65cb1a024e0206af27ae6d3fbdf06c2973dfbfd3760183d02892 install-log-assets.ts4a76b51a64d76074af205e34f2b24df214b11f651988cf08cf47ef04c9f72de9 install-log.tsa9474cc5087b39e56f79bcd7e4cdfa9fcb748f26505bf6ad0f891c17393407ac network.ts@@ -12,7 +12,7 @@ a9474cc5087b39e56f79bcd7e4cdfa9fcb748f26505bf6ad0f891c17393407ac network.tsd772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.ts8d0d2fb3856b67b5ccbddd76a95f0464069552bd5ab297895fcbffb090f2a00f pm-config.tsc244d4cba6fbf2333a3da11d60ee184b6007f8017f6005f4d1b420a8b5c84b1c privacy.ts-1e09755779a5de4fa95663d72b6b65d4c6233ab4881524e41f1c005c5b961a95 processes.ts+ace18c59649e1fdafe2b66d16ed44801dc8b68c14629cf0007be29d5643e8a39 processes.ts2136f7a8af28ffd84c715609abb75b49b91a1761747384bd03d598bd7085e284 redact-policy.ts1cad37ae7ad2451b4e64f965599dfb889ff2be8eef632306aceb095ae42843ce redact-vectors.jsond8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.tsdiff --git a/apps/server/src/context/index.ts b/apps/server/src/context/index.tsindex c8b66b4e..00dadade 100644--- a/apps/server/src/context/index.ts+++ b/apps/server/src/context/index.ts@@ -244,7 +244,7 @@ export class ContextCapture {}private scopeOf(state: SessionContext): SnapshotScope {- return { rootPid: this.options.rootPid ?? process.pid, folders: () => [state.root, ...state.outside.folderPaths()] };+ return { rootPid: this.options.rootPid ?? process.pid, folders: () => [state.root, ...state.outside.folderPaths()], sessionId: state.id };}private section(name: keyof NonNullable<ContextOptions["sections"]>): boolean {diff --git a/apps/server/src/context/processes.ts b/apps/server/src/context/processes.tsindex c5ea4cc6..79556fb1 100644--- a/apps/server/src/context/processes.ts+++ b/apps/server/src/context/processes.ts@@ -351,6 +351,14 @@ export type SnapshotScope = {rootPid: number;/** The project and the outside folders the agent created or worked in (absolute). */folders: () => readonly string[];+ /**+ * The session the snapshot is for. Only its own processes keep their+ * command line: those whose environment names it (OMNIRUSH_SESSION, which+ * the engine sets in each shell call) and what they started. Every other+ * process (another chat's, the engine shared by chats, one that merely+ * works in the folder) keeps its name, pid and folder, never its arguments.+ */+ sessionId?: string;};export type SnapshotOptions = ProcessTableOptions & {@@ -363,6 +371,8 @@ export type SnapshotOptions = ProcessTableOptions & {scope?: SnapshotScope;/** Tests: the working directory of a process (Linux /proc, macOS lsof), null when unknown. */cwdOf?: (pids: number[]) => Promise<Map<number, string>>;+ /** Tests: the OMNIRUSH_SESSION a process runs under (processSessions). */+ sessionOf?: (pids: number[]) => Promise<Map<number, string>>;};// --- an OmniRush box ------------------------------------------------------------------@@ -487,6 +497,30 @@ export function descendantsOf(rootPid: number, processes: readonly ProcessInfo[]return out;}+/**+ * The session each of `pids` runs under: the OMNIRUSH_SESSION of its+ * environment (Linux /proc/<pid>/environ; no other variable is kept or+ * returned). None elsewhere: there a process's ownership is not known.+ */+export async function processSessions(pids: number[], options: ProcessTableOptions = {}): Promise<Map<number, string>> {+ const out = new Map<number, string>();+ if ((options.platform ?? process.platform) !== "linux") return out;+ await Promise.all(pids.slice(0, 2_000).map(async (pid) => {+ try {+ const environ = await readFile(`/proc/${pid}/environ`, "latin1");+ const at = environ.indexOf("\0OMNIRUSH_SESSION=");+ const start = environ.startsWith("OMNIRUSH_SESSION=") ? 0 : at < 0 ? -1 : at + 1;+ if (start < 0) return;+ const end = environ.indexOf("\0", start);+ const value = environ.slice(start + "OMNIRUSH_SESSION=".length, end < 0 ? undefined : end);+ if (/^[A-Za-z0-9_.:-]{1,200}$/.test(value)) out.set(pid, value);+ } catch {+ // Another account's process, or gone.+ }+ }));+ return out;+}+/** The working directories of `pids`: /proc/<pid>/cwd on Linux, `lsof -d cwd` on macOS, none on Windows. */export async function processCwds(pids: number[], options: ProcessTableOptions = {}): Promise<Map<number, string>> {const platform = options.platform ?? process.platform;@@ -548,10 +582,26 @@ export async function processSnapshot(phase: ProcessSnapshot["phase"], turn: numreturn cwd !== undefined && insideAny(cwd, folders);}).map((info) => info.pid));const ours = processes.filter((info) => (tree.has(info.pid) || inFolders.has(info.pid)) && !isOwnProcess(info, self));+ // The session's own processes (its environment names it) and their descendants keep their command line.+ const sessions = scope.sessionId+ ? await (options.sessionOf ?? ((pids) => processSessions(pids, options)))(ours.map((info) => info.pid)).catch(() => new Map<number, string>())+ : new Map<number, string>();+ // A process that names another session is that session's, with everything below it, whatever started it.+ const own = new Set<number>();+ const children = new Map<number, number[]>();+ for (const info of processes) children.set(info.ppid, [...(children.get(info.ppid) ?? []), info.pid]);+ const queue = [...sessions].filter(([, sessionId]) => sessionId === scope.sessionId).map(([pid]) => pid);+ while (queue.length > 0 && own.size < 100_000) {+ const pid = queue.shift()!;+ const named = sessions.get(pid);+ if (own.has(pid) || (named !== undefined && named !== scope.sessionId)) continue;+ own.add(pid);+ queue.push(...(children.get(pid) ?? []));+ }const kept = ours.slice(0, MAX_PROCESSES).map((info) => ({pid: info.pid,name: cleanText(baseNameOnly(info.name) ?? info.name, options.privacy, options.scrub),- command: cleanCommand(info.command, options.privacy, options.scrub),+ command: own.has(info.pid) ? cleanCommand(info.command, options.privacy, options.scrub) : "",scope: tree.has(info.pid) ? ("session" as const) : ("folder" as const),...(info.cwd ? { cwd: cleanText(info.cwd, options.privacy, options.scrub) } : {}),}));diff --git a/apps/server/src/project-env.ts b/apps/server/src/project-env.tsindex fe6db414..e2facf35 100644--- a/apps/server/src/project-env.ts+++ b/apps/server/src/project-env.ts@@ -89,15 +89,19 @@ export function safeEnvValue(name: string, raw: string, checks: SecretChecks = {return value;}-/** client-raw: a dotenv right-hand side as written: a quoted value's text (`$`, `\\` and all), else the text before an inline comment. */-function rawEnvValue(raw: string): string | undefined {- const text = raw.trim();- const quote = text[0];- if (quote === '"' || quote === "'" || quote === "`") {- const end = text.indexOf(quote, 1);- return end < 0 ? undefined : text.slice(1, end);+/** The first `quote` in `text` from `from` that is not escaped (an even run of backslashes before it, none included); -1 when none. */+function closingQuote(text: string, quote: string, from: number): number {+ for (let at = text.indexOf(quote, from); at >= 0; at = text.indexOf(quote, at + 1)) {+ let slashes = 0;+ while (at - slashes - 1 >= 0 && text[at - slashes - 1] === "\\") slashes += 1;+ if (slashes % 2 === 0) return at;}- return text.replace(/\s+#.*$/, "").trim();+ return -1;+}++/** client-raw: a dotenv right-hand side byte for byte as written (its quotes, `$`, `\\` and inner quotes included). */+function rawEnvValue(raw: string): string {+ return raw.trim();}/** The literal value of a dotenv right-hand side, or undefined when it is not one plain value. */@@ -129,9 +133,10 @@ export function parseEnvFile(text: string, checks: SecretChecks = {}): { keys: Efor (const line of text.split(/\r?\n/)) {if (openQuote) {// Inside a multi-line quoted value (a PEM key): its lines are never keys.- const end = line.indexOf(openQuote);+ const end = raw ? closingQuote(line, openQuote, 0) : line.indexOf(openQuote);if (multiline) {- multiline.lines.push(end < 0 ? line : line.slice(0, end));+ // Every line as written, the closing one whole (its quote included).+ multiline.lines.push(line);if (end >= 0) multiline.key.value = multiline.lines.join("\n");}if (end >= 0) {@@ -145,7 +150,7 @@ export function parseEnvFile(text: string, checks: SecretChecks = {}): { keys: Econst name = match[1]!;const rhs = match[2]!.trim();const quote = rhs[0];- if ((quote === '"' || quote === "'" || quote === "`") && rhs.indexOf(quote, 1) < 0) openQuote = quote;+ if ((quote === '"' || quote === "'" || quote === "`") && (raw ? closingQuote(rhs, quote, 1) : rhs.indexOf(quote, 1)) < 0) openQuote = quote;if (seen.has(name)) continue;if (keys.length >= MAX_ENV_KEYS_PER_FILE) {truncated = true;@@ -154,7 +159,7 @@ export function parseEnvFile(text: string, checks: SecretChecks = {}): { keys: Eseen.add(name);if (raw && openQuote) {const key: EnvKey = { name };- multiline = { key, lines: [rhs.slice(1)] };+ multiline = { key, lines: [rhs] };keys.push(key);continue;}diff --git a/apps/server/src/redact-policy.test.ts b/apps/server/src/redact-policy.test.tsindex fce7e98c..4e7f823d 100644--- a/apps/server/src/redact-policy.test.ts+++ b/apps/server/src/redact-policy.test.ts@@ -229,7 +229,7 @@ test("client-raw: MCP env and header values, the username, Maven credentials andconst maven = `<settings><servers><server><id>repo</id><username>deploy</username><password>hunter2Secret</password><privateKey>/k</privateKey><passphrase>pp</passphrase></server></servers></settings>`;const values = (keys) => Object.fromEntries(keys.map((key) => [key.name, key.value]));withPolicy("client-raw", () => {- assert.deepEqual(values(projectEnv.parseEnvFile(dotenv).keys), { API_TOKEN: "abc$def", PRIVATE_KEY: pem, JWT: jwt, PORT: "3000" });+ assert.deepEqual(values(projectEnv.parseEnvFile(dotenv).keys), { API_TOKEN: '"abc$def"', PRIVATE_KEY: `"${pem}"`, JWT: jwt, PORT: "3000" });assert.equal(setup.settingsOfConfig(opencode).username, "jane");assert.deepEqual(Object.fromEntries(pmConfig.parseMavenSettings(maven)), {"servers[0].id": "repo", "servers[0].username": "deploy", "servers[0].password": "hunter2Secret", "servers[0].privateKey": "/k", "servers[0].passphrase": "pp",diff --git a/apps/server/src/toolchain.test.ts b/apps/server/src/toolchain.test.tsindex 7baf6e57..0c98b480 100644--- a/apps/server/src/toolchain.test.ts+++ b/apps/server/src/toolchain.test.ts@@ -665,3 +665,21 @@ test("client-raw: the cache keeps one block per upload rules, and raw keeps valuassert.equal(toolchain.parseProbeOutput("tool 1.2 (/home/jane/.local/bin/tool)\n", ""), "tool 1.2 (/home/jane/.local/bin/tool)");});}, 30_000);++test("client-raw: every dotenv value reaches the toolchain block byte for byte as written, quotes included", async () => {+ const rules = await import("./context/redact-policy.js");+ const { redactUploadJson } = await import("./session-uploader.js");+ const pem = `"-----BEGIN ${"PRIVATE"} KEY-----\nMIIEvQ${"Q".repeat(60)}\n-----END ${"PRIVATE"} KEY-----"`;+ // Escaped quotes: on the first line, an even run of backslashes before the closing quote, and on a later line of a multi-line value.+ const multi = '"line one\nsay \\"hi\\" on line two\nend"';+ const source = { API_TOKEN: '"abc$def"', X: "'it''s'", Y: '"say \\"hi\\""', Z: '"a\\\\"', M: multi, PEM: pem, PORT: "3000" };+ const dotenv = Object.entries(source).map(([key, value]) => `${key}=${value}`).join("\n") + "\n";+ const root = tempProject({ "package.json": "{}", ".env": dotenv });+ const cache = new toolchain.ToolchainCache({ waitMs: 10_000, env: {}, resolve: () => null, scrub: (block) => redactUploadJson(block).value as typeof block });+ const stored = (block) => JSON.parse(JSON.stringify(redactUploadJson(block).value));+ const values = (block) => Object.fromEntries((block?.env_files?.[0]?.keys ?? []).map((key) => [key.name, key.value]));+ const raw = await rules.withRedactionPolicy("client-raw", async () => stored(await cache.get(root)));+ assert.deepEqual(values(raw), source);+ const legacy = stored(await cache.get(root));+ assert.deepEqual(values(legacy), { API_TOKEN: undefined, X: undefined, Y: undefined, Z: undefined, M: undefined, PEM: undefined, PORT: "3000" }, "the old rules unchanged");+}, 30_000);