Skip to content

Terminal Focus Reporting (\x1b[?1004h) remains enabled after abrupt exit on Windows, spilling [I into PowerShell prompt #996

Description

@ThemeHackers

Bug Description

When freebuff CLI (v0.0.149) exits unexpectedly or crashes on Windows PowerShell, it fails to execute terminal cleanup reset sequences (TERMINAL_RESET_SEQUENCES). This results in two primary issues:

  1. Terminal State Pollution ([I Error): Focus Reporting mode (\x1b[?1004h) remains enabled in the terminal host. Upon refocusing the PowerShell window, the terminal automatically emits \x1b[I into stdin, leaving [I in the input prompt and triggering PowerShell parser errors:
    Missing ] at end of attribute or type literal.
  2. Stdout Buffer Leak: Raw indexer/file content strings (e.g., array string pools from scanned .js / .css files) leak into the main scrollback buffer instead of being isolated within the alternate screen buffer (\x1b[?1049h).

Environment

  • App Version: freebuff v0.0.149 (npm wrapper v0.0.146)
  • OS: Windows 10 / 11
  • Shell: PowerShell (Windows Terminal / ConHost)

Steps to Reproduce

  1. Open Windows PowerShell in a workspace containing JavaScript / CSS files.
  2. Run the freebuff command.
  3. Terminate or trigger an unhandled exit / indexing operation.
  4. Observe raw source code chunks printed onto the main terminal scrollback buffer.
  5. Click or refocus the PowerShell window.
  6. Observe [I inserted into the prompt, causing:
    PS C:\...> [I
    At line:1 char:3
    + [I
    +   ~
    Missing ] at end of attribute or type literal.
    

Root Cause Analysis

  • cli/src/utils/terminal-reset-sequences.ts defines TERMINAL_RESET_SEQUENCES containing \x1b[?1004l (Disable focus reporting) and \x1b[?1049l (Exit alternate screen buffer).
  • On Windows PowerShell, when the underlying process exits or receives an unhandled exception in launcher.js or terminal-protocol-controller.ts, the exit handler is either bypassed or fails to flush TERMINAL_RESET_SEQUENCES to stdout/stderr before process termination.

Expected Behavior

The exit and error handlers in launcher.js and terminal-protocol-controller.ts should guarantee that TERMINAL_RESET_SEQUENCES (\x1b[?1004l\x1b[?1049l\x1b[?25h) are reliably flushed to standard output before exiting on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions