From 9776b8b89dea5e5ab1f6d052eacd5c3b934a957d Mon Sep 17 00:00:00 2001 From: Kenny Heitritter Date: Thu, 28 May 2026 17:56:04 -0500 Subject: [PATCH] fix(branding): prevent upstream-drift breakage in apply.ts Two pre-existing bugs surfaced after the upstream sync, both of which broke branded (CodeQ) builds: 1. External scoped package @gitlab/opencode-gitlab-auth was renamed to @gitlab/codeq-gitlab-auth by the opencode->productName replacement, causing 'bun install' to 404 and the build to fail. Exclude scoped packages (negative lookbehind for @/) and -gitlab-auth. 2. The CLI logo transform injected a logo() that references a 'const LOGO' array which upstream removed (logo now comes from ./logo glyphs), so the branded binary crashed at startup with 'LOGO is not defined'. Guard the CLI + TUI logo transforms to no-op when the expected structures are absent, preserving the upstream logo instead of crashing. --- branding/apply.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/branding/apply.ts b/branding/apply.ts index f9d5f84660c5..829a65dbe8dc 100644 --- a/branding/apply.ts +++ b/branding/apply.ts @@ -125,10 +125,11 @@ function buildReplacements(config: Branding): Replacement[] { // Product name replacements (case-sensitive) // Use negative lookbehind/lookahead to avoid matching: // - @opencode-ai package names + // - external scoped packages like @gitlab/opencode-gitlab-auth (preceded by `@/`) // - Directory paths like /opencode/ (but allow /bin/opencode at end of path) // - File extensions like opencode.json replacements.push({ - search: /(? ${r.productName}`, }) @@ -224,6 +225,16 @@ const FILE_TRANSFORMS: FileTransform[] = [ { pattern: "packages/opencode/src/cli/ui.ts", transform: (content, config) => { + // Guard against upstream drift: this transform assumes ui.ts defines a + // `const LOGO = [...]` array consumed by logo(). Newer upstream versions + // moved the logo into ./logo (glyphs.left/right). If the LOGO array is + // not present, skip the rewrite entirely rather than injecting a logo() + // that references an undefined LOGO (which crashes the CLI at startup). + if (!/const LOGO = \[\n[\s\S]*?\n \]/.test(content)) { + warn("ui.ts: `const LOGO` array not found (upstream changed logo structure); skipping CLI logo branding") + return content + } + const logoStr = config.logo.cli.map((row) => ` [\`${row[0]}\`, \`${row[1]}\`],`).join("\n") let result = content.replace(/const LOGO = \[\n[\s\S]*?\n \]/, `const LOGO = [\n${logoStr}\n ]`) @@ -257,6 +268,14 @@ const FILE_TRANSFORMS: FileTransform[] = [ { pattern: "packages/opencode/src/cli/cmd/tui/component/logo.tsx", transform: (content, config) => { + // Guard against upstream drift: skip if the expected LOGO_LEFT/LOGO_RIGHT + // arrays are no longer present (avoids injecting an unused PURPLE const + // and keeps the branded build aligned with the upstream component). + if (!/const LOGO_LEFT = \[/.test(content) || !/const LOGO_RIGHT = \[/.test(content)) { + warn("logo.tsx: LOGO_LEFT/LOGO_RIGHT not found (upstream changed TUI logo); skipping TUI logo branding") + return content + } + const left = config.logo.tui.left.map((l) => `\`${l}\``).join(", ") const right = config.logo.tui.right.map((l) => `\`${l}\``).join(", ")