refactor(core): replace legacy logger with Effect logging (#31310)

This commit is contained in:
Dax
2026-06-08 15:41:56 -04:00
committed by GitHub
parent 0a7cb20e66
commit c06ad7c881
152 changed files with 698 additions and 2243 deletions
+2 -9
View File
@@ -1,10 +1,8 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
import * as Log from "@opencode-ai/core/util/log"
import { OAUTH_DUMMY_KEY } from "../auth"
import { createServer } from "http"
import { InstallationVersion } from "@opencode-ai/core/installation/version"
const log = Log.create({ service: "plugin.xai" })
// Public Grok-CLI OAuth client. xAI's auth server rejects loopback OAuth from
// non-allowlisted clients, so we reuse the Grok-CLI client_id that xAI ships
@@ -510,8 +508,6 @@ async function startOAuthServer(): Promise<{ port: number; redirectUri: string }
// behavior and crash the entire opencode process. Matches the silent-
// swallow behavior the Codex plugin gets from its permanent
// `oauthServer!.on("error", reject)`.
server.on("error", (err) => log.warn("xai oauth server error", { error: err }))
log.info("xai oauth server started", { host: OAUTH_HOST, port: OAUTH_PORT })
resolve()
})
oauthServer = server
@@ -522,7 +518,7 @@ async function startOAuthServer(): Promise<{ port: number; redirectUri: string }
function stopOAuthServer() {
if (oauthServer) {
oauthServer.close(() => log.info("xai oauth server stopped"))
oauthServer.close()
oauthServer = undefined
}
}
@@ -607,7 +603,6 @@ export async function XaiAuthPlugin(input: PluginInput, options: XaiAuthPluginOp
if (expiresSoon) {
if (!refreshPromise) {
const refreshToken = currentAuth.refresh
log.info("refreshing xai access token")
refreshPromise = refreshAccessToken(refreshToken, options)
.then(async (tokens) => {
const refreshedExpires = Date.now() + (tokens.expires_in ?? 3600) * 1000
@@ -627,7 +622,7 @@ export async function XaiAuthPlugin(input: PluginInput, options: XaiAuthPluginOp
expires: refreshedExpires,
},
})
.catch((err) => log.warn("failed to persist refreshed xai tokens", { error: err }))
.catch(() => {})
return { access: tokens.access_token, refresh: refreshedRefresh, expires: refreshedExpires }
})
.finally(() => {
@@ -688,7 +683,6 @@ export async function XaiAuthPlugin(input: PluginInput, options: XaiAuthPluginOp
expires: Date.now() + (tokens.expires_in ?? 3600) * 1000,
}
} catch (err) {
log.error("xai oauth callback failed", { error: err })
return { type: "failed" as const }
} finally {
stopOAuthServer()
@@ -725,7 +719,6 @@ export async function XaiAuthPlugin(input: PluginInput, options: XaiAuthPluginOp
expires: Date.now() + (tokens.expires_in ?? 3600) * 1000,
}
} catch (err) {
log.error("xai device code callback failed", { error: err })
return { type: "failed" as const }
}
},