Commit Graph
111 Commits
Author SHA1 Message Date
zhanghongyu_0626 b04af6e701 feat(docs): Update demo SOP and enhance documentation for advisor agent
- Added new entry for "STAFF-20003" role in `jwt_service.py` to support additional user permissions.
- Revised the demo SOP documentation to reflect updated processes and clarify the presentation flow, including changes to the demo script and internal guidelines.
- Enhanced the presentation materials with a new HTML slide deck for the advisor agent demo, ensuring a cohesive visual representation of the features and capabilities.
- Updated various documentation files to align with recent changes in the advisor agent functionalities and testing baselines.

This update improves the clarity and usability of the demo materials while ensuring that the documentation accurately reflects the current state of the project.
2026-09-13 17:44:09 +08:00
zhanghongyu_0626 2296a4a002 feat(api): Add convert_meta_api for retrieving latest NAV date and enhance created_at field handling
- Introduced `convert_meta_api` endpoint to fetch the latest NAV date for conversion processes, restricted to users with the "risk_officer" role.
- Updated `created_at` field in `AgentMessage` to use UTC timezone for consistency in timestamp handling.
- Added `get_max_product_nav_date` method in `CoreReadOnlyRepository` to support the new API functionality.
- Enhanced Milvus template loading in `MilvusTemplateVectorStore` to ensure collections are loaded when they exist.

This update improves the API's capability to handle conversion metadata and ensures accurate timestamp management across the application.
2026-09-13 12:40:44 +08:00
zhanghongyu_0626andCursor c09b987ffe feat(web): 基金转换演示页与 agent 镜像表迁移; Core seed 修复
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-12 17:59:10 +08:00
zhanghongyu_0626andCursor 03fce883d4 merge(risk-control-agent): fund convert T+1 on merger base (plan A)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-12 17:52:17 +08:00
GaoYiYuan_0626 88cdfe6ad8 文档:合并请求订正为 PR #3(base=merger,用户指出 PR #2 分支错误已关闭)· 冲突按 merger 重测 15 文件 2026-09-12 17:41:23 +08:00
zhanghongyu_0626 c7fa32ef62 docs(advisor): 顾问线已合入 merger,同步记忆与 E2E 日志
- MEMORY/TODO/合并说明:integrate/advisor-agent 已通过 fast-forward 并入 merger(4be27c5)
- ADV-001:补充 4be27c5 与 64c5db7 后端结论仍成立,无需重跑
2026-09-12 17:23:09 +08:00
zhanghongyu_0626 4be27c589c 合并一下 2026-09-12 17:16:15 +08:00
zhanghongyu_0626 64c5db73a9 refactor(kyc): Remove ApiResponse response model from KYC session endpoints
- Updated KYC session endpoints to remove the ApiResponse response model, simplifying the API structure.
- Enhanced clarity in the KYC session creation, retrieval, chat, and completion methods by focusing on the payload and response data directly.
- Improved code readability and maintainability by streamlining the endpoint definitions.
2026-09-12 16:48:25 +08:00
zhanghongyu_0626 d394686a3b feat(advisor-agent): Integrate advisor agent functionalities and migration scripts
- Merged the `integrate/advisor-agent` branch into the `merger`, enhancing the advisor agent's capabilities with compliance, KYC, and script templates.
- Updated the testing baseline to reflect 926 passed tests, with 65 failures concentrated in the advisor agent's `test_sprint*` cases.
- Introduced new migration scripts for advisor-related database structures, ensuring smooth integration and data management.
- Enhanced documentation to include the new API structure and integration details, providing clarity for future development.

This update significantly advances the advisor agent's functionality while maintaining a structured approach to integration and testing.
2026-09-12 16:37:29 +08:00
GaoYiYuan_0626 2453e73ad0 文档:PR #2 创建留痕(风控+基金转换并入 main · 中文描述 · 冲突实测 23 文件) 2026-09-12 16:27:14 +08:00
GaoYiYuan_0626 08389371a7 文档:里程碑 tag convert-m1 落账(指向收官提交 292770f · 已推送远程 · MEMORY 对照表更新) 2026-09-12 15:19:59 +08:00
GaoYiYuan_0626 292770f1fb README:最新更新章节(转换线收官/集成测试/种子补拉)+ 前端已留接口契约(chat 四端点 + 基金转换四端点)+ 全仓文档推送状态回写 2026-09-12 15:15:51 +08:00
zhanghongyu_0626 973bf1b834 feat(advisor-agent): Integrate advisor agent into merger with new API structure
- Merged `xinghuo/advisor-agent` into the `merger` branch, establishing a new API prefix `/api/advisor-agent` to avoid conflicts with existing endpoints.
- Implemented a comprehensive implementation plan detailing the integration steps, including conflict resolution, database migrations, and service adaptations.
- Introduced new files for advisor compliance, script templates, KYC, and market alerts, ensuring a cohesive addition to the existing architecture.
- Updated documentation to reflect the new structure and integration process, enhancing clarity for future development and maintenance.

This integration significantly expands the capabilities of the merger, providing a robust framework for advisor-related functionalities while maintaining compliance and operational integrity.
2026-09-12 15:14:29 +08:00
zhanghongyu_0626 601ed258f3 feat(analyst): Enhance asset management and ambiguity detection features
- Added new endpoints to the analyst API for managing assets, including `GET /assets` to list assets and `POST /assets/{kind}/{asset_id}/publish` to publish assets.
- Introduced `DictAmbiguityCheckRequest` schema for checking metric ambiguities, enhancing the analyst's ability to clarify definitions and aliases.
- Implemented `detect_dict_ambiguity` function to analyze potential ambiguities in metrics, providing structured feedback for users.
- Updated `AnalystAgent` to support the new asset management functionalities and ambiguity detection logic, improving overall user experience.
- Enhanced existing schemas and services to accommodate new features, ensuring robust data handling and validation.

