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.
- agents/__init__.py +32 -0
- agents/base.py +190 -0
- agents/deep/__init__.py +37 -0
- agents/deep/calibration_loop.py +144 -0
- agents/deep/critic.py +125 -0
- agents/deep/deepen.py +193 -0
- agents/deep/models.py +149 -0
- agents/deep/pipeline.py +164 -0
- agents/deep/quant_fusion.py +192 -0
- agents/deep/themes.py +95 -0
- agents/deep/tiers.py +106 -0
- agents/financial/__init__.py +10 -0
- agents/financial/catalyst.py +279 -0
- agents/financial/debate.py +145 -0
- agents/financial/earnings.py +303 -0
- agents/financial/fundamental.py +159 -0
- agents/financial/macro.py +99 -0
- agents/financial/news.py +207 -0
- agents/financial/risk.py +132 -0
- agents/financial/sector.py +279 -0
- agents/financial/synthesis.py +274 -0
- agents/financial/technical.py +258 -0
- agents/portfolio_agent.py +333 -0
- agents/realty/__init__.py +62 -0
- agents/realty/asset_diagnosis.py +150 -0
- agents/realty/business_match.py +165 -0
- agents/realty/cashflow_verify.py +208 -0
- agents/realty/contract_rules.py +209 -0
- agents/realty/energy_anomaly.py +188 -0
- agents/realty/exit_settlement.py +207 -0
- agents/realty/fulfillment_risk.py +205 -0
- agents/realty/ops_optimize.py +159 -0
- agents/realty/revenue_share.py +214 -0
- agents/registry.py +144 -0
- agents/sports/__init__.py +0 -0
- agents/sports/football_agent.py +169 -0
- agents/team.py +289 -0
- aliyun_data_client.py +660 -0
- apps/README.md +12 -0
- apps/__init__.py +2 -0
- apps/channels/README.md +15 -0
- apps/cli/README.md +13 -0
- apps/cli/__init__.py +2 -0
- apps/cli/bootstrap.py +99 -0
- apps/cli/codegen_paths.py +29 -0
- apps/cli/commands/__init__.py +16 -0
- apps/cli/commands/analysis_cmds.py +288 -0
- apps/cli/commands/backtest_cmds.py +1887 -0
- apps/cli/commands/broker_cmds.py +1154 -0
- apps/cli/commands/business_workflow_cmds.py +289 -0
- apps/cli/commands/catalog.py +84 -0
- apps/cli/commands/data_cmds.py +405 -0
- apps/cli/commands/diagnostic_cmds.py +179 -0
- apps/cli/commands/diagnostic_ops_cmds.py +696 -0
- apps/cli/commands/finance_render.py +12 -0
- apps/cli/commands/market.py +399 -0
- apps/cli/commands/market_cmds.py +1276 -0
- apps/cli/commands/market_context.py +425 -0
- apps/cli/commands/market_render.py +7 -0
- apps/cli/commands/model_cmds.py +1579 -0
- apps/cli/commands/ops_cmds.py +668 -0
- apps/cli/commands/portfolio_cmds.py +962 -0
- apps/cli/commands/report.py +377 -0
- apps/cli/commands/scaffold_templates.py +617 -0
- apps/cli/commands/session_cmds.py +179 -0
- apps/cli/commands/session_ux_cmds.py +280 -0
- apps/cli/commands/team.py +588 -0
- apps/cli/commands/team_render.py +8 -0
- apps/cli/commands/ui_cmds.py +358 -0
- apps/cli/commands/workflow_cmds.py +279 -0
- apps/cli/commands/workspace_cmds.py +1414 -0
- apps/cli/config_paths.py +70 -0
- apps/cli/config_store.py +61 -0
- apps/cli/deterministic.py +122 -0
- apps/cli/direct.py +48 -0
- apps/cli/github_app_auth.py +135 -0
- apps/cli/handlers/__init__.py +11 -0
- apps/cli/handlers/broker_handlers.py +122 -0
- apps/cli/handlers/chart_handlers.py +1309 -0
- apps/cli/handlers/market_handlers.py +2509 -0
- apps/cli/handlers/realty_handlers.py +114 -0
- apps/cli/handlers/strategy_advice.py +82 -0
- apps/cli/hooks.py +180 -0
- apps/cli/i18n.py +284 -0
- apps/cli/intent.py +136 -0
- apps/cli/intent_router.py +217 -0
- apps/cli/lifecycle_hooks.py +48 -0
- apps/cli/main.py +29 -0
- apps/cli/market_metadata.py +135 -0
- apps/cli/market_universe.py +265 -0
- apps/cli/message_processing.py +257 -0
- apps/cli/plan_mode.py +139 -0
- apps/cli/plotly_html.py +15 -0
- apps/cli/prediction_feedback.py +202 -0
- apps/cli/preflight.py +497 -0
- apps/cli/project_aria.py +60 -0
- apps/cli/prompts/__init__.py +0 -0
- apps/cli/prompts/coding.py +658 -0
- apps/cli/prompts/system_prompts.py +531 -0
- apps/cli/prompts/ui.py +434 -0
- apps/cli/providers/__init__.py +1 -0
- apps/cli/providers/base.py +271 -0
- apps/cli/providers/chat_routing.py +80 -0
- apps/cli/providers/llm/__init__.py +1 -0
- apps/cli/providers/llm/ollama_stream.py +1170 -0
- apps/cli/providers/llm/sse_stream.py +216 -0
- apps/cli/providers/runtime_bridge.py +185 -0
- apps/cli/runtime_consumer.py +489 -0
- apps/cli/session_export.py +87 -0
- apps/cli/session_jsonl.py +207 -0
- apps/cli/session_store.py +112 -0
- apps/cli/todo_tracker.py +190 -0
- apps/cli/tools/__init__.py +40 -0
- apps/cli/tools/context.py +46 -0
- apps/cli/tools/file_tools.py +112 -0
- apps/cli/tools/market_tools.py +549 -0
- apps/cli/tools/notebook_tools.py +111 -0
- apps/cli/tools/system_tools.py +669 -0
- apps/cli/tools/write_tools.py +715 -0
- apps/cli/tradingview_bridge.py +434 -0
- apps/cli/update_check.py +152 -0
- apps/cli/utils/__init__.py +0 -0
- apps/cli/utils/market_detect.py +1578 -0
- apps/daemon/README.md +14 -0
- apps/vscode/README.md +115 -0
- apps/vscode/package.json +70 -0
- aria_cli.py +11636 -0
- aria_code-4.1.3.dist-info/METADATA +952 -0
- aria_code-4.1.3.dist-info/RECORD +284 -0
- aria_code-4.1.3.dist-info/WHEEL +5 -0
- aria_code-4.1.3.dist-info/entry_points.txt +2 -0
- aria_code-4.1.3.dist-info/licenses/LICENSE +121 -0
- aria_code-4.1.3.dist-info/top_level.txt +50 -0
- aria_daemon.py +1295 -0
- aria_feishu_bot.py +1359 -0
- aria_relay_client.py +182 -0
- aria_relay_server.py +405 -0
- aria_telegram_bot.py +202 -0
- ariarc.py +328 -0
- artifacts.py +491 -0
- backtest_report.py +472 -0
- brokers/__init__.py +72 -0
- brokers/base.py +207 -0
- brokers/capabilities.py +264 -0
- brokers/cn/__init__.py +10 -0
- brokers/cn/easytrader_broker.py +193 -0
- brokers/cn/futu_broker.py +194 -0
- brokers/cn/longbridge_broker.py +190 -0
- brokers/cn/tiger_broker.py +196 -0
- brokers/cn/xtquant_broker.py +175 -0
- brokers/config.py +364 -0
- brokers/intl/__init__.py +5 -0
- brokers/intl/alpaca_broker.py +183 -0
- brokers/intl/ibkr_broker.py +215 -0
- brokers/intl/webull_broker.py +156 -0
- brokers/paper_broker.py +259 -0
- brokers/planning.py +296 -0
- brokers/registry.py +181 -0
- brokers/trading.py +237 -0
- change_store.py +127 -0
- command_safety.py +19 -0
- computer_use_tools.py +504 -0
- dashboard_generator.py +578 -0
- data_analysis_tools.py +808 -0
- data_cleaner.py +483 -0
- data_service.py +481 -0
- datasources/__init__.py +23 -0
- datasources/base.py +166 -0
- datasources/router.py +221 -0
- datasources/sources/__init__.py +15 -0
- datasources/sources/akshare_source.py +269 -0
- datasources/sources/alpha_vantage_source.py +202 -0
- datasources/sources/edgar_source.py +218 -0
- datasources/sources/finnhub_source.py +197 -0
- datasources/sources/fred_source.py +219 -0
- datasources/sources/tushare_source.py +141 -0
- datasources/sources/web_scraper_source.py +278 -0
- datasources/sources/world_bank_source.py +205 -0
- datasources/sources/yfinance_source.py +152 -0
- demo_player.py +204 -0
- doctor.py +508 -0
- file_analysis_tools.py +734 -0
- finance_formulas.py +389 -0
- football_data_client.py +1670 -0
- intent_classifier.py +358 -0
- local_finance_tools.py +3221 -0
- local_llm_provider.py +552 -0
- macro_tools.py +368 -0
- market_data_client.py +1899 -0
- mcp_client.py +506 -0
- memory_manager.py +245 -0
- model_capability.py +416 -0
- notification_tools.py +248 -0
- packages/__init__.py +23 -0
- packages/aria_agents/__init__.py +5 -0
- packages/aria_agents/manifest.py +69 -0
- packages/aria_core/__init__.py +34 -0
- packages/aria_core/architecture.py +192 -0
- packages/aria_core/export.py +124 -0
- packages/aria_core/manifest.py +65 -0
- packages/aria_infra/__init__.py +15 -0
- packages/aria_infra/arthera.py +52 -0
- packages/aria_infra/doctor.py +246 -0
- packages/aria_infra/product.py +37 -0
- packages/aria_mcp/__init__.py +25 -0
- packages/aria_mcp/bridge.py +38 -0
- packages/aria_mcp/config.py +97 -0
- packages/aria_mcp/tools.py +61 -0
- packages/aria_sdk/__init__.py +19 -0
- packages/aria_sdk/client.py +396 -0
- packages/aria_sdk/providers.py +70 -0
- packages/aria_sdk/streaming.py +73 -0
- packages/aria_sdk/types.py +86 -0
- packages/aria_services/__init__.py +55 -0
- packages/aria_services/context.py +258 -0
- packages/aria_services/data.py +11 -0
- packages/aria_services/provider_health.py +189 -0
- packages/aria_services/registry.py +213 -0
- packages/aria_services/usage.py +138 -0
- packages/aria_skills/__init__.py +5 -0
- packages/aria_skills/registry.py +59 -0
- packages/aria_tools/__init__.py +5 -0
- packages/aria_tools/registry.py +128 -0
- packages/quant_engine/__init__.py +6 -0
- packages/quant_engine/sports/__init__.py +72 -0
- packages/quant_engine/sports/calibrator.py +353 -0
- packages/quant_engine/sports/dixon_coles.py +234 -0
- packages/quant_engine/sports/elo.py +299 -0
- packages/quant_engine/sports/form.py +188 -0
- packages/quant_engine/sports/h2h.py +195 -0
- packages/quant_engine/sports/ml_model.py +354 -0
- packages/quant_engine/sports/predictor.py +311 -0
- packages/quant_engine/sports/tracker.py +664 -0
- packages/quant_engine/stochastic/__init__.py +27 -0
- packages/quant_engine/stochastic/gbm_enhanced.py +195 -0
- packages/quant_engine/stochastic/ito_calculus.py +477 -0
- packages/quant_engine/stochastic/kelly_criterion.py +181 -0
- packages/quant_engine/stochastic/monte_carlo_advanced.py +95 -0
- packages/quant_engine/stochastic/options_pricing.py +573 -0
- packages/quant_engine/stochastic/stochastic_processes.py +90 -0
- plan_utils.py +194 -0
- plugin_loader.py +328 -0
- portfolio_ledger.py +262 -0
- privacy/__init__.py +5 -0
- privacy/feedback.py +123 -0
- project_tools.py +525 -0
- providers/__init__.py +30 -0
- providers/llm/__init__.py +19 -0
- providers/llm/anthropic.py +184 -0
- providers/llm/base.py +139 -0
- providers/llm/ollama.py +128 -0
- providers/llm/openai_compat.py +282 -0
- providers/llm/registry.py +358 -0
- realty_data_tools.py +659 -0
- report_generator.py +1314 -0
- runtime/__init__.py +103 -0
- runtime/agent_loop.py +1183 -0
- runtime/approval.py +51 -0
- runtime/events.py +102 -0
- runtime/gateway.py +128 -0
- runtime/lsp.py +346 -0
- runtime/subagent.py +258 -0
- runtime/tool_executor.py +104 -0
- runtime/tool_policy.py +106 -0
- safety/__init__.py +21 -0
- safety/permissions.py +275 -0
- setup_wizard.py +653 -0
- strategy_vault.py +420 -0
- ui/__init__.py +100 -0
- ui/banner.py +310 -0
- ui/completer.py +391 -0
- ui/console.py +271 -0
- ui/image_render.py +243 -0
- ui/input_box.py +376 -0
- ui/picker.py +195 -0
- ui/render/__init__.py +11 -0
- ui/render/finance.py +1480 -0
- ui/render/market.py +225 -0
- ui/render/output.py +681 -0
- ui/render/team.py +346 -0
- ui/robot.py +235 -0
- workspace/__init__.py +6 -0
- workspace/files.py +170 -0
- 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
|