fix(cli): format structured commands in history export#12023
Conversation
Greptile SummaryThis PR fixes a crash in the CLI history export when a
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the HTML export path and re-uses an already-tested helper. The change touches only the display layer of history export. No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/cli/src/utils/helpers.ts | Exports the previously private formatStructuredCommand helper so it can be reused in export.ts; no logic changes. |
| apps/cli/src/session/export.ts | Widens renderCommandsHTML parameter from string[] to unknown[] and routes each element through formatStructuredCommand before HTML-escaping, fixing the crash on structured { command, args } entries. |
| apps/cli/src/commands/history.test.ts | Adds a focused regression test that exercises the structured-command export path and asserts the formatted output appears in the HTML. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["renderCommandsHTML(commands: unknown[])"] --> B{"forEach command"}
B --> C["formatStructuredCommand(cmd)"]
C --> D{"typeof cmd"}
D -->|string| E["return cmd as-is"]
D -->|object with 'command' key| F["return 'command args...' joined"]
D -->|other| G["return String(cmd)"]
E --> H["escapeHtml(result)"]
F --> H
G --> H
H --> I["Rendered HTML <code> block"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["renderCommandsHTML(commands: unknown[])"] --> B{"forEach command"}
B --> C["formatStructuredCommand(cmd)"]
C --> D{"typeof cmd"}
D -->|string| E["return cmd as-is"]
D -->|object with 'command' key| F["return 'command args...' joined"]
D -->|other| G["return String(cmd)"]
E --> H["escapeHtml(result)"]
F --> H
G --> H
H --> I["Rendered HTML <code> block"]
Reviews (2): Last reviewed commit: "Merge branch 'main' into freshness/cline..." | Re-trigger Greptile
There was a problem hiding this comment.
Pull request overview
Fixes a CLI history export crash when run_commands tool calls store commands as structured objects ({ command, args }) instead of plain strings, by formatting commands through the existing structured-command formatter before HTML-escaping.
Changes:
- Exported
formatStructuredCommandfrom the CLI helpers so it can be reused by history export. - Updated history export HTML rendering to accept
run_commandsentries containing structured command objects. - Added a regression test covering structured
run_commandscommand objects in exported history HTML.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/cli/src/utils/helpers.ts | Exports the existing formatStructuredCommand helper for reuse outside the module. |
| apps/cli/src/session/export.ts | Uses formatStructuredCommand() when rendering run_commands entries to prevent non-string crashes during escapeHtml(). |
| apps/cli/src/commands/history.test.ts | Adds coverage ensuring structured command objects export correctly (e.g. cmd /c dir). |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17f0803e9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
History export could crash when a saved
run_commandsentry used the structured{ command, args }form instead of a plain string.This formats each command through the CLI's existing structured-command helper before escaping it, while string commands keep the same output path. I checked the focused history/helper tests, typecheck, Biome, SDK build, the full CLI unit suite with 784 tests passing, and the CLI build.
Fixes #11942