This update significantly improves the analyst API's capabilities, allowing for better asset management and clarity in metric definitions.
2026-09-12 15:14:01 +08:00
GaoYiYuan_0626 eac6b61ce4 文档:第 6 步集成测试收官(转换线 AIcoding 六步全流程完成 · 849 绿 / CONVERT_STRESS 7/7 / 真库 9/9 / 紧池 100% 重测) 2026-09-12 14:52:01 +08:00
GaoYiYuan_0626 b411d5a087 T-14/T-17 开口闭环:PRD §2.5.3 修订 + truncate 舍去法接入 + R-12 定稿(用户三项拍板 · 849 绿 / 真库 9/9)
① PRD §2.5.3 修订:删「易方达 ETF 场外取整数位」(无证据且有反证,真实整数位载体为场内),改记「2 位主流 + 舍去型真实存在」,版本块加注记
② rounding_mode=truncate 消费接入(用户拍板补做):
   - core_ro.get_share_rounding = 位数+模式回退链单点(规则行 → core_product → 默认 2/half_up,mode 白名单读取即校验,get_share_digits 转薄包装)
   - calc.product_round/in_qty 加 mode 参数(truncate → ROUND_DOWN)
   - 确认段 + 申购折算两处透传;载体 09-seed-org.sql ⑦ 段 PROD-005828(product 层回退,零转换场景引用)
   - 测试 +7(842→849):calc 4 + 确认段 2(truncate 34945.53 vs half_up .54 分化 + 回退链遮蔽语义)+ 申购段 1
   - 突变:两调用点同拆 mode 透传 → 2 红,还原绿;真库 9/9(seed 新增 ⑫ 载体在位断言)
③ R-12 口径裁定追认定稿:条目回写开发计划(NULL 不参与 A/C 判定 / 同类走一般转换规则)

审核教训留痕:PRD 独立 AI 三轮审查未抓出外部事实断言无出处 —— 联网核实铁律再添例证
文档:开发计划 T-14 开口闭环段 + 基线 849 · 日志新节 · TODO/MEMORY/AGENTS/交接文档开口清零
2026-09-12 14:31:35 +08:00
GaoYiYuan_0626 cde0c226fe 基金转换 T+1 模型:T-15/T-16/T-17 收官(842 绿 / 真库 9/9 / 转换线第 5 步完成)
T-15 D28 部分成交专项:
- sqlite +1 终态单幂等 skipped 口径裁定(ConfirmConflict 仅限读后状态才变窗口)
- 真库 confirm +3 组 19 项(E2 占用释放双向 / G2 actual_qty=0 → rejected / H2 撤单后确认)→ 102/102
- CONVERT_STRESS Barrier(2) 窄窗争批:恰 1 confirmed + 1 rejected
- 突变实证防御纵深:④可用量复核 / ⑤plan_lots / 事务内哨兵三道防线拆任一道仍收敛 rejected

T-16 D29 资金流中转:
- _insert_cash_flows 全仓唯一写入点(out/redeem 费前 + in/subscribe 净转入,remark=convert:{gid} 同事务)
- test_confirm_writes_no_cash_flow 反转为恰 2 条 + 金额对账(T-7 登记闭环)
- 真库 apply A2 组 + B 组 0 残留 → 30/30;confirm 反转断言 → 103/103
- FK 坑(core_cash_flow.fk_cf_customer 挡客户删除):5 处清理段补删

T-17 D30 share_class + A/C 互转:
- _validate_products 纯新增拦截分支:两端 share_class 非空且不同才查 allow_ac_convert(任一端=1 两向放行)
- 口径裁定 2 条(R-12 字面偏差,待用户追认):NULL 不参与 A/C 判定 / 同类走一般转换规则
- 联网核实(用户铁律):A/C 互转需管理人开通(摩根 2025-11 公告)= 开关真实载体;持有期重新起算与本仓一致
- 种子 ⑥ 段(双开对/双关对照/同类对照);sqlite +4 → 842 passed / 8 skipped;真库 accept H 组 → 43/43
- 突变:分支失效 → closed 红,还原绿

文档:开发计划 T-15~T-17 DoD 全勾 + 执行记录 · 基线 842 · TODO/MEMORY/AGENTS/交接文档 v4.5 终态(第 5 步收官 → 下一步第 6 步集成测试)
2026-09-12 13:42:49 +08:00
GaoYiYuan_0626 1a615bbbef 基金转换 T+1 模型:T-14 D27 产品舍入真正接入 + 联网核实纠偏(837 绿 / 真库 9/9 / 种子 v1.1 全 2 位)
- 接入面 4 处单点收敛:core_ro.get_share_digits(唯一回退链:规则行→core_product.share_digits→PLACES=2)· calc.in_qty 加 digits=PLACES 可选参数 · 确认段(business_type=convert)· 网关申购折算(subscribe);redeem 份额申报无折算无消费方
- 边界裁定:只接落库侧(开发计划 DoD 即边界),响应展示维持 q(D2) 收敛(2 位产品逐字节零漂移);PRD §2.5.2 展示按产品覆盖为登记开口
- 联网核实(用户铁律):主流 2 位 ✅ · 位数按各基金合同配置 ✅(南方 2012 调整公告)· 舍去 TRUNCATE 型真实存在 ✅ · 货基 2 位 ✅ · 「指数基金份额 4 位」证伪 ❌(ETF 联接/指数合同全 2 位)→ 11-seed-share-rule.sql v1.1:3 产品 9 行 4→2 + 头注重写为核实出处;「易方达 ETF 场外整数位」无证据有反证(登记开口待拍板)
- 测试 +7(830→837 零回归):calc 层 2 + confirm 段 3(回退链三层各 1 + business_type 干扰行)+ 申购段 2;4 位种子行 = D27 机制验证载体(docstring 钉明)
- 突变验证 2 组(confirm/gateway digits 改固定 2 → 各 2 红,还原零残留);真库 9/9 退出码 0(seed 重灌 42 行全 2 位生效)
- 开口 2 项待用户拍板:① PRD §2.5.3 易方达句修订 ② rounding_mode=truncate 消费接入(真实存在、T-14 范围外)
2026-09-12 12:41:20 +08:00
zhanghongyu_0626 a0f550646e feat(analyst): Add analyze endpoint and chart specification validation
- Introduced a new `/analyze` endpoint in the analyst API to process analysis requests, allowing users to receive textual interpretations and chart specifications based on provided prompts.
- Enhanced `analyst_schemas.py` with `AnalyzeRequest` and `ChartSpec` models to structure analysis requests and validate chart specifications.
- Implemented chart validation logic in a new `analyst_chart.py` service, ensuring that chart types and fields are correctly specified and conform to allowed values.
- Updated `AnalystAgent` to handle analysis requests, integrating the new logic for generating responses based on user prompts and data availability.
- Added unit tests to verify the functionality of the new endpoint and validation mechanisms, ensuring robustness and reliability.

