feat: 新增金融事实语义封套 FinancialFact 并接入行情/财务能力 (close #24) - #82
Open
xuilen wants to merge 1 commit into
Open
Conversation
定义统一的 FinancialFact 封套, 使每个金融事实(行情/K线/财务指标/估值)都携带: - 规范化 instrumentId、metric、value、结构化 unit(currency/percent/basis-points/ratio/shares/scaled) - 原生 currency, 以及 asOf(数据自身时间戳) 与 retrievedAt(抓取时间) 分离, 绝不用本地 Date.now() 冒充 asOf - timing(live/delayed/eod/historical) 与 exchangeTimezone/marketSession 区分实时性 - 财务事实的 FiscalPeriod(quarter/fy/ttm/annual) 结构化解析 - raw/split-adjusted/dividend-adjusted 调整口径显式标记, 默认 unknown 而非猜测 - FX 换算 convertCurrency 保留原生 value/currency 与换算来源/汇率/汇率时点 - computeStale 按 timing 判定 stale, 供 UI/Agent 识别过期数据 将封套接入 quote/kline/financials/valuation 四个能力 manifest, 使 summary 能回答"何时/何种货币/何种口径"。缺省元数据一律显式标记 unknown, 绝不猜测。 新增 27 个单测(computeStale/convertCurrency/isPriceSeries/markUnknown/describeFact 及各 factory 映射), 全部通过。
helsome
requested changes
Sep 11, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
测试报告格式本身合格,但这条现在有一个需要先修的主干兼容问题:刚合入的 #59 已建立 canonical instrument identity,并在行情等结构上携带 instrumentId。你当前 quoteToFacts / klineToFacts 仍直接把 provider symbol(例如 NVDA.US)写成 FinancialFact.instrumentId,会把 canonical identity 又退回 ticker/provider symbol,导致 evidence/fact 关联出现两套身份。
请先 rebase 最新 main,并让 fact factory 优先使用上游 canonical instrumentId;只有确实没有 canonical identity 时才显式 fallback/unknown,不要把 symbol 冒充 canonical id。随后用 Bun 1.4.2 重跑现有 core + capability focused tests 即可。另外你报告里的 Windows path baseline 已被刚合入的 #70 修过,rebase 后请更新这一条测试结果。无需扩大成真实 provider E2E。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
实现 issue #24「定义 freshness / market-session / currency / adjustment 语义」。此前 Quote/Kline/财务指标/估值是散落的裸结构,货币、单位、调整口径、时效性都靠自由文本或约定,Agent/UI 无法可靠回答「什么时间、什么货币、什么口径」。
改动
packages/core/src/financial-fact.ts:统一FinancialFact封套instrumentId / metric / value+ 结构化unit(currency/percent/basis-points/ratio/shares/count/scaled)asOf(数据自身时间戳)与retrievedAt(抓取时间)分离,绝不用本地Date.now()冒充 asOftiming(live/delayed/eod/historical/unknown)、exchangeTimezone、marketSessionFiscalPeriod(quarter/fy/ttm/annual)结构化解析adjustment(raw/split-adjusted/dividend-adjusted/…)显式标记,缺省unknown而非猜测convertCurrency保留原生 value/currency + 换算来源/汇率/汇率时点computeStale按 timing 判定过期,供 UI/Agent 识别financial-fact-factories.ts:Quote/Kline/FinancialReport/CalcIndex → facts 的唯一定义处describeFact,CapabilityResult新增可选facts[](向后兼容)unknown,从不猜测测试报告
bun test packages/core→ 27 pass / 0 fail(新增)bun test packages/shared/src/capabilities packages/shared/src/agent→ 75 pass / 1 failpi-runtime-agent-backend.test.ts:529的 Windows 路径分隔符基线问题(/tmp/pi/s1.jsonlvs\tmp\pi\s1.jsonl),在 main 上即可复现,与本改动无关bunx tsc --noEmit:core / shared / longbridge-tools / pi-extension / ui / i18n / skill-hub 全部通过验收对照