Skip to content

bug(pi): console.warn in diagnostics emitter corrupts TUI input bar #1528

Description

@MciG-ggg

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):

  1. 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.
  2. Gate behind PI_DEBUG — only emit to stderr when PI_DEBUG=1 is set, so normal usage is clean.
  3. 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_memoryserver_unavailable diagnostic)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions