A desktop coding agent with free access to frontier models.
TypeScript
Merge branch 'fix/v1.1.1-runtime' into fix/v1.1.1-sessions-visible
ogsamrat7aafabe97dd8
diff --cc apps/server/src/server.tsindex 188b357d,a73cd580..bc0d90ab--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@@ -4801,66 -4864,19 +4880,72 @@@ async function requireWorkspaceRunModeI}));}- /**- * True when the managed engine reports any non-idle session (subagent child- * sessions carry their own ids and statuses, so they count too). Unknown- * activity reports false: a reload against a dead engine fails loudly on its- * own, and "unknown" must never park reloads forever.- */+/**+ * Whether two session folders are the same folder: the Windows extended-length+ * prefix, slash direction and a trailing slash never matter, and case does not+ * matter on Windows and macOS (both case-insensitive by default).+ */+export function isSameSessionFolder(left: string, right: string, platform: NodeJS.Platform = process.platform): boolean {+ const normalize = (value: string) => {+ const unified = normalizeOpencodeDirectory(value.trim(), platform).replace(/\\/g, "/").replace(/\/+$/, "");+ const folder = unified || "/";+ return platform === "win32" || platform === "darwin" ? folder.toLowerCase() : folder;+ };+ return Boolean(left.trim()) && normalize(left) === normalize(right);+}++/** Most recently updated sessions across every engine project (up to this many are scanned). */+const SESSIONS_BY_FOLDER_SCAN = 2_000;++/**+ * The sessions stored for `directory`, newest first, read from the engine's+ * unscoped session list: no project filter and no exact folder filter.+ */+export async function listEngineSessionsInFolder(+ config: ServerConfig,+ workspace: WorkspaceInfo,+ directory: string,+ limit: number,+ fetchImpl: (input: string, init?: RequestInit) => Promise<Response> = loopbackFetch,+): Promise<unknown[]> {+ const pool = enginePoolForConfig(config);+ const route = pool?.routeRequest("GET", "/experimental/session") ?? null;+ const connection = route ? null : resolveWorkspaceOpencodeConnection(config, workspace);+ const baseUrl = route?.target.baseUrl ?? connection?.baseUrl?.trim() ?? "";+ if (!baseUrl) throw new ApiError(503, "opencode_unconfigured", "OpenCode base URL is missing for this workspace");+ const headers = new Headers();+ // The header picks the folder's engine instance; with no `directory` query+ // the engine lists sessions of every folder and project.+ headers.set("x-opencode-directory", buildOpencodeDirectoryHeader(directory));+ const auth = route+ ? buildEngineAuthProbeHeader(route.target.username, route.target.password)+ : connection?.authHeader ?? null;+ if (auth) headers.set("Authorization", auth);+ const url = buildOpencodeProxyUrl(baseUrl, "/experimental/session", `?limit=${SESSIONS_BY_FOLDER_SCAN}&archived=true`);+ const response = await fetchImpl(url, { headers, signal: AbortSignal.timeout(45_000) });+ if (!response.ok) {+ throw new ApiError(response.status === 404 ? 404 : 502, "opencode_engine_unreachable", `The engine session list failed with status ${response.status}`);+ }+ const payload: unknown = await response.json();+ if (!Array.isArray(payload)) return [];+ return payload+ .filter((session) => isRecord(session) && typeof session.directory === "string" && isSameSessionFolder(session.directory, directory))+ .slice(0, limit);+}+- async function engineHasActiveSessions(config: ServerConfig, workspace: WorkspaceInfo): Promise<boolean> {+ /**+ * True when the managed engine reports any non-idle session (subagent child+ * sessions carry their own ids and statuses, so they count too). Unknown+ * activity reports `unknownIsBusy`: false for callers that would otherwise+ * park a reload forever against a dead engine, true for the rollover pool,+ * where "busy" only means rolling over to a standby instead of disposing an+ * engine that may still be running sessions.+ */+ async function engineHasActiveSessions(+ config: ServerConfig,+ workspace: WorkspaceInfo,+ unknownIsBusy = false,+ ): Promise<boolean> {try {const opencode = createWorkspaceOpencodeClient(config, workspace);const statuses = unwrapOpencodeResult(await opencode.session.status(), "/session/status");