This update significantly enhances the analytical capabilities of the application, providing users with improved tools for data interpretation and visualization.
2026-09-12 12:33:37 +08:00
GaoYiYuan_0626 5f7ad9180b 文档:T-13 回写 + 全仓进度一致性(开发计划 DoD 6/6 全勾 + 执行记录 · PRD §9 第 18/31 条实测回填 · 交接文档 v4.3) 2026-09-12 11:58:42 +08:00
GaoYiYuan_0626 9ad8a90de1 文档:T-12 回写 + 全仓进度一致性(开发计划 DoD 全勾 + 执行记录)
- 开发计划 v2.0 T-12 节:DoD 4/4 全勾 + 执行记录(三改动面 / 联网核实留痕 /
  confirm_one 留痕修复 / 真库 56/56 / 突变 4 组 / rebuild_alerts 路径勘误)
- 交接文档 v4.2(T-12 完成块 + 基线 849,.gitignore 内不入库)
- TODO.md / MEMORY.md / AGENTS.md:T-1~T-12 ✅ / T-13~T-17 ⬜,基线 849
- 2026-09-12.md 追加 T-12 执行记录(含用户铁律:外部真实业务事实必须联网核实)
2026-09-12 10:55:01 +08:00
GaoYiYuan_0626 b4a61dc306 文档:T-11 回写 + 全仓进度一致性(开发计划 DoD 全勾 + 执行记录 / 交接文档 v4.1 / TODO / MEMORY / AGENTS / 当日日志) 2026-09-12 09:35:13 +08:00
zhanghongyu_0626 d4a2461ba4 feat(nav): Enhance product API with historical NAV tracking and new charting features
- Updated `ready.py` to include a health check for the new `products_nav_history` endpoint, ensuring system readiness.
- Enhanced the `ProductNavChartPanel` component to visualize historical NAV data with various charting options, including line and column charts.
- Introduced new utility functions for filtering and aggregating NAV data, improving data handling in the frontend.
- Updated tests to verify the inclusion of the new `products_nav_history` check in the API response.
- Improved documentation to reflect recent changes and the new testing baseline of 833 passed tests, indicating enhanced stability.

This update significantly improves the product API by providing access to historical NAV data and enhancing user insights through visualizations.
2026-09-11 21:38:54 +08:00
GaoYiYuan_0626 5a784dc185 文档:T-10 回写 + 全仓进度一致性(开发计划 DoD 全勾 + 执行记录)
- 开发计划 v2.0:T-10 六项 DoD 全勾(申购落批次 / 哨兵不超扣 / T+2 半开区间
  双向 / 金额公式 D26 / 转换后不超扣验收 9 / rebuild 无漂移)+ 新增执行记录
  (改法、验证证据 844 passed、真库 89/89、突防验证、3 处断点与口径)
- 交接文档 v4.0(gitignore 不入库,本轮未提交)
- AGENTS.md 入口引用 → T-1~T-10 ✅ / 844 / 89/89 / 下一步 T-11
- docs/memory/TODO.md:T-10 完成条目 + 待办行 T-11~T-17
- docs/memory/MEMORY.md:进度 + 自检第 5/6 问 → 844 / T-1~T-10
2026-09-11 21:24:40 +08:00
zhanghongyu_0626 2b4eaa9725 feat(nav): Implement historical NAV tracking and enhance product API
- Added `list_nav_history` method in `CoreReadOnlyRepository` to retrieve historical NAV data for products over a specified number of days.
- Introduced `get_nav_history` endpoint in `product_service` to return historical NAV sequences, improving product data accessibility.
- Updated `products.py` to include new API endpoint for fetching NAV history, ensuring compliance with access control.
- Enhanced `ready.py` to include a health check for the new functionality, ensuring system readiness.
- Updated documentation to reflect the new testing baseline of 833 passed tests, indicating improved stability and functionality across the application.

This update significantly enhances the product API by providing access to historical NAV data, improving user insights into product performance.
2026-09-11 20:47:18 +08:00
GaoYiYuan_0626 6ecde37885 文档:convert_fund 退役并入 T-13(用户 2026-09-11 裁定)
开发计划 T-13 目标/改法 6/DoD/风险补「convert_fund 退役 + 清理 v1.0 依赖链」;
TODO 待办行补注裁定。本地提交,未推送远程
2026-09-11 20:42:37 +08:00
GaoYiYuan_0626 2277d61568 文档:T-9 回写 + 全仓进度一致性(开发计划 DoD 全勾 + 执行记录 / 交接文档 v3.9 / TODO / 两份 MEMORY / AGENTS.md)
开发计划 T-9 新增执行记录(附 2 处口径缺陷细节);各入口进度统一
T-1~T-9 ✅ / 834 passed / 真库 verify_convert_api 88/88 / 下一步 T-10
2026-09-11 20:37:51 +08:00
GaoYiYuan_0626 9f28633e55 文档:T-8 回写 + 全仓进度一致性复核(订正 5 处漏同步)
本轮在 T-8 提交(57f16a5)后做文档回写,并对全仓「同一事实的副本」做一致性扫描,
发现并当场订正 5 处漏同步(均属上次改了主状态位、漏改副本):

- AGENTS.md 入口引用(最重要,属项目记忆已强调的「全仓同步入口引用」漏项):
  T-1~T-6 ✅/797 基线/下一步 T-7 → T-1~T-8 ✅/829 基线/下一步 T-9;
  T-6 真库 verify_convert_accept.py 36/36 → 37/37,并并列 83/83、39/39。
- docs/memory/TODO.md:汇总待办行「T-8 ~ T-17(含已完成之引擎时机)」→「T-9 ~ T-17」;
  为 v0.x 线引用块加编号歧义提示(其 T-11/T-12 与新线同号且均涉 amount_view,易混)。
