Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): match a report-style date cell, and resolve a US CSV stem

Haozhe Wu335eb0ef1365
diff --git a/agent/src/agent/grounding.py b/agent/src/agent/grounding.py
index 0eff61f23..3a2b728e7 100644
--- a/agent/src/agent/grounding.py
+++ b/agent/src/agent/grounding.py
@@ -88,7 +88,16 @@ _CSV_DATE_COLUMNS = {"date", "datetime", "trade_date", "timestamp", "index"}
# Filename -> symbol mapping for run-dir CSVs. The bash workaround writes each
# series with a filesystem-safe stem: ``BYN_V.csv`` for ``BYN.V``, ``PDI_TO.csv``
# for ``PDI.TO``, ``GC_F.csv`` for ``GC=F``.
-_CSV_FILENAME_SUFFIX_MAP = (("_V", ".V"), ("_TO", ".TO"), ("_F", "=F"))
+_CSV_FILENAME_SUFFIX_MAP = (
+ ("_V", ".V"),
+ ("_TO", ".TO"),
+ ("_F", "=F"),
+ # A US name is written ``INTC_US.csv`` by the same workaround, and
+ # ``.US`` is the venue suffix the rest of the project resolves on. Without
+ # this row the CSV was ingested as no evidence at all, so every price the
+ # run had actually fetched came back "numeric_claim_unavailable".
+ ("_US", ".US"),
+)
# Only ``get_market_data`` returns bars whose columns are already the canonical
# OHLC field names. Every other market-sensitive tool nests its quote somewhere,
@@ -643,8 +652,18 @@ def _coerce_csv_number(value: Any) -> int | float | None:
# "." is deliberately not a separator: a decimal price such as 8.5 would parse
# as month 8 day 5 and match a real trading day.
+# A report writes the day as a table cell -- "08-10(一)", "08-10(周一)盘中",
+# "08-10盘中" -- and the weekday or session suffix made the cell match no
+# evidence row at all, so every price in that row came back
+# "numeric_claim_unavailable" even though the run had fetched the bar.
+_TRADING_DAY_SUFFIX = (
+ r"(?:\s*[((]\s*(?:周|星期)?[一二三四五六日天]\s*[))])?"
+ r"\s*(?:盘中|盘后|盘前|收盘|开盘|早盘|尾盘)?"
+)
_YEARLESS_CLAIM_DATE_RE = re.compile(
- r"^(0?[1-9]|1[0-2])\s*[-/月]\s*(0?[1-9]|[12]\d|3[01])\s*[日号]?$"
+ r"^(0?[1-9]|1[0-2])\s*[-/月]\s*(0?[1-9]|[12]\d|3[01])\s*[日号]?"
+ + _TRADING_DAY_SUFFIX
+ + r"$"
)
_ISO_TIMESTAMP_RE = re.compile(r"^(\d{4})-(\d{1,2})-(\d{1,2})")
diff --git a/agent/tests/test_agent_grounding.py b/agent/tests/test_agent_grounding.py
index cf4de497a..31263ab39 100644
--- a/agent/tests/test_agent_grounding.py
+++ b/agent/tests/test_agent_grounding.py
@@ -2239,3 +2239,31 @@ def test_an_order_line_is_an_instruction_not_an_observation(tmp_path: Path) -> N
"000543.SZ 收盘价 8.20 CNY,挂单 100 股 @ 12.00(source: tencent)"
)
assert result.valid is True, result.issues
+
+
+def test_a_report_style_date_cell_still_matches_its_evidence_row() -> None:
+ """"08-10(一)" and "08-10盘中" are the same trading day as "08-10".
+
+ A weekday or session suffix made the cell match no evidence row, so every
+ price in that row was reported numeric_claim_unavailable even though the
+ run had fetched the bar.
+ """
+ from src.agent.grounding import _timestamp_matches_claim_date
+
+ stamp = "2026-08-10T15:00:00Z"
+ for claim in ("08-10", "8-10", "08-10(一)", "08-10(周一)", "08-10(周一)盘中", "08-10盘中", "08-10收盘"):
+ assert _timestamp_matches_claim_date(stamp, claim) is True, claim
+
+ # The suffix is decoration, not a wildcard — a different day still misses.
+ assert _timestamp_matches_claim_date(stamp, "08-11(一)") is False
+
+
+def test_a_us_csv_stem_resolves_to_its_venue_suffix() -> None:
+ """``INTC_US.csv`` is ``INTC.US``; without the row it was no evidence at all."""
+ from src.agent.grounding import _symbol_from_csv_filename
+
+ assert _symbol_from_csv_filename("INTC_US") == "INTC.US"
+ assert _symbol_from_csv_filename("BYN_V") == "BYN.V"
+ assert _symbol_from_csv_filename("GC_F") == "GC=F"
+ # A bare name has no venue suffix and must stay unresolvable.
+ assert _symbol_from_csv_filename("AAPL") is None