← reports

#5847 · Shell intent parsing promotes a trailing output filter

Bug Medium priority Low effort threads provider-claude-code

2026-10-20 · Issue #5847 · trusted base e0f6fda5a02332bd4eb44183542a57f34f3263d7

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

The timeline can label a general shell command as a search when a later shell segment invokes grep. The command parser skips unrecognized initial executables, then promotes the first recognizable search segment to represent the entire command. A synthetic normalized command event reproduces the incorrect title in both the timeline title builder and the CLI text formatter, without executing any shell payload. Three non-search-first cases fail the expected command-title check in each of two clean trusted checkouts; a search-first control passes. This is a display classification defect, not evidence that the command itself changed or that any deletion occurred during verification.

2. Claims vs findings

ClaimFindingEvidence
A non-search command with a trailing grep is titled as a search.VerifiedPipe, AND-list, and semicolon-list synthetic events all produce “Searched for warning” titles.
The CLI also uses the misleading search label.VerifiedThe real timeline text formatter emits a search heading for each non-search-first case. Its command detail still contains the complete command.
The reported completed-turn row specifically reads “Explored 1 search”.Unverified exact wordingThe minimal one-command fixture emits a direct search heading, not that aggregate heading. The wrong search intent is directly confirmed.
A cleanup operation removed a large amount of data.Not testedNo issue-supplied command or script was executed; all commands in this reproduction are inert event strings.
Flat completed turns should offer another expansion preference.Separate feature requestNo product-setting changes are proposed by this report.

3. Environment

4. Minimal reproduction

  1. Use a clean checkout at the recorded base commit, then install and build the trusted source:
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Download repro.mjs to a scratch directory. From the checkout root, run:
    node --conditions=source --import tsx /path/to/repro.mjs "$PWD"
    The driver creates synthetic command-start/completion events, renders a flat completed turn, and compares actual timeline titles to independently specified expected titles. It never spawns or evaluates the command strings.
  3. Expected: all comparisons pass and Mismatches: 0. Actual on trusted main: exit 1 and Mismatches: 3:
    Command: node build.mjs 2>&1 | grep -v warning | tail -n 5
    Expected title: Ran node build.mjs 2>&1 | grep -v warning | tail -n 5
    Actual title: Searched for warning
    CLI heading: ── Searched for warning ────────────────────────────────────
    
    Command: node build.mjs && grep warning build.log
    Expected title: Ran node build.mjs && grep warning build.log
    Actual title: Searched for warning in build.log
    
    Command: node build.mjs; grep warning build.log
    Expected title: Ran node build.mjs; grep warning build.log
    Actual title: Searched for warning in build.log
    
    Search-first control: grep warning build.log | tail -n 5
    Expected and actual: Searched for warning in build.log
    Mismatches: 3
    Exact JSON output: first run and second run. This is a semantic-label/text-formatter reproduction; no screenshot or macOS UI verification is claimed.
Complete reproduction driver
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";

const root = resolve(process.argv[2] ?? process.cwd());
const source = (path) => pathToFileURL(resolve(root, path)).href;
const { createTimelineEventFactory, renderTimelineFixture, flattenTimelineRows } =
  await import(source("packages/thread-view/test/timeline-test-harness.ts"));
const { buildTimelineViewRows, buildTimelineRowTitle } =
  await import(source("packages/thread-view/src/index.ts"));
