Description
The Pi integration's diagnostic emitter writes JSON to stderr via console.warn(), which corrupts the TUI input bar rendering. The stderr output interleaves with the TUI's stdout-based cursor-positioned rendering, causing the diagnostic JSON to appear inline with the ❯ prompt and breaking the border.
── π ... ─────────────────────────────────────
{"component":"powercontext.pi","event":"flush_memory","outcome":"server_unavailable",...}
─────────────────────────────────────────
Root cause
In integrations/pi/plugins/powercontext/extensions/powercontext.ts:
const emitDiagnostic = createDiagnosticEmitter((line) => console.warn(line))
console.warn() writes to process.stderr, which goes directly to the terminal. Pi's TUI uses ANSI cursor positioning on stdout for incremental rendering. Any stderr output during rendering corrupts the display.
The DSH integration does this correctly
In integrations/dsh/plugins/powercontext/src/index.ts:
const emitDiagnostic = createDiagnosticEmitter((line) => ctx.logger.warn(line))
The DSH host provides a proper logger. The Pi ExtensionContext does not expose a logger property, so the Pi integration fell back to console.warn().
Proposed fix
Options (from least to most effort):
- Write diagnostics to a file — e.g.
$PI_POWERCONTEXT_DIAGNOSTIC_LOG or a fixed path like ~/.powercontext/pi-diagnostics.log. Silent by default, opt-in via env var.
- Gate behind
PI_DEBUG — only emit to stderr when PI_DEBUG=1 is set, so normal usage is clean.
- Provide a logging API in Pi's ExtensionContext — add
ctx.log(level, message) or ctx.logger that the host can route safely (to file, to a status widget, or suppressed in TUI mode). This would also benefit other extensions.
Option 1 or 2 is a quick fix for the powercontext side. Option 3 is the proper long-term fix on Pi's side.
Environment
- powercontext pi plugin: current master
- Pi version: latest
- Ghostty
- Reproducible whenever PowerContext server returns 503 (triggers
flush_memory → server_unavailable diagnostic)
Description
The Pi integration's diagnostic emitter writes JSON to stderr via
console.warn(), which corrupts the TUI input bar rendering. The stderr output interleaves with the TUI's stdout-based cursor-positioned rendering, causing the diagnostic JSON to appear inline with the❯prompt and breaking the border.Root cause
In
integrations/pi/plugins/powercontext/extensions/powercontext.ts:console.warn()writes toprocess.stderr, which goes directly to the terminal. Pi's TUI uses ANSI cursor positioning on stdout for incremental rendering. Any stderr output during rendering corrupts the display.The DSH integration does this correctly
In
integrations/dsh/plugins/powercontext/src/index.ts:The DSH host provides a proper logger. The Pi
ExtensionContextdoes not expose aloggerproperty, so the Pi integration fell back toconsole.warn().Proposed fix
Options (from least to most effort):
$PI_POWERCONTEXT_DIAGNOSTIC_LOGor a fixed path like~/.powercontext/pi-diagnostics.log. Silent by default, opt-in via env var.PI_DEBUG— only emit to stderr whenPI_DEBUG=1is set, so normal usage is clean.ctx.log(level, message)orctx.loggerthat the host can route safely (to file, to a status widget, or suppressed in TUI mode). This would also benefit other extensions.Option 1 or 2 is a quick fix for the powercontext side. Option 3 is the proper long-term fix on Pi's side.
Environment
flush_memory→server_unavailablediagnostic)