Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(cli): keep empty edge columns when parsing markdown tables

santhreal92f0f6e35dbb
diff --git a/agent/cli/ui/transcript.py b/agent/cli/ui/transcript.py
index a768155f3..45d6fd2ba 100644
--- a/agent/cli/ui/transcript.py
+++ b/agent/cli/ui/transcript.py
@@ -146,8 +146,14 @@ def _parse_table(lines: list[str]) -> Table | None:
def _split_row(line: str) -> list[str]:
- stripped = line.strip().strip("|")
- return [cell.strip() for cell in stripped.split("|")]
+ # Peel only the row's bounding pipes; str.strip("|") would also drop empty
+ # leading/trailing cells (||Name| → Name, |a|b|| → a|b).
+ parts = line.strip().split("|")
+ if parts and parts[0] == "":
+ parts = parts[1:]
+ if parts and parts[-1] == "":
+ parts = parts[:-1]
+ return [cell.strip() for cell in parts]
def _clean_inline_markdown(text: str) -> str:
diff --git a/agent/tests/test_cli_parse_table_edge_columns.py b/agent/tests/test_cli_parse_table_edge_columns.py
new file mode 100644
index 000000000..5e77eb302
--- /dev/null
+++ b/agent/tests/test_cli_parse_table_edge_columns.py
@@ -0,0 +1,45 @@
+"""CLI transcript tables must keep empty leading/trailing columns."""
+
+from __future__ import annotations
+
+from cli.ui.transcript import _parse_table, _split_row
+
+
+def test_split_row_keeps_empty_edge_cells() -> None:
+ assert _split_row("|Name|Qty||") == ["Name", "Qty", ""]
+ assert _split_row("||Name|Qty|") == ["", "Name", "Qty"]
+ assert _split_row("|a|1|note|") == ["a", "1", "note"]
+
+
+def test_parse_table_keeps_trailing_empty_header_column() -> None:
+ lines = [
+ "|Name|Qty||",
+ "|---|---|---|",
+ "|a|1|note|",
+ "|b|2|other|",
+ ]
+ table = _parse_table(lines)
+ assert table is not None
+ assert [col.header for col in table.columns] == ["Name", "Qty", ""]
+ assert [col._cells for col in table.columns] == [
+ ["a", "b"],
+ ["1", "2"],
+ ["note", "other"],
+ ]
+
+
+def test_parse_table_keeps_leading_empty_header_with_row_labels() -> None:
+ lines = [
+ "||Name|Qty|",
+ "|---|---|---|",
+ "|row1|a|1|",
+ "|row2|b|2|",
+ ]
+ table = _parse_table(lines)
+ assert table is not None
+ assert [col.header for col in table.columns] == ["", "Name", "Qty"]
+ assert [col._cells for col in table.columns] == [
+ ["row1", "row2"],
+ ["a", "b"],
+ ["1", "2"],
+ ]