const commands = [
  "node build.mjs 2>&1 | grep -v warning | tail -n 5",
  "node build.mjs && grep warning build.log",
  "node build.mjs; grep warning build.log",
  "grep warning build.log | tail -n 5",
];
let failures = 0;
for (const command of commands) {
  const event = createTimelineEventFactory({ threadId: "thread-1", turnId: "turn-1" });
  const fixture = renderTimelineFixture({
    completedTurnDisplay: "flat",
    verbose: false,
    events: [
      event.turnStarted({ createdAt: 0 }),
      event.commandStarted({ itemId: "command-1", command, createdAt: 1_000 }),
      event.commandCompleted({ itemId: "command-1", command, exitCode: 0, createdAt: 2_000 }),
      event.assistantCompleted({ itemId: "answer", text: "Done.", createdAt: 3_000 }),
      event.turnCompleted({ createdAt: 4_000 }),
    ],
    projectionOptions: { turnMessageDetail: "full" },
  });
  const rows = flattenTimelineRows(fixture.rows).filter((row) => row.kind === "work");
  const titles = buildTimelineViewRows(rows).map((row) =>
    buildTimelineRowTitle(row, { summaryStyle: "bundle", workStyle: "default" }).plain,
  );
  const expectedTitle = command.startsWith("grep ")
    ? "Searched for warning in build.log"
    : `Ran ${command}`;
  const passed = titles.length === 1 && titles[0] === expectedTitle;
  if (!passed) failures += 1;
  console.log(JSON.stringify({ command, expectedTitle, titles, text: fixture.text, passed }, null, 2));
}
console.log(`Mismatches: ${failures}`);
process.exitCode = failures === 0 ? 0 : 1;

5. Root cause

classifyShellSegment returns kind: "none" for general executables, while grep and rg produce search intents. In parseShellCommandIntents, only a detected write clears the result and stops iteration. A none segment is silently skipped; a subsequent search becomes the first retained intent:

if (classification.kind === "write") {
  intents = [];
  return false;
}
if (classification.kind === "intent" && intents.length === 0) {
  intents.push(classification.intent);
}
return true;

This is not a malformed grep pattern or provider execution problem. Command lifecycle projection computes these intents from the full normalized shell string. The title builder then prefers a single exploration-intent title over the full command title. Thus an output filter can replace the visible identity of a general command. The underlying command detail remains available; the headline is misleading.

6. Proposed fix

Conservatively refuse to derive an exploratory summary when the first nonempty shell segment has no recognized exploratory intent. Keep the existing scan of later segments for write disqualification after a recognized first segment. This restores the existing generic command label and complete command text for the demonstrated cases, while preserving genuine search-first pipelines. Add a regression table at the real event-to-timeline-title boundary and correct the old parser fixture that currently expects a search title after unrelated initial commands. No protocol, storage, dependency, or new expansion setting is needed.

7. Pull request review

No open pull request linked to #5847 was present in the GitHub search or issue timeline when checked. No external or linked-PR code was checked out or run.

8. Related issues

#3709 and #3710 concern command presentation preferences and formatting. They do not establish a fix for the reproduced classification error.

9. Verification

The same agent repeated the complete reproduction in a second, freshly created detached worktree named verify at the exact recorded base commit, after a separate frozen install and successful full build. Before running, git status --short was empty and git rev-parse HEAD matched the base. Command: node --conditions=source --import tsx ../repro.mjs "$PWD". Result: exit 1, the same three wrong labels, and the passing search-first control. The two JSON logs are byte-for-byte identical. This is a repeated clean reproduction by one agent, not an independent review.

An initial draft of the driver checked row kinds; inspection showed normalized shell rows remain command rows even when their titles are search labels. The final driver and this report check observable titles instead. The report also narrows the aggregate-heading claim: the exact one-search bundle wording was not reproduced in this minimal fixture.

10. Appendix and scope

The existing parser and v3 projection suites pass on the baseline: 62 tests in two files. Command: pnpm exec turbo run test --filter=@bb/thread-view -- test/tool-call-parsing.test.ts test/v3-item-projection.test.ts. Their current coverage misses non-search-first command titles and includes one parser expectation that promotes a later search.

Reproduction commands and exact results are saved in the linked driver and two logs. Build commands are listed above. No actual shell payload, issue-supplied script, private filesystem path, user data, or destructive action was used. Issue content was treated only as untrusted claims; its expansion-setting request was not treated as an instruction.