Skip to content

The agent that grows with you

fix(desktop): strip installer escapes at the Electron bootstrap emitter too

teknium16e58dcdbe761
diff --git a/apps/desktop/electron/bootstrap-runner.test.ts b/apps/desktop/electron/bootstrap-runner.test.ts
index e94dcf34566..19fb679fd86 100644
--- a/apps/desktop/electron/bootstrap-runner.test.ts
+++ b/apps/desktop/electron/bootstrap-runner.test.ts
@@ -9,6 +9,7 @@ import {
buildPinArgs,
buildPosixPinArgs,
cachedScriptPath,
+ cleanInstallerLogLine,
hasExistingGitCheckout,
installedAgentInstallScript,
installRefForStamp,
@@ -272,3 +273,19 @@ test('resolveInstallScript rethrows when the 404 fallback is unavailable', async
fs.rmSync(home, { recursive: true, force: true })
}
})
+
+// #112675: install.sh colours its banners and curl/uv redraw progress with \r
+// even into a pipe; the overlay renders lines as plain text, so the emitter
+// must hand every consumer (log ring, Details panel, Copy output) the text a
+// terminal would be left showing.
+test('installer log lines reach the emitter without escape sequences; \\r redraws keep the last frame', () => {
+ assert.equal(cleanInstallerLogLine('\u001b[0;32m✓\u001b[0m Detected: macos (macos)'), '✓ Detected: macos (macos)')
+ assert.equal(cleanInstallerLogLine('\u001b[2K\u001b[1GCloning repository…\u001b[K'), 'Cloning repository…')
+ assert.equal(cleanInstallerLogLine('\u001b]0;hermes\u0007Installing Hermes'), 'Installing Hermes')
+ assert.equal(cleanInstallerLogLine('\r 12%\r 67%\r100%\u001b[K'), '100%')
+ assert.equal(cleanInstallerLogLine('Resolving dependencies…\r'), 'Resolving dependencies…')
+ // Only-escape frames drop entirely, so the caller emits nothing for them.
+ assert.equal(cleanInstallerLogLine('\u001b[0m\r'), '')
+ // Plain multi-byte text is untouched.
+ assert.equal(cleanInstallerLogLine('Ready — café ✓ 中文'), 'Ready — café ✓ 中文')
+})
diff --git a/apps/desktop/electron/bootstrap-runner.ts b/apps/desktop/electron/bootstrap-runner.ts
index ddc273f8ddc..dce1713a5f1 100644
--- a/apps/desktop/electron/bootstrap-runner.ts
+++ b/apps/desktop/electron/bootstrap-runner.ts
@@ -20,7 +20,7 @@
* { type: 'manifest', stages: [{name, title, category, needs_user_input}, ...] }
* { type: 'stage', name, state: 'running'|'succeeded'|'skipped'|'failed',
* json?, durationMs?, error? }
- * { type: 'log', stage?, line, stream: 'stdout'|'stderr' } // raw line from install.ps1
+ * { type: 'log', stage?, line, stream: 'stdout'|'stderr' } // one installer line, escapes stripped
* { type: 'complete', marker: <written marker payload> }
* { type: 'failed', stage?, error } // bootstrap aborted
*
@@ -38,6 +38,10 @@ import fsp from 'node:fs/promises'
import https from 'node:https'
import path from 'node:path'
+// Relative, not `@hermes/shared/ansi`: the electron bundle is built by esbuild
+// with no tsconfig path resolution (see scripts/bundle-electron-main.mjs).
+import { stripAnsi } from '../../shared/src/ansi'
+
import { hiddenWindowsChildOptions } from './windows-child-options'
const IS_WINDOWS = process.platform === 'win32'
@@ -456,6 +460,18 @@ function resolveWindowsPowerShell() {
return 'powershell.exe'
}
+// install.sh (and the git/curl/uv children it drives) writes SGR colours,
+// cursor/erase sequences, OSC titles and \r progress redraws into the pipe as
+// if it were a TTY. The install overlay renders each line as plain text, so
+// strip them ONCE here, at the emitter: the main-process log ring, the
+// renderer's Details panel and "Copy output" all read the same clean line
+// (#112675). \r redraws collapse to the last frame a terminal would show.
+function cleanInstallerLogLine(raw: string): string {
+ const frames = raw.split('\r').map(stripAnsi).filter(Boolean)
+
+ return frames.length ? frames[frames.length - 1] : ''
+}
+
function spawnPowerShell(scriptPath, args, { emit, stageName, abortSignal, hermesHome }: any = {}) {
return new Promise<any>((resolve, reject) => {
const ps = process.platform === 'win32' ? resolveWindowsPowerShell() : 'pwsh'
@@ -508,7 +524,7 @@ function spawnPowerShell(scriptPath, args, { emit, stageName, abortSignal, herme
let nl
while ((nl = stdoutBuf.indexOf('\n')) !== -1) {
- const line = stdoutBuf.slice(0, nl).replace(/\r$/, '')
+ const line = cleanInstallerLogLine(stdoutBuf.slice(0, nl))
stdoutBuf = stdoutBuf.slice(nl + 1)
if (line) {
@@ -524,7 +540,7 @@ function spawnPowerShell(scriptPath, args, { emit, stageName, abortSignal, herme
let nl
while ((nl = stderrBuf.indexOf('\n')) !== -1) {
- const line = stderrBuf.slice(0, nl).replace(/\r$/, '')
+ const line = cleanInstallerLogLine(stderrBuf.slice(0, nl))
stderrBuf = stderrBuf.slice(nl + 1)
if (line) {
@@ -547,12 +563,15 @@ function spawnPowerShell(scriptPath, args, { emit, stageName, abortSignal, herme
}
// Flush any trailing bytes
- if (stdoutBuf) {
- emit && emit({ type: 'log', stage: stageName, line: stdoutBuf, stream: 'stdout' } as any)
+ const stdoutTail = cleanInstallerLogLine(stdoutBuf)
+ const stderrTail = cleanInstallerLogLine(stderrBuf)
+
+ if (stdoutTail) {
+ emit && emit({ type: 'log', stage: stageName, line: stdoutTail, stream: 'stdout' } as any)
}
- if (stderrBuf) {
- emit && emit({ type: 'log', stage: stageName, line: stderrBuf, stream: 'stderr' } as any)
+ if (stderrTail) {
+ emit && emit({ type: 'log', stage: stageName, line: stderrTail, stream: 'stderr' } as any)
}
resolve({ stdout, stderr, code, signal, killed } as any)
@@ -602,7 +621,7 @@ function spawnBash(scriptPath, args, { emit, stageName, abortSignal, hermesHome
let nl
while ((nl = stdoutBuf.indexOf('\n')) !== -1) {
- const line = stdoutBuf.slice(0, nl).replace(/\r$/, '')
+ const line = cleanInstallerLogLine(stdoutBuf.slice(0, nl))
stdoutBuf = stdoutBuf.slice(nl + 1)
if (line) {
@@ -618,7 +637,7 @@ function spawnBash(scriptPath, args, { emit, stageName, abortSignal, hermesHome
let nl
while ((nl = stderrBuf.indexOf('\n')) !== -1) {
- const line = stderrBuf.slice(0, nl).replace(/\r$/, '')
+ const line = cleanInstallerLogLine(stderrBuf.slice(0, nl))
stderrBuf = stderrBuf.slice(nl + 1)
if (line) {
@@ -640,12 +659,15 @@ function spawnBash(scriptPath, args, { emit, stageName, abortSignal, hermesHome
abortSignal.removeEventListener('abort', onAbort)
}
- if (stdoutBuf) {
- emit && emit({ type: 'log', stage: stageName, line: stdoutBuf, stream: 'stdout' })
+ const stdoutTail = cleanInstallerLogLine(stdoutBuf)
+ const stderrTail = cleanInstallerLogLine(stderrBuf)
+
+ if (stdoutTail) {
+ emit && emit({ type: 'log', stage: stageName, line: stdoutTail, stream: 'stdout' })
}
- if (stderrBuf) {
- emit && emit({ type: 'log', stage: stageName, line: stderrBuf, stream: 'stderr' })
+ if (stderrTail) {
+ emit && emit({ type: 'log', stage: stageName, line: stderrTail, stream: 'stderr' })
}
resolve({ stdout, stderr, code, signal, killed })
@@ -1045,6 +1067,7 @@ export {
buildPinArgs,
buildPosixPinArgs,
cachedScriptPath,
+ cleanInstallerLogLine,
hasExistingGitCheckout,
installedAgentInstallScript,
installRefForStamp,
diff --git a/apps/desktop/tsconfig.electron.json b/apps/desktop/tsconfig.electron.json
index 058f132dea4..b0b82a27509 100644
--- a/apps/desktop/tsconfig.electron.json
+++ b/apps/desktop/tsconfig.electron.json
@@ -16,6 +16,6 @@
"rootDir": "..",
"outDir": "build/electron-types"
},
- "include": ["electron", "../shared/src/data-url-read-max.ts", "../shared/src/translucency.ts"],
+ "include": ["electron", "../shared/src/ansi.ts", "../shared/src/data-url-read-max.ts", "../shared/src/translucency.ts"],
"exclude": ["src", "electron/**/*.e2e.mts"]
}