- docs/memory/MEMORY.md:自检问答第 6 问进度 T-1~T-7 ✅/827 → T-1~T-8 ✅/829。
- 开发计划(T-8 执行期订正,承 57f16a5 代码提交):
  就地订正 T-7 执行记录第 2 条「T-8 剩余仅为 rules.amount_view」之误(F-10 明确 T-8 不动去重口径,属 T-11);
  新增 T-8「执行记录」5 条差异裁定;DoD 全勾。

不入库但同批完成(交接文档.md 受 .gitignore 忽略):
  - 顶部版本 v3.7 → v3.8;§③ 表格行;§B.11 状态块(T-8 完成 + 两处订正);
  - 开工纪律行 T-1~T-6 → T-1~T-8;
  - §B.11「未落地(T-1 起执行)」立项期清单 → 「已落地」并附实测行号
    (01-ddl.sql 272/297/305 行;已进 reset.ps1 与 verify_convert_seed.py 清单),原文折叠留痕。

复核:全量 pytest -q → 829 passed / 10 skipped(16.37s,零失败)。
2026-09-11 19:53:31 +08:00
GaoYiYuan_0626 0e27fec5cb 文档:T-7 确认段落地回写(开发计划 DoD 全勾 + 执行记录 / 交接文档 §B.11 / TODO / 两处 MEMORY)
- 开发计划 T-7:DoD 9 项勾选 + 新增「执行记录」小节,逐条留痕 6 处与计划的差异裁定:
  ① 确认段不做最低持有重判(计划缺口,强制全转属受理段决策,受理单 remark 传承);
  ② 新增 format/audit/engine_call 三共用模块(后者顺带完成 T-8 的「引擎时机改」);
  ③ nav.py 未改(确认段直调 core_ro.get_nav_on,取 T−1 路径随 v1.0 convert_fund 一并删);
  ④ test_convert_integration 改写推迟到 T-9(需端到端真接口);
  ⑤ 受理单置 confirmed 并入 apply_convert 同事务(防「批次已扣、状态未置」中间态);
  ⑥ MySQL rowcount=changed rows 陷阱(nav_pending 重试不得复用冲突判定)。
- 交接文档 §B.11:T-6→T-7 完成、基线 797→827、真库 36/36→37/37 与 83/83、
  新增 T-7 实施期发现段、下一步 T-8/T-9(并注明 T-8 范围已缩小)。
- docs/memory/TODO.md:进度行 + T-6 真库数 + T-7 条目勾选与详述。
- .workbuddy/memory/MEMORY.md 与 docs/memory/MEMORY.md:进度与关键裁定同步;
  当日工作日志补「续 3:T-7 确认段落地」。
2026-09-11 19:37:30 +08:00
GaoYiYuan_0626 f056fcd007 基金转换 T+1 模型:T-1~T-6 落地(DDL/数据层/语义收窄/锁/受理事务)
AIcoding 第 5 步 todo 开发(开发计划 v2.0)前半段:

- T-1 3 张新表 DDL(core_convert_request 6 态 ENUM / core_trade_calendar /
  core_share_rule)+ 种子 + sqlite 单一事实源同步 + 列清单断言
- T-2/T-2b calc 扩展(product_round/redeem_amount/partial_qty)+ 真实净值实算回填
- T-3 convert_request_repository(6 态 + 条件 UPDATE 守卫)+ core_ro 三读方法
  + share_lot_repository.available_qty_with_inflight(R-3 在途占用推导)
- T-4 convert_repository.sync_mirror 成为 risk_convert_detail 唯一进度镜像写入口
  (旧三方法标 Deprecated,T-7 后删)
- T-5 locks.py 锁键构造器 convert_req_lock_key / convert_confirm_lock_key
- T-6 convert_service.accept_convert 受理事务(八步:锁→幂等→校验→受理日顺延
  →在途占用校验→落单→镜像+审计→202;不扣份额/不折算/不写流水)
  + tests/test_convert_accept.py(16 用例)
  + scripts/dev/verify_convert_accept.py(真库 36/36 一致)
  + trading_calendar.py 纯函数包(R-5)+ 21 用例

T-6 真库实测暴露并修复:confirm_eta 在日历数据边界抛 ValueError,会让已落库
的受理单在调用方眼里变 500;改为展示性字段容错 + 单测守护。

基线:798 passed / 10 skipped,零回归。
2026-09-11 19:21:15 +08:00
zhanghongyu_0626 793c0307f8 feat(risk): Enhance risk management functionality and access control
- Updated `RiskListAccess` and `ThresholdWriteAccess` to enforce access control in the risk repository and threshold repository, ensuring only authorized roles can perform sensitive operations.
- Introduced new methods in `RiskRepository` for counting pending alerts and listing alerts with access checks, improving data security and compliance.
- Enhanced the `chat.py` and `deps.py` files to integrate compliance roles into the risk management matrix, allowing for more granular access control.
- Updated documentation to reflect the new testing baseline of 825 passed tests, indicating improved stability and functionality across the application.

This update significantly strengthens the risk management capabilities, ensuring robust access control and compliance with organizational policies.
2026-09-11 17:07:22 +08:00
zhanghongyu_0626 8556da489a feat(analyst): Add sample and escalate functionality to analyst API
- Introduced new endpoints `/api/analyst/query/{trace_id}/sample` and `/api/analyst/escalate` for sampling query results and escalating issues to human analysts, respectively.
- Enhanced `AnalystAgent` to support sampling of SQL results based on trace ID and to handle escalation requests, improving user experience in error scenarios.
- Updated `analyst_schemas.py` to include `EscalateRequest` for structured escalation requests.
- Added corresponding frontend API calls and UI components to facilitate user interactions with the new features.
- Implemented unit tests to ensure the reliability of the new functionalities.

This update significantly enhances the analytical capabilities of the application, allowing users to retrieve detailed query samples and escalate issues effectively.
2026-09-11 15:18:56 +08:00
zhanghongyu_0626 0fb7d34d7a feat(analyst): Implement audit logging for query denial and clarification
- Enhanced the `AnalystAgent` class to include an `_audit_terminal` method for logging query denials, clarifications, and errors, ensuring compliance and traceability.
- Updated error handling paths to call the new audit method, capturing relevant details such as question, user authentication, and SQL context.
- Introduced new validation checks in `sql_guard.py` to enforce ownership filters for sensitive queries, improving security measures.
- Added unit tests to verify the correct logging behavior and ownership filter enforcement, ensuring robust functionality.

