aria-code 4.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. agents/__init__.py +32 -0
  2. agents/base.py +190 -0
  3. agents/deep/__init__.py +37 -0
  4. agents/deep/calibration_loop.py +144 -0
  5. agents/deep/critic.py +125 -0
  6. agents/deep/deepen.py +193 -0
  7. agents/deep/models.py +149 -0
  8. agents/deep/pipeline.py +164 -0
  9. agents/deep/quant_fusion.py +192 -0
  10. agents/deep/themes.py +95 -0
  11. agents/deep/tiers.py +106 -0
  12. agents/financial/__init__.py +10 -0
  13. agents/financial/catalyst.py +279 -0
  14. agents/financial/debate.py +145 -0
  15. agents/financial/earnings.py +303 -0
  16. agents/financial/fundamental.py +159 -0
  17. agents/financial/macro.py +99 -0
  18. agents/financial/news.py +207 -0
  19. agents/financial/risk.py +132 -0
  20. agents/financial/sector.py +279 -0
  21. agents/financial/synthesis.py +274 -0
  22. agents/financial/technical.py +258 -0
  23. agents/portfolio_agent.py +333 -0
  24. agents/realty/__init__.py +62 -0
  25. agents/realty/asset_diagnosis.py +150 -0
  26. agents/realty/business_match.py +165 -0
  27. agents/realty/cashflow_verify.py +208 -0
  28. agents/realty/contract_rules.py +209 -0
  29. agents/realty/energy_anomaly.py +188 -0
  30. agents/realty/exit_settlement.py +207 -0
  31. agents/realty/fulfillment_risk.py +205 -0
  32. agents/realty/ops_optimize.py +159 -0
  33. agents/realty/revenue_share.py +214 -0
  34. agents/registry.py +144 -0
  35. agents/sports/__init__.py +0 -0
  36. agents/sports/football_agent.py +169 -0
  37. agents/team.py +289 -0
  38. aliyun_data_client.py +660 -0
  39. apps/README.md +12 -0
  40. apps/__init__.py +2 -0
  41. apps/channels/README.md +15 -0
  42. apps/cli/README.md +13 -0
  43. apps/cli/__init__.py +2 -0
  44. apps/cli/bootstrap.py +99 -0
  45. apps/cli/codegen_paths.py +29 -0
  46. apps/cli/commands/__init__.py +16 -0
  47. apps/cli/commands/analysis_cmds.py +288 -0
  48. apps/cli/commands/backtest_cmds.py +1887 -0
  49. apps/cli/commands/broker_cmds.py +1154 -0
  50. apps/cli/commands/business_workflow_cmds.py +289 -0
  51. apps/cli/commands/catalog.py +84 -0
  52. apps/cli/commands/data_cmds.py +405 -0
  53. apps/cli/commands/diagnostic_cmds.py +179 -0
  54. apps/cli/commands/diagnostic_ops_cmds.py +696 -0
  55. apps/cli/commands/finance_render.py +12 -0
  56. apps/cli/commands/market.py +399 -0
  57. apps/cli/commands/market_cmds.py +1276 -0
  58. apps/cli/commands/market_context.py +425 -0
  59. apps/cli/commands/market_render.py +7 -0
  60. apps/cli/commands/model_cmds.py +1579 -0
  61. apps/cli/commands/ops_cmds.py +668 -0
  62. apps/cli/commands/portfolio_cmds.py +962 -0
  63. apps/cli/commands/report.py +377 -0
  64. apps/cli/commands/scaffold_templates.py +617 -0
  65. apps/cli/commands/session_cmds.py +179 -0
  66. apps/cli/commands/session_ux_cmds.py +280 -0
  67. apps/cli/commands/team.py +588 -0
  68. apps/cli/commands/team_render.py +8 -0
  69. apps/cli/commands/ui_cmds.py +358 -0
  70. apps/cli/commands/workflow_cmds.py +279 -0
  71. apps/cli/commands/workspace_cmds.py +1414 -0
  72. apps/cli/config_paths.py +70 -0
  73. apps/cli/config_store.py +61 -0
  74. apps/cli/deterministic.py +122 -0
  75. apps/cli/direct.py +48 -0
  76. apps/cli/github_app_auth.py +135 -0
  77. apps/cli/handlers/__init__.py +11 -0
  78. apps/cli/handlers/broker_handlers.py +122 -0
  79. apps/cli/handlers/chart_handlers.py +1309 -0
  80. apps/cli/handlers/market_handlers.py +2509 -0
  81. apps/cli/handlers/realty_handlers.py +114 -0
  82. apps/cli/handlers/strategy_advice.py +82 -0
  83. apps/cli/hooks.py +180 -0
  84. apps/cli/i18n.py +284 -0
  85. apps/cli/intent.py +136 -0
  86. apps/cli/intent_router.py +217 -0
  87. apps/cli/lifecycle_hooks.py +48 -0
  88. apps/cli/main.py +29 -0
  89. apps/cli/market_metadata.py +135 -0
  90. apps/cli/market_universe.py +265 -0
  91. apps/cli/message_processing.py +257 -0
  92. apps/cli/plan_mode.py +139 -0
  93. apps/cli/plotly_html.py +15 -0
  94. apps/cli/prediction_feedback.py +202 -0
  95. apps/cli/preflight.py +497 -0
  96. apps/cli/project_aria.py +60 -0
  97. apps/cli/prompts/__init__.py +0 -0
  98. apps/cli/prompts/coding.py +658 -0
  99. apps/cli/prompts/system_prompts.py +531 -0
  100. apps/cli/prompts/ui.py +434 -0
  101. apps/cli/providers/__init__.py +1 -0
  102. apps/cli/providers/base.py +271 -0
  103. apps/cli/providers/chat_routing.py +80 -0
  104. apps/cli/providers/llm/__init__.py +1 -0
  105. apps/cli/providers/llm/ollama_stream.py +1170 -0
  106. apps/cli/providers/llm/sse_stream.py +216 -0
  107. apps/cli/providers/runtime_bridge.py +185 -0
  108. apps/cli/runtime_consumer.py +489 -0
  109. apps/cli/session_export.py +87 -0
  110. apps/cli/session_jsonl.py +207 -0
  111. apps/cli/session_store.py +112 -0
  112. apps/cli/todo_tracker.py +190 -0
  113. apps/cli/tools/__init__.py +40 -0
  114. apps/cli/tools/context.py +46 -0
  115. apps/cli/tools/file_tools.py +112 -0
  116. apps/cli/tools/market_tools.py +549 -0
  117. apps/cli/tools/notebook_tools.py +111 -0
  118. apps/cli/tools/system_tools.py +669 -0
  119. apps/cli/tools/write_tools.py +715 -0
  120. apps/cli/tradingview_bridge.py +434 -0
  121. apps/cli/update_check.py +152 -0
  122. apps/cli/utils/__init__.py +0 -0
  123. apps/cli/utils/market_detect.py +1578 -0
  124. apps/daemon/README.md +14 -0
  125. apps/vscode/README.md +115 -0
  126. apps/vscode/package.json +70 -0
  127. aria_cli.py +11636 -0
  128. aria_code-4.1.3.dist-info/METADATA +952 -0
  129. aria_code-4.1.3.dist-info/RECORD +284 -0
  130. aria_code-4.1.3.dist-info/WHEEL +5 -0
  131. aria_code-4.1.3.dist-info/entry_points.txt +2 -0
  132. aria_code-4.1.3.dist-info/licenses/LICENSE +121 -0
  133. aria_code-4.1.3.dist-info/top_level.txt +50 -0
  134. aria_daemon.py +1295 -0
  135. aria_feishu_bot.py +1359 -0
  136. aria_relay_client.py +182 -0
  137. aria_relay_server.py +405 -0
  138. aria_telegram_bot.py +202 -0
  139. ariarc.py +328 -0
  140. artifacts.py +491 -0
  141. backtest_report.py +472 -0
  142. brokers/__init__.py +72 -0
  143. brokers/base.py +207 -0
  144. brokers/capabilities.py +264 -0
  145. brokers/cn/__init__.py +10 -0
  146. brokers/cn/easytrader_broker.py +193 -0
  147. brokers/cn/futu_broker.py +194 -0
  148. brokers/cn/longbridge_broker.py +190 -0
  149. brokers/cn/tiger_broker.py +196 -0
  150. brokers/cn/xtquant_broker.py +175 -0
  151. brokers/config.py +364 -0
  152. brokers/intl/__init__.py +5 -0
  153. brokers/intl/alpaca_broker.py +183 -0
  154. brokers/intl/ibkr_broker.py +215 -0
  155. brokers/intl/webull_broker.py +156 -0
  156. brokers/paper_broker.py +259 -0
  157. brokers/planning.py +296 -0
  158. brokers/registry.py +181 -0
  159. brokers/trading.py +237 -0
  160. change_store.py +127 -0
  161. command_safety.py +19 -0
  162. computer_use_tools.py +504 -0
  163. dashboard_generator.py +578 -0
  164. data_analysis_tools.py +808 -0
  165. data_cleaner.py +483 -0
  166. data_service.py +481 -0
  167. datasources/__init__.py +23 -0
  168. datasources/base.py +166 -0
  169. datasources/router.py +221 -0
  170. datasources/sources/__init__.py +15 -0
  171. datasources/sources/akshare_source.py +269 -0
  172. datasources/sources/alpha_vantage_source.py +202 -0
  173. datasources/sources/edgar_source.py +218 -0
  174. datasources/sources/finnhub_source.py +197 -0
  175. datasources/sources/fred_source.py +219 -0
  176. datasources/sources/tushare_source.py +141 -0
  177. datasources/sources/web_scraper_source.py +278 -0
  178. datasources/sources/world_bank_source.py +205 -0
  179. datasources/sources/yfinance_source.py +152 -0
  180. demo_player.py +204 -0
  181. doctor.py +508 -0
  182. file_analysis_tools.py +734 -0
  183. finance_formulas.py +389 -0
  184. football_data_client.py +1670 -0
  185. intent_classifier.py +358 -0
  186. local_finance_tools.py +3221 -0
  187. local_llm_provider.py +552 -0
  188. macro_tools.py +368 -0
  189. market_data_client.py +1899 -0
  190. mcp_client.py +506 -0
  191. memory_manager.py +245 -0
  192. model_capability.py +416 -0
  193. notification_tools.py +248 -0
  194. packages/__init__.py +23 -0
  195. packages/aria_agents/__init__.py +5 -0
  196. packages/aria_agents/manifest.py +69 -0
  197. packages/aria_core/__init__.py +34 -0
  198. packages/aria_core/architecture.py +192 -0
  199. packages/aria_core/export.py +124 -0
  200. packages/aria_core/manifest.py +65 -0
  201. packages/aria_infra/__init__.py +15 -0
  202. packages/aria_infra/arthera.py +52 -0
  203. packages/aria_infra/doctor.py +246 -0
  204. packages/aria_infra/product.py +37 -0
  205. packages/aria_mcp/__init__.py +25 -0
  206. packages/aria_mcp/bridge.py +38 -0
  207. packages/aria_mcp/config.py +97 -0
  208. packages/aria_mcp/tools.py +61 -0
  209. packages/aria_sdk/__init__.py +19 -0
  210. packages/aria_sdk/client.py +396 -0
  211. packages/aria_sdk/providers.py +70 -0
  212. packages/aria_sdk/streaming.py +73 -0
  213. packages/aria_sdk/types.py +86 -0
  214. packages/aria_services/__init__.py +55 -0
  215. packages/aria_services/context.py +258 -0
  216. packages/aria_services/data.py +11 -0
  217. packages/aria_services/provider_health.py +189 -0
  218. packages/aria_services/registry.py +213 -0
  219. packages/aria_services/usage.py +138 -0
  220. packages/aria_skills/__init__.py +5 -0
  221. packages/aria_skills/registry.py +59 -0
  222. packages/aria_tools/__init__.py +5 -0
  223. packages/aria_tools/registry.py +128 -0
  224. packages/quant_engine/__init__.py +6 -0
  225. packages/quant_engine/sports/__init__.py +72 -0
  226. packages/quant_engine/sports/calibrator.py +353 -0
  227. packages/quant_engine/sports/dixon_coles.py +234 -0
  228. packages/quant_engine/sports/elo.py +299 -0
  229. packages/quant_engine/sports/form.py +188 -0
  230. packages/quant_engine/sports/h2h.py +195 -0
  231. packages/quant_engine/sports/ml_model.py +354 -0
  232. packages/quant_engine/sports/predictor.py +311 -0
  233. packages/quant_engine/sports/tracker.py +664 -0
  234. packages/quant_engine/stochastic/__init__.py +27 -0
  235. packages/quant_engine/stochastic/gbm_enhanced.py +195 -0
  236. packages/quant_engine/stochastic/ito_calculus.py +477 -0
  237. packages/quant_engine/stochastic/kelly_criterion.py +181 -0
  238. packages/quant_engine/stochastic/monte_carlo_advanced.py +95 -0
  239. packages/quant_engine/stochastic/options_pricing.py +573 -0
  240. packages/quant_engine/stochastic/stochastic_processes.py +90 -0
  241. plan_utils.py +194 -0
  242. plugin_loader.py +328 -0
  243. portfolio_ledger.py +262 -0
  244. privacy/__init__.py +5 -0
  245. privacy/feedback.py +123 -0
  246. project_tools.py +525 -0
  247. providers/__init__.py +30 -0
  248. providers/llm/__init__.py +19 -0
  249. providers/llm/anthropic.py +184 -0
  250. providers/llm/base.py +139 -0
  251. providers/llm/ollama.py +128 -0
  252. providers/llm/openai_compat.py +282 -0
  253. providers/llm/registry.py +358 -0
  254. realty_data_tools.py +659 -0
  255. report_generator.py +1314 -0
  256. runtime/__init__.py +103 -0
  257. runtime/agent_loop.py +1183 -0
  258. runtime/approval.py +51 -0
  259. runtime/events.py +102 -0
  260. runtime/gateway.py +128 -0
  261. runtime/lsp.py +346 -0
  262. runtime/subagent.py +258 -0
  263. runtime/tool_executor.py +104 -0
  264. runtime/tool_policy.py +106 -0
  265. safety/__init__.py +21 -0
  266. safety/permissions.py +275 -0
  267. setup_wizard.py +653 -0
  268. strategy_vault.py +420 -0
  269. ui/__init__.py +100 -0
  270. ui/banner.py +310 -0
  271. ui/completer.py +391 -0
  272. ui/console.py +271 -0
  273. ui/image_render.py +243 -0
  274. ui/input_box.py +376 -0
  275. ui/picker.py +195 -0
  276. ui/render/__init__.py +11 -0
  277. ui/render/finance.py +1480 -0
  278. ui/render/market.py +225 -0
  279. ui/render/output.py +681 -0
  280. ui/render/team.py +346 -0
  281. ui/robot.py +235 -0
  282. workspace/__init__.py +6 -0
  283. workspace/files.py +170 -0
  284. workspace/verify.py +113 -0
