Skip to content

[Bug]: Pi adapter: ctx_execute renders blank in collapsed TUI — shows only code fence opening #1094

Description

@danyal002

Bug Description

When ctx_execute (or ctx_execute_file / ctx_batch_execute) runs in Pi, the collapsed TUI rendering shows only the opening of a markdown code fence (e.g. triple-backtick shell) and nothing else — no command, no output, no closing fence. The tool executes correctly, but the user sees a blank-looking result.

Image

Root Cause

buildExecuteEcho() in src/server.ts prepends a markdown code fence to every ctx_execute response:

(fence opening)shell
<code>
(fence closing)

<actual output>

createContextModeResultRenderer() in src/adapters/pi/mcp-bridge.ts handles Pi's collapsed (non-expanded) view by:

  1. Taking the full response text
  2. Splitting it by newlines
  3. Finding the first non-empty line
  4. If ≤ 180 chars, showing only that line

The first non-empty line is the opening of the code fence — the triple-backtick + language tag. So in collapsed mode, the user sees:

ctx_execute
(fence opening)shell

…and nothing else. The actual command, closing fence, and output are all hidden.

The same issue affects ctx_batch_execute (its formatCommandOutput prepends # <label>\n\n$ <cmd>\n\n).

Fix

PR: https://github.com/danyal002/context-mode/pull/1 (against next)

Added stripEchoPreamble() in src/adapters/pi/mcp-bridge.ts that strips both echo formats before finding the first meaningful line in collapsed mode. The full echo still reaches the LLM via execute() and survives in FTS5 indexed chunks — this only affects what the Pi TUI shows in collapsed mode.

Platform

Pi

context-mode version

1.0.169

Debug script output

ctx-debug JSON
{
  "version": "2.0.0",
  "generated": "2026-08-27T15:25:28Z",
  "sections": {
    "1. System Info": {
      "info": {
        "OS type": "macos",
        "uname -a": "Darwin COMP-K6MPF72D33 25.5.0 Darwin Kernel Version 25.5.0 arm64",
        "Architecture": "arm64",
        "macOS version": "26.5.1 (25F80)",
        "Shell": "/bin/zsh"
      }
    },
    "2. Runtime Versions": {
      "info": {
        "Node.js": "v26.5.0",
        "Python": "Python 3.10.13",
        "npm": "11.17.0"
      }
    },
    "3. context-mode Installation": {
      "info": {
        "Installed version": "1.0.169",
        "Plugin root": "/Users/danyal.khan/context-mode",
        "Install method": "git clone / manual",
        "npm latest": "1.0.169"
      }
    },
    "4. better-sqlite3 Native Module": {
      "checks": [
        { "pass": true, "label": "better-sqlite3 .node binary exists" },
        { "pass": true, "label": "require('better-sqlite3') succeeds" }
      ]
    }
  }
}

Exact prompt that triggered the bug

Any prompt that causes the agent to use ctx_execute with language: "shell". For example:

"Run ls -la using ctx_execute"

Full error output

Not a crash — the tool executes successfully. The bug is in the TUI rendering: the collapsed renderResult displays only the code fence opening (triple-backtick + shell) from the echo preamble instead of a meaningful summary line.

Steps to reproduce

  1. Start a Pi session with context-mode v1.0.169
  2. Send any prompt that triggers ctx_execute with language: "shell" (e.g. "Use ctx_execute to run: echo hello")
  3. Observe the TUI — the tool result area shows only the fence opening with no command or output visible
  4. Expand the tool result (if possible) — the full output including echo and result is visible in expanded mode

Expected behavior

The collapsed view should show the first meaningful line of actual output (e.g. hello for echo hello), not the markdown code fence opening.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions