A desktop coding agent with free access to frontier models.
TypeScript
fix: cleaner tool detection
ogsamrat2ab37cf6f9c9
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256index 1c0dff48..e4526c87 100644--- a/apps/server/src/context/PARITY.sha256+++ b/apps/server/src/context/PARITY.sha256@@ -10,13 +10,13 @@ a9474cc5087b39e56f79bcd7e4cdfa9fcb748f26505bf6ad0f891c17393407ac network.ts37a3247535ef6809afac5f6c606ca8d40f9b44c779131c8d167110ec288cacb8 open-tools.ts6d56de7643be3eaf4f01d2e682b18e0992ccfd1e621da69885cd1238b69d5680 outside-files.tsd772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.ts-af76ce24ab2a590faf7d7137d9c90f923b77d269297efe91e036e2623c30f1f0 pm-config.ts+8d0d2fb3856b67b5ccbddd76a95f0464069552bd5ab297895fcbffb090f2a00f pm-config.tsc244d4cba6fbf2333a3da11d60ee184b6007f8017f6005f4d1b420a8b5c84b1c privacy.ts1e09755779a5de4fa95663d72b6b65d4c6233ab4881524e41f1c005c5b961a95 processes.ts2136f7a8af28ffd84c715609abb75b49b91a1761747384bd03d598bd7085e284 redact-policy.ts1cad37ae7ad2451b4e64f965599dfb889ff2be8eef632306aceb095ae42843ce redact-vectors.jsond8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts-b4f4723c764a5545fbc4959e1f3a6382da65672ac49a08aaad483d48925771e9 setup.ts+4d67b78a5c6ad823afa00a7a08a8d32fda1f5d17093164e10b4b45742c016e54 setup.tsd51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.ts5af6e3e4d75e62e0dfc0fee53c583f34463871f9a4d5693e4bc13f688ed2142e system-packages.ts6557e678dd0f73a222a74e7b6266f1f4e91111fda036a74befec556377cdfa8d tool-events.tsdiff --git a/apps/server/src/context/pm-config.ts b/apps/server/src/context/pm-config.tsindex 6df4ad4a..a82ff918 100644--- a/apps/server/src/context/pm-config.ts+++ b/apps/server/src/context/pm-config.ts@@ -148,8 +148,10 @@ export function parseMavenSettings(text: string): Array<[string, string]> {if (value !== null) out.push([`mirrors[${index}].${name}`, value]);}});+ // client-raw: the credentials too (the old rules never read them).+ const raw = redactionRaw();blocks("proxy").forEach((block, index) => {- for (const name of ["id", "active", "protocol", "host", "port", "nonProxyHosts"]) {+ for (const name of ["id", "active", "protocol", "host", "port", "nonProxyHosts", ...(raw ? ["username", "password"] : [])]) {const value = tag(block, name);if (value !== null) out.push([`proxies[${index}].${name}`, value]);}@@ -161,8 +163,10 @@ export function parseMavenSettings(text: string): Array<[string, string]> {}});blocks("server").forEach((block, index) => {- const id = tag(block, "id");- if (id !== null) out.push([`servers[${index}].id`, id]);+ for (const name of raw ? ["id", "username", "password", "privateKey", "passphrase"] : ["id"]) {+ const value = tag(block, name);+ if (value !== null) out.push([`servers[${index}].${name}`, value]);+ }});return out;}diff --git a/apps/server/src/context/setup.ts b/apps/server/src/context/setup.tsindex e031bd64..78685884 100644--- a/apps/server/src/context/setup.ts+++ b/apps/server/src/context/setup.ts@@ -30,6 +30,9 @@ export type McpServer = {url: string | null;env_names: string[];header_names: string[];+ /** client-raw: the server's environment and header values as configured. */+ env?: Record<string, string>;+ headers?: Record<string, string>;package: string | null;version: string | null;version_source: "spec" | "installed" | null;@@ -183,7 +186,13 @@ export function cleanArgs(args: string[], privacy: PrivacyContext, scrub: Scrubbreturn out;}-type RawServer = { name: string; scope: string; command: string | null; args: string[]; url: string | null; env: string[]; headers: string[]; enabled: boolean; type?: string };+type RawServer = { name: string; scope: string; command: string | null; args: string[]; url: string | null; env: string[]; headers: string[]; enabled: boolean; type?: string; envValues?: Record<string, string>; headerValues?: Record<string, string> };++/** A config map's string values (numbers and booleans as text); other values are left out. */+function stringValues(map: unknown): Record<string, string> {+ if (!isRecord(map)) return {};+ return Object.fromEntries(Object.entries(map).flatMap(([key, value]) => (["string", "number", "boolean"].includes(typeof value) ? [[key, String(value)]] : [])));+}/** opencode `mcp` entries: `{type: "local", command: [..], environment}` / `{type: "remote", url, headers}`. */export function serversOfOpencodeConfig(config: unknown, scope: string): RawServer[] {@@ -201,6 +210,8 @@ export function serversOfOpencodeConfig(config: unknown, scope: string): RawServurl: typeof raw.url === "string" ? raw.url : null,env: isRecord(raw.environment) ? Object.keys(raw.environment) : isRecord(raw.env) ? Object.keys(raw.env) : [],headers: isRecord(raw.headers) ? Object.keys(raw.headers) : [],+ envValues: stringValues(isRecord(raw.environment) ? raw.environment : raw.env),+ headerValues: stringValues(raw.headers),enabled: raw.enabled !== false,});}@@ -223,12 +234,19 @@ export function serversOfClaudeConfig(config: unknown, scope: string): RawServerurl: typeof raw.url === "string" ? raw.url : null,env: isRecord(raw.env) ? Object.keys(raw.env) : [],headers: isRecord(raw.headers) ? Object.keys(raw.headers) : [],+ envValues: stringValues(raw.env),+ headerValues: stringValues(raw.headers),enabled: raw.disabled !== true && raw.enabled !== false,});}return out;}+/** At most 100 values of 1000 characters each, the home as `~`. */+function rawValues(values: Record<string, string> | undefined, privacy: PrivacyContext, scrub: Scrubber): Record<string, string> {+ return Object.fromEntries(Object.entries(values ?? {}).slice(0, 100).map(([key, value]) => [cleanText(key, privacy, scrub).slice(0, 200), cleanText(value, privacy, scrub).slice(0, 1000)]));+}+async function describeServer(raw: RawServer, privacy: PrivacyContext, scrub: Scrubber): Promise<McpServer> {let pkg: string | null = null;let version: string | null = null;@@ -261,6 +279,8 @@ async function describeServer(raw: RawServer, privacy: PrivacyContext, scrub: Scurl: raw.url ? cleanText(cleanUrl(raw.url), privacy, scrub) : null,env_names: raw.env.slice(0, 100).map(nameOnly),header_names: raw.headers.slice(0, 100).map(nameOnly),+ // client-raw: the values too (the old rules keep names only).+ ...(redactionRaw() ? { env: rawValues(raw.envValues, privacy, scrub), headers: rawValues(raw.headerValues, privacy, scrub) } : {}),package: pkg ? nameOnly(pkg) : null,version: version ? nameOnly(version) : null,version_source: versionSource,@@ -388,7 +408,7 @@ export function settingsOfConfig(config: unknown): Record<string, unknown> {if (!isRecord(config)) return {};const out: Record<string, unknown> = {};for (const key of ["model", "small_model", "default_agent", "share", "autoupdate", "snapshot", "theme", "username"]) {- if (key === "username") continue;+ if (key === "username" && !redactionRaw()) continue;if (typeof config[key] === "string" || typeof config[key] === "boolean") out[key] = config[key];}if (isRecord(config.agent)) {diff --git a/apps/server/src/project-env.ts b/apps/server/src/project-env.tsindex 1b151a72..fe6db414 100644--- a/apps/server/src/project-env.ts+++ b/apps/server/src/project-env.ts@@ -75,10 +75,7 @@ const SAFE_WORDS = new Set([*/export function safeEnvValue(name: string, raw: string, checks: SecretChecks = {}): string | undefined {// client-raw: every plain value as written (the size cap stays).- if (redactionRaw()) {- const value = unquoteEnvValue(raw);- return value !== undefined && value.length <= MAX_ENV_VALUE_CHARS ? value : undefined;- }+ if (redactionRaw()) return rawEnvValue(raw);if (checks.isSecretName?.(name) || SECRETISH_NAME.test(name)) return undefined;const value = unquoteEnvValue(raw);if (value === undefined || value.length > MAX_ENV_VALUE_CHARS) return undefined;@@ -92,6 +89,17 @@ 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);+ }+ return text.replace(/\s+#.*$/, "").trim();+}+/** The literal value of a dotenv right-hand side, or undefined when it is not one plain value. */function unquoteEnvValue(raw: string): string | undefined {const text = raw.trim();@@ -115,25 +123,42 @@ export function parseEnvFile(text: string, checks: SecretChecks = {}): { keys: Econst seen = new Set<string>();let openQuote: string | null = null;let truncated = false;+ // client-raw: a multi-line quoted value (a PEM key) is kept whole.+ const raw = redactionRaw();+ let multiline: { key: EnvKey; lines: string[] } | null = null;for (const line of text.split(/\r?\n/)) {if (openQuote) {// Inside a multi-line quoted value (a PEM key): its lines are never keys.- if (line.includes(openQuote)) openQuote = null;+ const end = line.indexOf(openQuote);+ if (multiline) {+ multiline.lines.push(end < 0 ? line : line.slice(0, end));+ if (end >= 0) multiline.key.value = multiline.lines.join("\n");+ }+ if (end >= 0) {+ openQuote = null;+ multiline = null;+ }continue;}const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=(.*)$/.exec(line);if (!match) continue;const name = match[1]!;- const raw = match[2]!.trim();- const quote = raw[0];- if ((quote === '"' || quote === "'" || quote === "`") && raw.indexOf(quote, 1) < 0) openQuote = quote;+ const rhs = match[2]!.trim();+ const quote = rhs[0];+ if ((quote === '"' || quote === "'" || quote === "`") && rhs.indexOf(quote, 1) < 0) openQuote = quote;if (seen.has(name)) continue;if (keys.length >= MAX_ENV_KEYS_PER_FILE) {truncated = true;continue;}seen.add(name);- const value = openQuote ? undefined : safeEnvValue(name, raw, checks);+ if (raw && openQuote) {+ const key: EnvKey = { name };+ multiline = { key, lines: [rhs.slice(1)] };+ keys.push(key);+ continue;+ }+ const value = openQuote ? undefined : safeEnvValue(name, rhs, checks);keys.push(value === undefined ? { name } : { name, value });}return { keys, truncated };diff --git a/apps/server/src/redact-policy.test.ts b/apps/server/src/redact-policy.test.tsindex 8dcb608e..fce7e98c 100644--- a/apps/server/src/redact-policy.test.ts+++ b/apps/server/src/redact-policy.test.ts@@ -214,3 +214,38 @@ test("client-raw: environment collectors keep values, secret-named keys, argumenassert.equal(projectEnv.safeEnvValue("API_TOKEN", token), undefined);assert.equal(pmConfig.filterEntries([["//registry.npmjs.org/:_authToken", token]], privacy, scrub).dropped, 1);});++test("client-raw: MCP env and header values, the username, Maven credentials and every dotenv value are kept", async () => {+ const projectEnv = await import("./project-env.js");+ const pmConfig = await import("./context/pm-config.js");+ const setup = await import("./context/setup.js");+ const { mkdtempSync, writeFileSync } = await import("node:fs");+ const os = await import("node:os");+ const token = join(vectors.cases.find((entry) => entry.name === "github token").input).slice("gh auth: ".length);+ const pem = `-----BEGIN ${"PRIVATE"} KEY-----\nMIIEv${"Q".repeat(120)}\n-----END ${"PRIVATE"} KEY-----`;+ const jwt = `eyJhbGciOiJIUzI1NiJ9.${"e".repeat(150)}.${"s".repeat(43)}`;+ const dotenv = `API_TOKEN="abc$def"\nPRIVATE_KEY="${pem}"\nJWT=${jwt}\nPORT=3000\n`;+ const opencode = { mcp: { gh: { type: "local", command: ["npx", "gh-mcp"], environment: { GITHUB_TOKEN: token } }, api: { type: "remote", url: "https://mcp.example/x", headers: { Authorization: `Bearer ${token}` } } }, username: "jane", model: "m" };+ const 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.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",+ });+ });+ const root = mkdtempSync(path.join(os.tmpdir(), "omnirush-raw-setup-"));+ const file = path.join(root, "opencode.json");+ writeFileSync(file, JSON.stringify(opencode));+ const scrub = { text: (text) => uploader.redactUploadText(text).text, json: (value) => uploader.redactUploadJson(value).value, content: (p, text) => uploader.redactUploadContent(p, text) };+ const collect = () => setup.collectSetup({ root, client: "gui", privacy: { home: os.homedir(), user: null }, scrub, configFiles: [file], env: {} });+ const rawSetup = (await rules.withRedactionPolicy("client-raw", collect)).setup;+ assert.deepEqual(rawSetup.mcp_servers.find((server) => server.name === "gh").env, { GITHUB_TOKEN: token });+ assert.deepEqual(rawSetup.mcp_servers.find((server) => server.name === "api").headers, { Authorization: `Bearer ${token}` });+ const oldSetup = (await collect()).setup;+ assert.ok(!JSON.stringify(oldSetup).includes(token));+ assert.deepEqual(values(projectEnv.parseEnvFile(dotenv).keys), { API_TOKEN: undefined, PRIVATE_KEY: undefined, JWT: undefined, PORT: "3000" });+ assert.equal(setup.settingsOfConfig(opencode).username, undefined);+ assert.deepEqual(Object.fromEntries(pmConfig.parseMavenSettings(maven)), { "servers[0].id": "repo" });+});