This update significantly strengthens the auditing capabilities of the analyst agent, enhancing security and compliance in query handling.
2026-09-11 14:45:16 +08:00
zhanghongyu_0626 aea97a243c feat(analyst): Introduce interpret functionality and enhance chat API
- Added `interpret` flag to `AnalystChatRequest` for optional immediate interpretation of queries.
- Implemented new `POST /api/analyst/interpret` endpoint for on-demand data interpretation based on the latest query snapshot.
- Updated `AnalystAgent` to handle interpretation logic, including error handling and response formatting.
- Enhanced `AnalystQueryPage` to include a button for triggering interpretations, improving user interaction.
- Updated frontend API calls to support the new interpret functionality, ensuring seamless integration with existing workflows.

This update significantly enhances the analytical capabilities of the application, allowing users to request interpretations of their queries directly.
2026-09-11 12:15:18 +08:00
zhanghongyu_0626 0e35eb84ba feat(docs): Update iteration and TODO documentation with recent changes and optimizations
- Enhanced `ITERATION.md` to include new entries for front-end/API optimizations and Chat session management improvements.
- Expanded `TODO.md` with a daily work summary, completed tasks, and upcoming priorities, ensuring clarity on project status and next steps.
- Added a new summary document for 2026-09-10, detailing work completed across various components, including front-end fixes and API enhancements.

This update improves documentation clarity and provides a comprehensive overview of recent developments and future tasks.
2026-09-11 10:45:49 +08:00
zhanghongyu_0626 9d4d4aaa6d feat(chat): Enhance session management with new API endpoints and filtering options
- Added `status` query parameter to `list_sessions_api` for filtering sessions by their status (active/closed).
- Introduced `close_all_sessions_api` endpoint to allow users to close all active sessions for the current actor.
- Updated `SessionRepository` to support status filtering in session listing and implemented logic for closing active sessions.
- Improved Redis connection settings for better performance and reliability.

This update enhances the chat functionality by providing more control over session management, improving user experience and system efficiency.
2026-09-10 22:30:07 +08:00
GaoYiYuan_0626 96fe1511d6 文档:回写 T-13 提交号 c56ea8d
docs/memory/2026-09-10.md 补记 T-13 已提交与领先远程 16 个提交。
2026-09-10 19:46:28 +08:00
GaoYiYuan_0626 c56ea8d50e 基金转换 T-13:全量回归 + 50 并发压测 + 性能实测补录
交付:新增 tests/test_convert_concurrency.py(9 条 · CONVERT_STRESS 门禁)+ test_convert_service 同键重试 3 条;app/repository/convert_repository.insert_placeholder 改三步法(R-a)、app/service/convert/convert_service.py 幂等判定 pending→202。

修复 2 处并发缺陷(压测暴露,sqlite 不可见):① 阶段一失败后同键重试永久 503(占位朴素 INSERT 撞 uk_group/uk_idem);② 同键竞态子窗口 A 真·双扣 / B 双扣+503(撞 uk_idem 直穿)。

验证:pytest 736 passed / 10 skipped(+5,跑两遍稳定);CONVERT_STRESS=1 并发 9/9;按 SOP 重灌双库复跑零回归;7 个 convert 真库脚本复跑零回归;突变 4 组全部精准命中。50 并发不超卖(成交 20~25)、紧池退避 40/50=80%(不够用)、松池 100%、跨客户 1213 死锁登记待评估;性能端到端 P50 44.2/max 59.8ms、阶段一 P50 9.8/max 16.7ms(未触阈值、未改实测值)。

文档:PRD v0.9.3(§9 第 18 条实测补录)+ 开发计划 §10(10.1~10.5)+ docs/memory/{TODO,MEMORY,FRAMEWORK,ITERATION,2026-09-10}。
2026-09-10 19:46:08 +08:00
GaoYiYuan_0626 f1666b78de 文档:回写 T-12 提交号
- docs/memory/2026-09-10.md 的 T-12 小节补 commit `22f2a41`
2026-09-10 19:00:11 +08:00
GaoYiYuan_0626 22f2a41192 基金转换 T-12:补偿脚本(详情 + 预警)
阶段二失败(或阶段 1.5 引擎失败)后,仅凭 Core 侧数据把「详情 + 预警」两件事补回来
(PRD §7.1 / 架构 §5.4)。

落地(改 3 + 新增 2 脚本 + 测试 2 文件)
- convert_service:新增公开 compensate_convert(group_id, ...) —— 补偿的服务端单点入口
  · 锁键 convert:rerun:{gid},与 convert_fund 幂等重试路径同一个键
  · 详情侧:非 completed 才补写,复用 _finalize_from_core(不另写第二份阶段二)
  · 预警侧:幂等锚点 = 转出端 out_trade_id,复用 find_alerts_by_trade;
    命中即 skipped,否则跑 process_convert_event
- risk_repository:has_engine_error_audit 加 decision 参数(默认值不变)
  · convert 线阶段 1.5 失败审计用 engine_error,普通交易用 risk_engine_error,不是同一个码
- rebuild_alerts.py:新增 --convert-group(与 location 参数 trade_ids 互斥),薄封装
- 新增 scripts/agent/cleanup_pending_convert.py(架构 §2 与开发计划 §9 指定路径):
  超 convert_compensate_sla_hours 的 pending 占位 → status='expired'(标记不硬删,S2)
- 新增 scripts/dev/verify_convert_compensate.py:真库验证脚本(MySQL 8.0.46)
- 测试 +12:test_convert_service +4(补写 / 幂等 / missing / locked)、
  test_demo_scripts +8(--convert-group 分派与接线 + cleanup 脚本)

state 四态与 CLI 退出码
- rebuilt(0) / skipped(0 幂等) / missing(1 零写入) / locked(3)
- 退出码 2 保留给 argparse 用法错误,故 locked 取 3

真库专属证据(sqlite 单测给不了的,本任务核心增量)
- status='expired' 在 MySQL ENUM 上被接受(sqlite 该列是 VARCHAR,写什么都收)
- created_at < cutoff 在 DATETIME(3) 上的时间边界正确(超时进候选 / 未超时不进 / 复跑幂等)
- input_summary 是真 JSON 列,而 has_engine_error_audit 用 LIKE 判定:脚本先断言
  information_schema 的 DATA_TYPE='json' 再验命中,并反向断言决策码不匹配则不命中