@@ -0,0 +1,12 @@
1
+ """Backwards-compatibility shim — canonical code lives in ui/render/finance.py."""
2
+ from ui.render.finance import * # noqa: F401, F403
3
+ from ui.render.finance import (
4
+ render_finance_result,
5
+ render_macro_result, render_cb_rates, render_econ_calendar,
6
+ render_options_chain, render_quality_scores, render_ichimoku,
7
+ render_fear_greed, render_funding_rates, render_peer_comparison,
8
+ render_house_price, render_reits_list, render_rental_yield,
9
+ render_property_val, render_multi_city, render_asset_score,
10
+ render_corr_matrix, render_portfolio_bt, render_sql_result,
11
+ render_alerts, format_backtest_output,
12
+ )
@@ -0,0 +1,399 @@
1
+ """Market command parsing and top-level routing helpers.
2
+
3
+ Keep this module independent from the terminal UI and market data providers so
4
+ CLI, Feishu, and future gateway adapters can share the same command semantics.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass
10
+ from typing import Mapping
11
+
12
+ from apps.cli.utils.market_detect import (
13
+ _extract_market_symbol,
14
+ _extract_market_symbols,
15
+ _is_blocked_market_symbol_candidate,
16
+ )
17
+
18
+
19
+ TOP_LEVEL_ROUTES: Mapping[str, str] = {
20
+ # quant workflow keywords -> slash command name
21
+ "analyze": "/analyze",
22
+ "analysis": "/analyze",
23
+ "分析": "/analyze",
24
+ "backtest": "/backtest",
25
+ "回测": "/backtest",
26
+ "risk": "/risk",
27
+ "风险": "/risk",
28
+ "report": "/report",
29
+ "报告": "/report",
30
+ "market": "/market",
31
+ "行情": "/market",
32
+ "screen": "/screen",
33
+ "筛选": "/screen",
34
+ "strategy": "/strategy",
35
+ "策略": "/strategy",
36
+ "signal": "/signal",
37
+ "信号": "/signal",
38
+ "chart": "/chart",
39
+ "图表": "/chart",
40
+ "news": "/news",
41
+ "新闻": "/news",
42
+ "predict": "/predict",
43
+ "预测": "/predict",
44
+ }
45
+
46
+ _VISUAL_ROUTE_PATTERNS: tuple[tuple[tuple[str, ...], str], ...] = (
47
+ (("晨报", "日报", "周报", "月报", "看板", "dashboard", "heatmap"), "/dashboard"),
48
+ (("报告", "report", "研报"), "/report"),
49
+ (("图表", "走势图", "k线图", "k线", "k-line", "kline", "candlestick", "chart", "plot"), "/chart"),
50
+ )
51
+
52
+ _DASHBOARD_MODE_HINTS: tuple[tuple[tuple[str, ...], str], ...] = (
53
+ (("持仓", "portfolio", "仓位", "组合", "资产"), "portfolio"),
54
+ (("市场", "行情", "quote", "prices", "watchlist", "热力图", "heatmap"), "market"),
55
+ (("晨报", "日报", "brief"), "brief"),
56
+ )
57
+
58
+ _CHART_PERIOD_HINTS: tuple[tuple[tuple[str, ...], str], ...] = (
59
+ (("近一年", "一年", "1y", "1年"), "1y"),
60
+ (("近三个月", "三个月", "3m", "3个月"), "3m"),
61
+ (("近六个月", "六个月", "6m", "6个月"), "6m"),
62
+ (("年初至今", "ytd"), "ytd"),
63
+ (("两年", "2y"), "2y"),
64
+ (("三年", "3y"), "3y"),
65
+ (("五年", "5y"), "5y"),
66
+ )
67
+
68
+ _REPORT_TYPE_HINTS: tuple[tuple[tuple[str, ...], str], ...] = (
69
+ (("深度", "详细", "deep"), "deep"),
70
+ (("简评", "简报", "brief"), "brief"),
71
+ (("研究报告", "投研报告", "研究", "report"), "standard"),
72
+ )
73
+
74
+ _TRADINGVIEW_HINTS = ("tradingview", "trading view", "pine")
75
+ _TRADINGVIEW_ZH_HINTS = ("用tradingview", "打开tradingview", "tradingview打开", "用 tv", "tv打开", "pine脚本")
76
+ _TRADINGVIEW_BULLISH_HINTS = ("看涨", "偏多", "多头", "上涨", "bullish", "bull", "upside")
77
+ _TRADINGVIEW_BEARISH_HINTS = ("看跌", "偏空", "空头", "下跌", "bearish", "bear", "downside")
78
+ _TRADINGVIEW_ANALYSIS_HINTS = (
79
+ "分析", "怎么看", "怎么判断", "哪些数据", "根据其的数据", "根据数据",
80
+ "指标", "信号", "analyze", "analysis", "data", "indicator", "signal",
81
+ )
82
+
83
+ _ROUTE_SYMBOL_BLOCKLIST = {"K", "LINE", "CHART", "PLOT"}
84
+ _CHART_CONTEXT_TOKEN_BLOCKLIST = {
85
+ "ABOVE", "BELOW", "INC", "TTM", "RATIO", "SIGNAL", "SUPPORT", "RESIST",
86
+ "RESISTANCE", "LEVEL", "LEVELS", "HIGH", "LOW", "OPEN", "CLOSE", "AVG",
87
+ "AVERAGE", "RETURN", "RETURNS", "TREND", "MOMENTUM",
88
+ }
89
+
90
+
91
+ def _news_topic(text: str, symbols: list[str]) -> str:
92
+ low = text.lower()
93
+ if "spacex" in low:
94
+ return "SpaceX"
95
+ if "lvmh" in low or "路易威登" in text:
96
+ return "LVMH"
97
+ return symbols[0] if symbols else text
98
+
99
+
100
+ def _route_symbols(text: str, *, limit: int = 6) -> list[str]:
101
+ """Resolve ticker/company mentions for natural-language command routing."""
102
+ seen: set[str] = set()
103
+ out: list[str] = []
104
+ for source in (text, text.upper()):
105
+ for symbol in _extract_market_symbols(source, limit=limit):
106
+ normalized = str(symbol or "").upper()
107
+ if (
108
+ not normalized
109
+ or normalized in _ROUTE_SYMBOL_BLOCKLIST
110
+ or _is_blocked_market_symbol_candidate(normalized)
111
+ ):
112
+ continue
113
+ if len(normalized) == 1 and "." not in normalized:
114
+ continue
115
+ if normalized not in seen:
116
+ seen.add(normalized)
117
+ out.append(normalized)
118
+ if len(out) >= limit:
119
+ return out
120
+ single = _extract_market_symbol(text) or _extract_market_symbol(text.upper())
121
+ normalized = str(single or "").upper()
122
+ if (
123
+ normalized
124
+ and normalized not in seen
125
+ and normalized not in _ROUTE_SYMBOL_BLOCKLIST
126
+ and not _is_blocked_market_symbol_candidate(normalized)
127
+ ):
128
+ out.append(normalized)
129
+ return out
130
+
131
+
132
+ @dataclass(frozen=True)
133
+ class RoutedCommand:
134
+ command: str
135
+ args: str = ""
136
+
137
+ @property
138
+ def text(self) -> str:
139
+ return f"{self.command} {self.args}".strip()
140
+
141
+
142
+ @dataclass(frozen=True)
143
+ class TechnicalArgs:
144
+ symbol: str
145
+ days: int = 120
146
+
147
+
148
+ @dataclass(frozen=True)
149
+ class AnalysisArgs:
150
+ symbol: str
151
+ focus: str = ""
152
+ lang: str = ""
153
+
154
+
155
+ _ANALYSIS_FOCUS_HINTS: tuple[tuple[tuple[str, ...], str], ...] = (
156
+ (("成交量", "交易量", "量价", "放量", "缩量", "volume", "volumes"), "volume"),
157
+ (("市值", "market cap", "marketcap", "capitalization"), "market_cap"),
158
+ (("基本面", "fundamental", "fundamentals", "valuation", "估值"), "fundamentals"),
159
+ (("技术面", "technical", "rsi", "macd", "支撑", "阻力"), "technical"),
160
+ )
161
+
162
+
163
+ def _analysis_focus_from_text(text: str) -> str:
164
+ low = text.lower()
165
+ for keywords, focus in _ANALYSIS_FOCUS_HINTS:
166
+ if any(k in low for k in keywords):
167
+ return focus
168
+ return ""
169
+
170
+
171
+ def parse_analysis_args(args: str, *, default_symbol: str = "AAPL") -> AnalysisArgs:
172
+ """Resolve natural-language /analyze args to one clean symbol plus focus."""
173
+ raw = (args or "").strip()
174
+ focus = ""
175
+ lang = ""
176
+ parts = raw.split()
177
+ cleaned_parts: list[str] = []
178
+ skip_next = False
179
+ for idx, part in enumerate(parts):
180
+ if skip_next:
181
+ skip_next = False
182
+ continue
183
+ token = part.strip()
184
+ low = token.lower()
185
+ if low.startswith("--focus="):
186
+ focus = low.split("=", 1)[1].strip()
187
+ continue
188
+ if low == "--focus" and idx + 1 < len(parts):
189
+ focus = parts[idx + 1].strip().lower()
190
+ skip_next = True
191
+ continue
192
+ if low.startswith("--lang="):
193
+ lang = low.split("=", 1)[1].strip().lower()
194
+ continue
195
+ if low == "--lang" and idx + 1 < len(parts):
196
+ lang = parts[idx + 1].strip().lower()
197
+ skip_next = True
198
+ continue
199
+ cleaned_parts.append(token)
200
+
201
+ cleaned = " ".join(cleaned_parts).strip()
202
+ if not focus:
203
+ focus = _analysis_focus_from_text(raw)
204
+
205
+ symbols = _route_symbols(cleaned or raw, limit=1)
206
+ symbol = symbols[0] if symbols else ""
207
+ if not symbol:
208
+ symbol = _extract_market_symbol(cleaned) or _extract_market_symbol((cleaned or raw).upper())
209
+ if not symbol:
210
+ for token in cleaned_parts:
211
+ candidate = token.strip(",,.。::;;()()[]【】").upper()
212
+ if candidate and not candidate.startswith("-") and not _is_blocked_market_symbol_candidate(candidate):
213
+ symbol = candidate
214
+ break
215
+ if lang not in ("zh", "en"):
216
+ zh_chars = sum(1 for c in raw if "\u4e00" <= c <= "\u9fff")
217
+ lang = "zh" if zh_chars else ""
218
+ return AnalysisArgs(symbol=(symbol or default_symbol).upper(), focus=focus, lang=lang)
219
+
220
+
221
+ def route_top_level_text(user_input: str, available_commands: set[str]) -> RoutedCommand | None:
222
+ """Translate bare workflow text into a slash command when possible."""
223
+
224
+ stripped = user_input.strip()
225
+ if not stripped or stripped.startswith("/"):
226
+ return None
227
+ low = stripped.lower()
228
+ compact_low = low.replace(" ", "")
229
+ low_words = {part.strip(".,,。::;;") for part in low.split()}
230
+ if "/tv" in available_commands and (
231
+ any(k in low for k in _TRADINGVIEW_HINTS)
232
+ or "tv" in low_words
233
+ or any(k in compact_low for k in _TRADINGVIEW_ZH_HINTS)
234
+ or ("tradingview" in compact_low)
235
+ ):
236
+ symbols = _route_symbols(stripped)
237
+ symbol = symbols[0] if symbols else ""
238
+ if symbol:
239
+ opts: list[str] = []
240
+ if any(k in low for k in ("pine", "strategy", "策略")):
241
+ opts.append("--pine")
242
+ if any(k in low for k in ("copy", "clipboard", "复制", "剪贴板")):
243
+ opts.append("--copy")
244
+ if any(k in low for k in ("reveal", "finder", "所在目录", "访达", "目录")):
245
+ opts.append("--reveal")
246
+ if any(k in low for k in ("txt", "text file", "文本副本", "文本")):
247
+ opts.append("--txt")
248
+ if any(k in low for k in ("打开", "open")) and "--pine" not in opts:
249
+ opts.append("--open")
250
+ if "--pine" not in opts:
251
+ if any(k in low for k in _TRADINGVIEW_BULLISH_HINTS):
252
+ opts.append("--bullish")
253
+ elif any(k in low for k in _TRADINGVIEW_BEARISH_HINTS):
254
+ opts.append("--bearish")
255
+ elif any(k in low for k in _TRADINGVIEW_ANALYSIS_HINTS):
256
+ opts.append("--analyze")
257
+ return RoutedCommand(command="/tv", args=" ".join([symbol, *opts]).strip())
258
+ for keywords, command in _VISUAL_ROUTE_PATTERNS:
259
+ if command not in available_commands:
260
+ continue
261
+ if any(k in low for k in keywords):
262
+ symbols = _route_symbols(stripped)
263
+ symbol = symbols[0] if symbols else ""
264
+ if command == "/dashboard":
265
+ mode = next(
266
+ (
267
+ dashboard_mode
268
+ for mode_kw, dashboard_mode in _DASHBOARD_MODE_HINTS
269
+ if any(k in low for k in mode_kw)
270
+ ),
271
+ "brief",
272
+ )
273
+ return RoutedCommand(command=command, args=mode)
274
+ if command == "/chart":
275
+ period = next(
276
+ (
277
+ period
278
+ for period_kw, period in _CHART_PERIOD_HINTS
279
+ if any(k in low for k in period_kw)
280
+ ),
281
+ "1y",
282
+ )
283
+ rest = " ".join(symbols) if symbols else stripped
284
+ return RoutedCommand(command=command, args=f"{rest} {period}".strip())
285
+ if command == "/report":
286
+ report_type = next(
287
+ (
288
+ report_type
289
+ for type_kw, report_type in _REPORT_TYPE_HINTS
290
+ if any(k in low for k in type_kw)
291
+ ),
292
+ "standard",
293
+ )
294
+ fmt = "html"
295
+ if any(k in low for k in ("markdown", "md")):
296
+ fmt = "md"
297
+ rest = symbol or stripped
298
+ args = " ".join(part for part in [rest, f"--type {report_type}" if report_type else "", f"--format {fmt}" if fmt else ""] if part)
299
+ return RoutedCommand(command=command, args=args)
300
+ if "/news" in available_commands and any(k in low for k in (
301
+ "新闻", "消息", "最新进展", "最近进展", "news", "latest", "recent",
302
+ )):
303
+ symbols = _route_symbols(stripped)
304
+ return RoutedCommand(command="/news", args=_news_topic(stripped, symbols))
305
+ parts = stripped.split(maxsplit=1)
306
+ keyword = parts[0].lower()
307
+ rest = parts[1] if len(parts) > 1 else ""
308
+ command = TOP_LEVEL_ROUTES.get(keyword)
309
+ if not command or command not in available_commands:
310
+ return None
311
+ if command == "/analyze":
312
+ parsed = parse_analysis_args(rest)
313
+ focus_arg = f" --focus {parsed.focus}" if parsed.focus else ""
314
+ zh_chars = sum(1 for c in stripped if "\u4e00" <= c <= "\u9fff")
315
+ lang_arg = f" --lang {'zh' if zh_chars else 'en'}"
316
+ return RoutedCommand(command=command, args=f"{parsed.symbol}{focus_arg}{lang_arg}".strip())
317
+ return RoutedCommand(command=command, args=rest)
318
+
319
+
320
+ def parse_symbols(args: str, fallback: list[str] | tuple[str, ...]) -> list[str]:
321
+ symbols = [part.upper() for part in args.split() if part.strip()]
322
+ return symbols or [str(item).upper() for item in fallback]
323
+
324
+
325
+ def sanitize_chart_symbol_args(raw_symbols: list[str] | tuple[str, ...]) -> list[str]:
326
+ """Drop analysis words that sometimes leak into chart symbol arguments."""
327
+ cleaned = [str(item or "").strip().strip(",,") for item in raw_symbols]
328
+ cleaned = [item for item in cleaned if item]
329
+ if not cleaned:
330
+ return []
331
+ if len(cleaned) == 1:
332
+ upper = cleaned[0].upper()
333
+ return [] if _is_blocked_market_symbol_candidate(upper) else cleaned
334
+
335
+ upper_tokens = [item.upper() for item in cleaned]
336
+ has_context_noise = any(
337
+ token in _CHART_CONTEXT_TOKEN_BLOCKLIST or _is_blocked_market_symbol_candidate(token)
338
+ for token in upper_tokens
339
+ )
340
+
341
+ out: list[str] = []
342
+ for raw, upper in zip(cleaned, upper_tokens):
343
+ if upper in _CHART_CONTEXT_TOKEN_BLOCKLIST:
344
+ continue
345
+ if _is_blocked_market_symbol_candidate(upper):
346
+ continue
347
+ # MA is a valid ticker (Mastercard), but in noisy generated chart args it
348
+ # usually comes from moving-average text next to TTM/above/below terms.
349
+ if upper == "MA" and has_context_noise and len(cleaned) > 2:
350
+ continue
351
+ out.append(raw)
352
+ return out
353
+
354
+
355
+ def parse_technical_args(args: str, *, default_symbol: str = "AAPL", default_days: int = 120) -> TechnicalArgs:
356
+ parts = args.strip().split()
357
+ symbol = default_symbol.upper()
358
+ days = default_days
359
+
360
+ if parts and not parts[0].startswith("-") and not parts[0].startswith("days="):
361
+ symbol = parts[0].upper()
362
+ option_parts = parts[1:]
363
+ else:
364
+ option_parts = parts
365
+
366
+ skip_next = False
367
+ for idx, part in enumerate(option_parts):
368
+ if skip_next:
369
+ skip_next = False
370
+ continue
371
+ raw = part.strip()
372
+ value = None
373
+ if raw.startswith("days="):
374
+ value = raw.split("=", 1)[1]
375
+ elif raw.startswith("--days="):
376
+ value = raw.split("=", 1)[1]
377
+ elif raw == "--days" and idx + 1 < len(option_parts):
378
+ value = option_parts[idx + 1]
379
+ skip_next = True
380
+
381
+ if value is not None:
382
+ try:
383
+ parsed = int(value)
384
+ if parsed > 0:
385
+ days = parsed
386
+ except ValueError:
387
+ pass
388
+
389
+ return TechnicalArgs(symbol=symbol, days=days)
390
+
391
+
392
+ async def try_top_level_route(user_input: str, commands) -> bool:
393
+ """Execute a top-level routed slash command through a SlashCommands object."""
394
+
395
+ routed = route_top_level_text(user_input, set(commands.commands))
396
+ if routed is None:
397
+ return False
398
+ await commands.execute(routed.text)
399
+ return True