A desktop coding agent with free access to frontier models.
TypeScript
feat: install wrappers in the engine env
ogsamrate7e4481d8b38
diff --git a/apps/server/src/capture-client.ts b/apps/server/src/capture-client.tsindex 096601ad..8746118b 100644--- a/apps/server/src/capture-client.ts+++ b/apps/server/src/capture-client.ts@@ -394,6 +394,7 @@ class CaptureClient implements CaptureService {sessionIntegrity: Boolean(this.options.sessionIntegrity),// Always: the chats this thread saw observed are known here even without a resolver.engineTarget: true,+ ...(this.options.installLog ? { installLog: this.options.installLog } : {}),sessionUploader: {upload: Boolean(sessionUploader.upload),uploadFile: Boolean(sessionUploader.uploadFile),diff --git a/apps/server/src/capture-host.ts b/apps/server/src/capture-host.tsindex 97b53184..4e6b508f 100644--- a/apps/server/src/capture-host.ts+++ b/apps/server/src/capture-host.ts@@ -94,6 +94,8 @@ export type CaptureHostOptions = {/** Capture context (context/): false turns it off, an object overrides its options. */context?: false | Partial<ContextOptions>;};+ /** The install log's raw folder and wrapper folder (install-log-host.ts), when the engines have them. */+ installLog?: { raw: string; bin: string } | null;archive: Pick<SessionArchiverOptions, "request" | "refreshAccessToken" | "fetch" | "gatewayUrl" | "accessToken" | "folderGate"> & {/** Archiving is on for this device (OMNIRUSH_ARCHIVE_ENABLED) and an account is connected. */enabled: boolean;@@ -150,6 +152,7 @@ export class CaptureHost {repairTranscript: (chat) => this.transcript(chat),// Capture context (context/); OMNIRUSH_CAPTURE_CONTEXT=0 turns it off.context: options.sessionUploader?.context ?? {},+ ...(options.installLog ? { installLog: options.installLog } : {}),...(options.onSessionClosed ? { onSessionClosed: options.onSessionClosed } : {}),// The touched-files archive hears of every path a session touches, here on the same thread.onPathTouched: (sessionId, path) => this.archive.pathTouched(sessionId, path),diff --git a/apps/server/src/capture-protocol.ts b/apps/server/src/capture-protocol.tsindex dee21eb9..44cd9dd4 100644--- a/apps/server/src/capture-protocol.ts+++ b/apps/server/src/capture-protocol.ts@@ -83,6 +83,8 @@ export type CaptureWorkerInit = {/** The main thread can name the engine holding a chat (to settle a turn a previous process left open). */engineTarget: boolean;sessionUploader: { upload: boolean; uploadFile: boolean; capabilities: boolean; refreshAccessToken: boolean; gatewayUrl?: string; accessToken?: string };+ /** The install log's folders (install-log-host.ts), when the engines have the wrappers. */+ installLog?: { raw: string; bin: string } | null;archive: {enabled: boolean;excludedDirs: string[];diff --git a/apps/server/src/capture-worker.ts b/apps/server/src/capture-worker.tsindex 0c47dc6d..49ea7e8a 100644--- a/apps/server/src/capture-worker.ts+++ b/apps/server/src/capture-worker.ts@@ -133,6 +133,7 @@ const host = new CaptureHost({},}: {}),+ ...(init.installLog ? { installLog: init.installLog } : {}),sessionUploader: {...(init.sessionUploader.upload? {diff --git a/apps/server/src/install-log-host.ts b/apps/server/src/install-log-host.tsnew file mode 100644index 00000000..c389391e--- /dev/null+++ b/apps/server/src/install-log-host.ts@@ -0,0 +1,29 @@+/**+ * The install log's wrappers for the engines this server starts+ * (context/install-log.ts): written once at startup under the runtime state+ * folder; every managed engine then gets them first on its PATH (and the pip+ * hook on its PYTHONPATH), so only the shells the engine starts for tool calls+ * see them. OMNIRUSH_INSTALL_LOG=0 leaves them out. Whether anything is noted+ * and sent is the server's call (capabilities `install_log`), read by the+ * session uploader.+ */+import { installLogEnv, installLogLocallyEnabled, prepareInstallLog, type InstallLogPaths } from "./context/install-log.js";++let prepared: InstallLogPaths | null = null;++/** Writes the wrappers (once per version) and this process's raw folder. */+export async function prepareDesktopInstallLog(stateDir: string, env: NodeJS.ProcessEnv = process.env): Promise<InstallLogPaths | null> {+ if (!installLogLocallyEnabled(env)) return null;+ prepared ??= await prepareInstallLog({ stateDir });+ return prepared;+}++/** What a managed engine's environment gets (nothing before prepareDesktopInstallLog, or when it failed). */+export function engineInstallLogEnv(base: Record<string, string | undefined>): Record<string, string> {+ return prepared ? installLogEnv(prepared, base) : {};+}++/** Tests: forget the prepared wrappers. */+export function resetDesktopInstallLog(): void {+ prepared = null;+}diff --git a/apps/server/src/managed-opencode.ts b/apps/server/src/managed-opencode.tsindex 82638c57..dffa6238 100644--- a/apps/server/src/managed-opencode.ts+++ b/apps/server/src/managed-opencode.ts@@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";import { globalOpencodeConfigDir } from "@omnirush/paths";import { engineDataEnv } from "./engine-data-home.js";import { repairEngineStoreBeforeStart } from "./engine-store-repair.js";+import { engineInstallLogEnv } from "./install-log-host.js";export type ManagedChildProcess = {exitCode: number | null;@@ -174,6 +175,8 @@ async function startManagedOpencodeServer(...engineEnvDefaults,...options.env,...dataEnv,+ // The install log's wrappers, first on PATH for the engine's tool shells only (install-log-host.ts).+ ...engineInstallLogEnv(baseEnv),OPENCODE_SERVER_USERNAME: username,OPENCODE_SERVER_PASSWORD: password,};diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex 992d39a4..0726af39 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -1482,11 +1482,14 @@ export class OmniRushGatewayBroker {if (!isRecord(payload)) return none;const v3 = payload.canonical_trace === true && Array.isArray(payload.schema_versions) && payload.schema_versions.some((version) => version === 3);const triggers = Array.isArray(payload.triggers) ? payload.triggers.filter((item): item is string => typeof item === "string") : null;+ const installLog = isRecord(payload.install_log) ? payload.install_log : null;return {schema_versions: v3 ? [1, 2, 3] : [1, 2],canonical_trace: v3,...uploadFeatureFlags(payload),...(triggers ? { triggers } : {}),+ // The install log switch, passed on as the server said it (context/install-log.ts reads it).+ ...(installLog ? { install_log: { enabled: installLog.enabled === true, sample_percent: typeof installLog.sample_percent === "number" ? installLog.sample_percent : 100 } } : {}),};} catch {return none;diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex b7eb0926..7250eb9d 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -205,6 +205,7 @@ import { GOOD_SESSION_ID_PATTERN, readGoodSession } from "./omnirush-good-sessioimport { PROJECT_ARCHIVE_BASE_IDLE_MS, PROJECT_ARCHIVE_BASE_MAX_DEFER_MS, projectArchiveSettings } from "./project-archive.js";import type { ArchiveApiRequestInit } from "./session-archive/upload.js";import { runtimeStorageDir } from "./runtime-db.js";+import { prepareDesktopInstallLog } from "./install-log-host.js";import pkg from "../package.json" with { type: "json" };import constants from "../../../constants.json" with { type: "json" };import { BestPracticesEngineReloads } from "./best-practices.js";@@ -1097,8 +1098,11 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {gatewayBroker,uploadEnabled: sessionUploaderEnabled({ upload: gatewayBroker.enabled }),});+ // The install log's wrappers (install-log-host.ts): ready before any engine starts.+ const installLogPaths = await prepareDesktopInstallLog(runtimeStorageDir(config)).catch(() => null);const capture = startCaptureService({stateDir: runtimeStorageDir(config),+ ...(installLogPaths ? { installLog: { raw: installLogPaths.raw, bin: installLogPaths.bin } } : {}),appVersion,// "opencode/1.18.32-r2": the bundled engine, as every upload names it (engine-identity.ts).engineVersion: BUNDLED_ENGINE_VERSION,diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex 3b9098da..c94e8b22 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -30,6 +30,7 @@ import { ExcludedFiles, listGitIgnored, type HashCache } from "./excluded-files.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 { INSTALL_LOG_OFF, installLogGate, type InstallLogGate } from "./context/install-log.js";import { isOpaqueKey, isOpaqueString, isSecretKey, isSecretValue, redactCredentials, redactionPolicy, redactionV3 } from "./context/redact-policy.js";import { maskWindowsProfiles } from "./context/privacy.js";import bundledBestPractices from "./bundled-best-practices.json" with { type: "json" };@@ -761,6 +762,12 @@ type SessionUploaderOptions = {* always passes one) and overrides its options; absent or false: off.*/context?: false | Partial<ContextOptions>;+ /**+ * The install log (context/install-log.ts): the engines' wrappers write to+ * `raw`; noting is on only while the capabilities say `install_log.enabled`+ * (sampled per session). Absent: none.+ */+ installLog?: { raw: string; bin?: string | null } | null;};export type TraceCapabilities = {@@ -774,6 +781,8 @@ export type TraceCapabilities = {recovered_segments?: boolean;/** The upload triggers the backend takes, when it lists them. */triggers?: string[];+ /** The install log switch (context/install-log.ts): absent is off. */+ install_log?: { enabled: boolean; sample_percent: number };};@@ -4507,6 +4516,7 @@ export class SessionUploader {private readonly onBinaryFile?: (sessionId: string, path: string) => void;private readonly fileUploader?: SessionUploaderOptions["uploadFile"];private readonly capabilityProbe?: SessionUploaderOptions["capabilities"];+ private readonly installLogPaths: { raw: string; bin?: string | null } | null;private traceSchemaCache: { version: 2 | 3; features: UploadFeatures; expiresAt: number } | null = null;private traceSchemaProbe: Promise<2 | 3> | null = null;/** Work counters for tests and profiling. */@@ -4521,6 +4531,7 @@ export class SessionUploader {this.uploader = options.upload;this.fileUploader = options.uploadFile;this.capabilityProbe = options.capabilities;+ this.installLogPaths = options.installLog ?? null;this.refreshAccessToken = options.refreshAccessToken;this.log = options.log ?? (() => undefined);const stateDir = options.stateDir ? resolve(options.stateDir) : null;@@ -4627,6 +4638,7 @@ export class SessionUploader {bundledSkillDirs: stateDir ? [join(stateDir, "skills")] : [],configFiles: stateDir ? [join(stateDir, "runtime-opencode-config.json")] : [],log: this.log,+ ...(this.installLogPaths ? { installLog: { ...this.installLogPaths, gate: () => this.installLogGate(), appDirs: stateDir ? [stateDir] : [] } } : {}),...overrides,});return capture.enabled ? capture : null;@@ -4900,6 +4912,16 @@ export class SessionUploader {return this.traceSchemaProbe;}+ /** The install log's server switch (GET /collect/capabilities `install_log`); off when it cannot be asked. */+ private async installLogGate(): Promise<InstallLogGate> {+ if (!this.capabilityProbe) return INSTALL_LOG_OFF;+ try {+ return installLogGate(await this.capabilityProbe());+ } catch {+ return INSTALL_LOG_OFF;+ }+ }+private downgradeTraceSchema(): void {this.traceSchemaCache = { version: 2, features: this.traceSchemaCache?.features ?? NO_UPLOAD_FEATURES, expiresAt: Date.now() + TRACE_CAPABILITY_TTL_MS };}