顺带收口(用户指示)
- core_ro.concentration_profile 补 h.qty > 0,与 list_holdings 真正同口径
  · ratio 不变(归零行市值为 0),但 rows 不再多出已清仓产品、不虚占截断判定位
  · 新用例含跨出口一致性断言;突变验证:去掉 qty > 0 → 精准 1 条红

验证
- pytest -q → 731 passed / 3 skipped(基线 719 加 12,零回归)
- 突变验证 3 组精准命中:去掉幂等锚点(1 红)/ 去掉 status 过滤(2 红)/ 补偿无视锁(1 红)
- 真库 verify_convert_compensate.py 34/34,隔离数据零残留
- 全套 7 个真库脚本复跑零回归:seed 全 PASS / apply 24 / service 35 / engine 31 / lots 20 / tools 14 / compensate 34
2026-09-10 18:59:42 +08:00
GaoYiYuan_0626 a6ac39edd6 基金转换 T-11:工具与 SQL 汇总去重(FR-C15 / R-d)
convert 在 core_trade 落两条流水(转出 redeem + 转入 subscribe,共享 convert_group_id),
所有金额聚合读取方必须只计一次,否则同笔转换金额翻倍。

落地(改码 3 处 + 新增 1 脚本 + 测试 3 文件)
- rules.py:_amount_view → 公开 amount_view(提升而非复制别名,全仓唯一金额聚合口径);
  docstring 补「跨模块共用」说明
- core_tools.py:query_recent_trades 的 sum_amount 改走 amount_view(FR-C15);
  items / total_count 保持全量不变——两条流水是真实的两笔权益变动,读到两条是对的
- core_ro.py:list_holdings 加 h.qty > 0(convert 转出全部份额留下的 qty=0 归零行不是持仓);
  sum_trades_on_date 加 convert 去重条件(R-d),组内只计转出端
- 新增 tests/test_core_tools.py(3 条:汇总不翻倍 / 跨口径一致性 / 持仓不返回 qty=0 行)
- tests/test_core_ro_sum.py 追加 1 条 convert 去重用例(既有断言零改动)
- 新增 scripts/dev/verify_convert_tools.py:真库验证脚本(MySQL 8.0.46)

执行期裁定 2 条(已留痕)
- _amount_view 提升为公开而非复制:一个函数两个名字会漂移(自检第 13 问)
- SQL 条件从 IS NULL 扩为 IS NULL OR = '':Python 的 if not gid 把空串当无组,
  而 SQL 里 '' IS NULL 恒假。真库实证:只写 IS NULL → 合计数 400000(正确 450000,漏算 50000)。
  不加则 RISK-002 漏算,且 sqlite 单测若只造 NULL 数据永远发现不了
- 等价性边界:组内无 redeem 时 SQL 丢整组、amount_view 保留首条;由 R-b 保证不可达

验证
- pytest -q → 718 passed / 3 skipped(基线 714 加 4,零回归)
- 突变验证 3 组均精准命中:去掉去重条件(2 红)/ 去掉 qty>0(1 红)/ 汇总不走 amount_view(2 红)
- 真库 verify_convert_tools.py 14/14,隔离数据零残留
- 复跑受影响真库脚本零回归:T-8 31/31、T-7 35/35、T-10 20/20
2026-09-10 18:40:27 +08:00
GaoYiYuan_0626 5c2dc94b40 文档:回写 T-10 提交记录与订正后口径
- docs/memory/2026-09-10.md 追加 T-10 提交记录(5e6fa06,领先远程 11 个提交、未推送)、
  提交含三部分说明、订正后口径(redeem 的 amount ÷ 净值 属项目简化,见 PRD §10.1)
- 记录交接文档 §B 两处状态漏改的订正(原仍写「下一步 = T-10」,已改为 T-10 已完成)
2026-09-10 18:29:57 +08:00
GaoYiYuan_0626 5e6fa06d03 基金转换 T-10:普通申赎批次维护(FR-C16)
让 core_trade 的普通申赎同步维护 core_share_lot 批次,为 convert 提供权威份额口径。

落地(改码 3 处 + 新增 2 个脚本)
- gateway_repository:新增 insert_share_lots / deduct_share_lots,各自单事务、走 rw 账号;
  只落已分配结果、不含分配逻辑,避免出现第二份 FIFO 口径
- share_lot_repository:__init__ 增可选 core_ro 入参,让 trade_gateway 复用同一份 FIFO 选批口径(D18)
- trade_gateway:新增 _nav_as_of / _maintain_lots,在落流水后、规则引擎前调用
  · subscribe:取 T 日(含)前最新净值 → qty = amount ÷ 净值(2 位 HALF_UP)→ 建批次(confirmed_at = T)
  · redeem:FIFO 扣减;无批次但有持仓 → D8 兜底补建后再扣;两者皆无 → 降级跳过
  · 整段 try 包住,任何异常只 warning,绝不阻断交易(R-c(1))
- 新增 scripts/core/rebuild_lots.py:按 core_holding 快照重建批次(L-7),与网关 D8 同调 bootstrap_lots;
  默认只补建无批次的持仓行(幂等),--force 才先删后建,--dry-run 只报告
- 新增 scripts/dev/verify_convert_lots.py:真库验证脚本(MySQL 8.0.46)

口径订正(联网查证 4 家管理人业务规则后)
- redeem 的 amount ÷ 净值 折算属本项目简化建模,不是行业标准
- 行业铁律是「金额申购、份额赎回」:投资者以份额申报,登记机构按 T 日净值算金额
  (睿远业务规则 §65 / 华泰保兴 §69 / 东方基金 §57 / 国投瑞银 §33;无一家公募支持按金额赎回)
- 派生风险:未知价法下 T 日净值当日不可得(T+1 公告),_nav_as_of 实取 T−1 净值,
  故此处算出的份额只是估算值
- 已记入 PRD §10.1 已知差异清单;trade_gateway 注释同步订正

