From 4995afed903ee521338cbb78777300bda75fe413 Mon Sep 17 00:00:00 2001 From: Flux Labs Date: Sun, 15 Mar 2026 09:56:41 -0500 Subject: [PATCH] refactor: replace hardcoded ANSI escapes with chalk, add debug logging - cli.ts: use chalk.yellow/dim/bold instead of raw \x1b sequences for version mismatch message; chalk v5 auto-respects NO_COLOR - update-check.ts: same chalk migration for the update banner - guided-flow.ts: log auto-start errors when GSD_DEBUG is set instead of silently swallowing them --- src/cli.ts | 19 +++++++++++-------- src/resources/extensions/gsd/guided-flow.ts | 4 +++- src/update-check.ts | 10 +++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index fa70b501b..b51a22dc3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -17,6 +17,7 @@ import { ensureManagedTools } from './tool-bootstrap.js' import { loadStoredEnvKeys } from './wizard.js' import { getPiDefaultModelAndProvider, migratePiCredentials } from './pi-migration.js' import { shouldRunOnboarding, runOnboarding } from './onboarding.js' +import chalk from 'chalk' import { checkForUpdates } from './update-check.js' // --------------------------------------------------------------------------- @@ -42,15 +43,10 @@ function exitIfManagedResourcesAreNewer(currentAgentDir: string): void { return } - const yellow = '\x1b[33m' - const dim = '\x1b[2m' - const reset = '\x1b[0m' - const bold = '\x1b[1m' - process.stderr.write( - `[gsd] ${yellow}Version mismatch detected${reset}\n` + - `[gsd] Synced resources are from ${bold}v${managedVersion}${reset}, but this \`gsd\` binary is ${dim}v${currentVersion}${reset}.\n` + - `[gsd] Run ${bold}npm install -g gsd-pi@latest${reset} or ${bold}gsd update${reset}, then try again.\n`, + `[gsd] ${chalk.yellow('Version mismatch detected')}\n` + + `[gsd] Synced resources are from ${chalk.bold(`v${managedVersion}`)}, but this \`gsd\` binary is ${chalk.dim(`v${currentVersion}`)}.\n` + + `[gsd] Run ${chalk.bold('npm install -g gsd-pi@latest')} or ${chalk.bold('gsd update')}, then try again.\n`, ) process.exit(1) } @@ -143,6 +139,13 @@ if (!isPrintMode) { checkForUpdates().catch(() => {}) } +// Warn if terminal is too narrow for readable output +if (!isPrintMode && process.stdout.columns && process.stdout.columns < 40) { + process.stderr.write( + chalk.yellow(`[gsd] Terminal width is ${process.stdout.columns} columns (minimum recommended: 40). Output may be unreadable.\n`), + ) +} + const modelRegistry = new ModelRegistry(authStorage) const settingsManager = SettingsManager.create(agentDir) diff --git a/src/resources/extensions/gsd/guided-flow.ts b/src/resources/extensions/gsd/guided-flow.ts index 5ad3cc766..437a3a4ef 100644 --- a/src/resources/extensions/gsd/guided-flow.ts +++ b/src/resources/extensions/gsd/guided-flow.ts @@ -65,7 +65,9 @@ export function checkAutoStartAfterDiscuss(): boolean { } catch { /* non-fatal — stale draft doesn't break anything, CONTEXT.md wins */ } pendingAutoStart = null; - startAuto(ctx, pi, basePath, false, { step }).catch(() => {}); + startAuto(ctx, pi, basePath, false, { step }).catch((err) => { + if (process.env.GSD_DEBUG) console.error('[gsd] auto start error:', err); + }); return true; } diff --git a/src/update-check.ts b/src/update-check.ts index 623a36b5a..18dc66cd1 100644 --- a/src/update-check.ts +++ b/src/update-check.ts @@ -1,5 +1,6 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs' import { dirname, join } from 'node:path' +import chalk from 'chalk' import { appRoot } from './app-paths.js' const CACHE_FILE = join(appRoot, '.update-check') @@ -46,14 +47,9 @@ export function writeUpdateCache(cache: UpdateCheckCache, cachePath: string = CA } function printUpdateBanner(current: string, latest: string): void { - const yellow = '\x1b[33m' - const dim = '\x1b[2m' - const reset = '\x1b[0m' - const bold = '\x1b[1m' - process.stderr.write( - ` ${yellow}Update available:${reset} ${dim}v${current}${reset} → ${bold}v${latest}${reset}\n` + - ` ${dim}Run${reset} npm update -g gsd-pi ${dim}or${reset} /gsd:update ${dim}to upgrade${reset}\n\n`, + ` ${chalk.yellow('Update available:')} ${chalk.dim(`v${current}`)} → ${chalk.bold(`v${latest}`)}\n` + + ` ${chalk.dim('Run')} npm update -g gsd-pi ${chalk.dim('or')} /gsd:update ${chalk.dim('to upgrade')}\n\n`, ) }