验证
- pytest -q → 714 passed / 3 skipped(基线 697 加 17,零回归)
- R16 test_redeem_accepted_without_alert 零改动通过(由 R-c(1) 降级保住)
- 真库 20/20;T-6 24/24、T-7 35/35 复跑零回归;真库隔离数据零残留
- 突变验证 2 组:切断接线 → 精准 2 条红;关掉 D8 兜底 → 精准 2 条红(含 D18 同源断言)
2026-09-10 18:28:48 +08:00
GaoYiYuan_0626 e80098b32f 文档订正:远程状态认知纠错(refs/remotes 写入不落盘)+ 交接清单过期基线
T-8/T-9 提交时两次依据 git branch -r / branch -vv 判定「远程分支不见了」并向用户报警,
两次均为误报。本次深挖确认根因,并订正此前写入的错误表述。

- docs/memory/MEMORY.md 交接清单第 7 问重写:
  本仓 .git/refs/remotes/** 写入不落盘 —— git update-ref refs/remotes/origin/X 返回 0、
  reflog 也建了,但松散引用消失,且会把整个 refs/remotes/origin/ 目录删掉(含手工放进的文件);
  git fetch 报告 [new branch] ... -> origin/risk-control-agent 后同样不落盘。
  故此前记的「stale tracking ref,git fetch 即恢复」是错的,fetch 并不修复。
  对照证据:写 refs/heads/** 完全正常;同一 git(2.55.0.windows.3)在 /tmp 新建仓库里写
  refs/remotes/** 完全正常 → 只此仓库特有;已排除外部进程删目录(marker 静置存活)、
  重解析点(lstat FILE_ATTRIBUTE_REPARSE_POINT=False)、hooks / commondir / 浅克隆。
  补绕过方案:packed-refs 是可靠存储,手工追加 <sha> refs/remotes/origin/<name> 后
  git branch -r 立即正常(还原=删掉该行)。
  补影响面:提交 / fetch 抓对象 / push 均不受影响(git push --dry-run 实测
  fffb78a..d0097d6 成功),仅影响本地显示与上游跟踪。
  顺手订正验证条目里过期的「516 passed / 3 skipped」→ 697,及第 73 行同款旧表述。
- docs/memory/2026-09-10.md 追加排查记录:7 条可复现证据 + 三步对照实验 + 绕过方案 + 影响面。
2026-09-10 18:07:43 +08:00
GaoYiYuan_0626 d0097d6004 基金转换 T-9:API 模型 + 网关分派(HTTP 层 convert 走通)+ 展示位数口径修复
一、T-9 本体:HTTP 层 convert 端到端走通

- api/simulate.py:TradeRequest 三型字段分池(subscribe/redeem → product_id+amount;
  convert → from/to_product_id + qty + 可选 client_request_id)+ model_validator 分支校验;
  未知类型放行给网关抛 400(保住既有 purchase → 400 断言);model_dump(exclude_none=True);
  PROCESSING → 202;异常捕获由 except LookupError 收窄为 except NotFoundError
  (原写法把 KeyError 这类编程错误静默转成 404,实测掩盖 convert 分支真实诊断)。
- gateway/trade_gateway.py:移除 convert 显式拒绝,新增 _submit_convert 分派
  (只做参数映射 + 仓储装配);convert 不写 trade_request 审计(审计归 convert_service)。
- utils/response.py:错误体合入 exc.extra(TOO_MANY_LOTS 的 batch_count/max_lots);
  既有 ApiError 无 extra 属性 → 老错误体逐字节不变。
- utils/trace.py + main.py:正则收敛单点定义。执行期发现 trace.py 与 main.py 各有一份
  内容完全相同的白名单副本 —— S4 要防的「漂移」其实已经发生,现将常量上移 trace.py
  成公开 HEADER_ID_PATTERN(同时解决 main→simulate 反向导入成环)。

二、展示位数口径修复(执行期发现 → 联网核验 → 修复 → 文档订正)

发现:同一逻辑响应两种写法 —— 首次 "53456.95" vs 幂等重放 "53456.9500",数值相等、字符串不等。
根因不是 T-7 写错,是契约缺位:§2.5 只规定「金额/份额 2 位」,净值、费率、申请份额的
回显位数根本没定义 → 实现只能 str(Decimal) 原样出网 → 位数随数据来源漂移。

修复:convert_service 新增 _q(value, unit) + _D2/_D4 规格常量作对外唯一出口 ——
金额/份额 2 位、净值/费率/份额尾差 4 位;响应 + 审计 summary + 异常日志共用该出口;
原 _s() 全部替换。首次路径幂等(除 requested_qty/actual_qty/lot[].qty 由 4 位补齐 2 位外不变)。

依据(2026-09-10 联网核验 7 家管理人公告):金额/份额「四舍五入保留至小数点后两位」;
「申请转换份额精确到小数点后两位」;净值保留 4 位第 5 位四舍五入(中欧/国泰公告由 3 位提高至 4 位);
费率以百分比 2 位表示。已知不统一:易方达 ETF 场外份额取整数位、南方基金取截断 → 取主流口径
并记入 PRD 已知差异(未来接真实 TA 需按基金合同配置化)。

三、文档订正

- PRD → v0.9.2:§2.5 拆 2.5.1 计算精度 / 2.5.2 展示位数(新增按字段分类的规格表 + 外部依据);
  §5.3 示例 requested_qty/actual_qty/lot_breakdown[].qty 4 位 → 2 位(原示例与 §2.5
  「计算与对外展示按 2 位」自相矛盾,属漏改);字段类型约定补「位数不自由 + 两条路径须逐字节一致」。
- 架构 → v1.0.1:§1 原则 11 补「str() 前必须按 §2.5.2 量化」,无结构变更。

四、验证

- 新增 tests/test_convert_integration.py(8 条真 MySQL 端到端,CNV-TEST-/TRD-TEST- 前缀隔离):
  折算与 PRD §5.3 逐项吻合、两条流水同组、持仓与批次如实变动、明细 completed + 审计、
  幂等重试不产生第二组、跨主体 400、未知类型 400,以及
  「首次与重放逐字段逐字节相等」+「展示位数规格」两条新闸门。
- test_trade_gateway.py +17(11 条错误码映射全表参数化 · 202 · 200 透传 · 不写 trade_request 审计)。
- test_integration_risk.py:R15 处置 —— 端到端已迁入新文件,原槽位改造为
  test_invalid_type_400_and_no_new_trade_audit(改用 purchase 触发),保住「校验失败不落审计」不变量。
- pytest -q → 697 passed / 3 skipped(基线 672 +25,零回归)。
- 真库复跑:T-6 24/24 · T-7 35/35 · T-8 31/31;calc_convert_demo.py 15/15。
- 突变验证 4 组:关掉 convert 分派 → 21 条红;关掉错误体 extra 展开 → 精准 1 条;
  关掉 client_request_id 正则 → 精准 1 条;关掉 _q() 展示量化 → 2 条红
  (assert '50000.0000' == '50000' 直接复现原缺陷)。均已恢复。
2026-09-10 18:00:20 +08:00
GaoYiYuan_0626 7ad1c8204d 基金转换 T-8:规则引擎改造(_amount_view 去重视图 + process_convert_event)
一次转换落两条流水(转出 redeem + 转入 subscribe,同 convert_group_id),
金额聚合类规则若两条都算会翻倍报假预警,故按「逐笔 / 聚合」拆成两个视图。

- rules.py:新增 _amount_view —— 同组内只保留 redeem 那条(无 convert_group_id
  的交易恒等通过、组内无 redeem 保首条、绝不删行);run_rules 双视图分流:
  RISK-001/003/004 用全量 eligible(逐笔判定),RISK-002/005 走金额视图去重。
- alert_service.py:抽出公开 build_trade_event(事件体结构唯一定义),
  record_trade_alerts 新增可选 events 参数;缺省 None 退化为单条,
  既有调用零改动。新建单落 payload.events 全部,聚合追加只追首条(只认转出端)。
- engine.py:抽 _run 共用实现;process_trade_event 变薄封装(签名与行为不变);
  新增 process_convert_event(out_trade, in_trade, ...) 与 _notify_error_hook
  (hook 自身异常吞掉,原始异常照常上抛)。

实质影响:阶段 1.5 从「ImportError 静默跳过」变为「真跑」——T-7 部署时
process_convert_event 不存在,T-8 落地后同一笔转换会真实出单 + 写 L3 + 落审计;
T-7 真库脚本复跑仍 35/35,无连带破坏。

验证:新增 tests/test_convert_engine.py(15 用例)+ test_convert_service.py
接线回归 1 条;pytest 672 passed / 3 skipped(基线 656 +16,零回归);
新增 scripts/dev/verify_convert_engine.py 真 MySQL 验证 31/31;
突变验证(关掉去重视图 → 4 条变红)确认用例非假绿。
2026-09-10 17:34:35 +08:00
GaoYiYuan_0626andWorkBuddy 3244922a55 基金转换 T-3:core_ro 新增 5 个只读方法 + share_lot_repository 读侧
- core_ro 新增 get_nav_as_of(D10) / get_redeem_fee_rules / list_share_lots(S1 确定性排序)
  / sum_remain_qty(仅 >0) / get_holding;不动 get_latest_nav 与 list_trades_range 白名单
- 新增 share_lot_repository:core_share_lot 读侧 FIFO 贪心选批 + 汇总,排序复用 core_ro 的 ORDER BY(D18 单一副本)
- 新增 tests/test_share_lot.py 15 用例;pytest 全量 624 passed / 3 skipped(基线 609,零回归)
- 同步开发计划 §5.1 执行记录与交接文档 §B 状态(v1.5 / T-3 ✅ / 基线 624)

Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
2026-09-10 15:42:55 +08:00
zhanghongyu_0626 48355cee8e feat(analytics): Enhance AnalystQueryPage with template and cache hit indicators
- Updated `AnalystQueryPage` to display tags for template hits and cache hits, improving user feedback on query performance.
- Adjusted SQL result label to streamline information presentation.
- Enhanced documentation to reflect the latest testing baseline with 804 passed tests, indicating improved stability and functionality across the application.

This update significantly enhances the user experience by providing clearer insights into query processing and results.
2026-09-10 15:31:20 +08:00
zhanghongyu_0626 ddcf53cfa8 feat(template): Implement template caching and SQL rendering for enhanced query handling
- Introduced `TemplateService` for managing SQL templates, allowing for parameterized queries based on user input.
- Added functionality to automatically reload templates upon asset creation in `analyst.py`.
- Enhanced `CacheService` to support table generation bumping, ensuring cache invalidation on data changes.
- Updated `RiskRepository` and `GatewayRepository` to trigger cache invalidation for relevant operations.
- Expanded `analyst_schemas.py` to include new fields for template tracking in response metadata.
- Created seed SQL script for populating initial templates and added unit tests for template rendering logic.

This update significantly improves the efficiency of query handling by leveraging SQL templates, reducing reliance on LLM for common queries.
2026-09-10 15:22:07 +08:00
GaoYiYuan_0626 497cee289f docs: 交接文档合并为单一入口 + 全仓指向统一到 交接文档.md §A/§B/§C
背景:交接文档的定位是「给 AI 接手用的入口」,此前三份分散(项目根 交接文档.md
+ docs/交接文档-基金转换.md + docs/交接文档-架构改进.md),且 docs/ 两份停留在旧版
(v1.0 / v1.1,不含 T-0~T-2b、609 passed、D20 实施等进度),新会话极易被误导。

改动:
- 三份合并为项目根 交接文档.md v3.0(545 行 = §0 公共层 + §A 风控主线 + §B 基金转换线
  + §C 架构改进线);该文件在 .gitignore:47 内,按用户要求不入库(交接文档只留本地)
- 全仓指向统一到 交接文档.md §A/§B/§C:AGENTS.md(含顶部新增「接手先读交接文档.md」)、
  docs/memory/{MEMORY,TODO,FRAMEWORK,ITERATION}、PRD-架构改进与稳定性加固、
  开发计划-架构改进、TODO-架构改进、开发计划-基金转换交易
- 两份 docs/交接文档-*.md 加「已废弃(2026-09-10)· 勿读」横幅并指向新入口,
  保留作历史留档(不删除)
- 记录事故:对 docs/ 下中文名文件使用 git rm 会静默抹除整个 docs/ 目录(复现 2 次、
  退出码 0),已零损失恢复;纪律写入 交接文档.md §0.4 与工作区记忆

无代码改动;pytest 609 passed / 3 skipped。
2026-09-10 15:04:13 +08:00