@weaxs/openclaw-stock-analysis 0.1.3 → 0.1.6

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.
package/index.ts CHANGED
@@ -28,9 +28,14 @@ const toolsDir = existsSync(join(here, "tools"))
28
28
  const repoRoot = dirname(toolsDir);
29
29
  const isWin = process.platform === "win32";
30
30
  const venvPython = join(repoRoot, ".venv", isWin ? "Scripts" : "bin", "python3");
31
+ // Staged-payload layout (openclaw/tools present in a dev checkout): the venv
32
+ // still lives at the repo root one level up.
33
+ const parentVenvPython = join(repoRoot, "..", ".venv", isWin ? "Scripts" : "bin", "python3");
31
34
 
32
35
  function pythonBin(): string {
33
- return existsSync(venvPython) ? venvPython : "python3";
36
+ if (existsSync(venvPython)) return venvPython;
37
+ if (existsSync(parentVenvPython)) return parentVenvPython;
38
+ return "python3";
34
39
  }
35
40
 
36
41
  async function runPy(script: string, args: string[]): Promise<string> {
@@ -45,17 +50,17 @@ export default definePluginEntry({
45
50
  id: "stock-analysis",
46
51
  name: "Stock Analysis",
47
52
  description:
48
- "Stock analysis, screening, and strategy backtesting across A/HK/US markets",
53
+ "Stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
49
54
  register(api) {
50
55
  // --- Data Tools ---
51
56
 
52
57
  api.registerTool({
53
58
  name: "get_kline",
54
59
  description:
55
- "获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)",
60
+ "获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF",
56
61
  parameters: Type.Object({
57
62
  symbol: Type.String({
58
- description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)",
63
+ description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)、7203.T(日股)、005930.KS(韩股)、2330.TW(台股)",
59
64
  }),
60
65
  period: Type.Optional(
61
66
  Type.Union(
@@ -80,7 +85,7 @@ export default definePluginEntry({
80
85
 
81
86
  api.registerTool({
82
87
  name: "get_quote",
83
- description: "获取股票实时行情报价。支持A股、港股、美股",
88
+ description: "获取股票实时行情报价。支持A股、港股、美股、日股、韩股、台股",
84
89
  parameters: Type.Object({
85
90
  symbol: Type.String({ description: "股票代码" }),
86
91
  }),
@@ -215,11 +220,11 @@ export default definePluginEntry({
215
220
  api.registerTool({
216
221
  name: "get_market_indices",
217
222
  description:
218
- "获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500",
223
+ "获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500;JP: 日经225/东证;KR: KOSPI/KOSDAQ;TW: 台湾加权",
219
224
  parameters: Type.Object({
220
225
  region: Type.Optional(
221
226
  Type.Union(
222
- [Type.Literal("cn"), Type.Literal("hk"), Type.Literal("us")],
227
+ [Type.Literal("cn"), Type.Literal("hk"), Type.Literal("us"), Type.Literal("jp"), Type.Literal("kr"), Type.Literal("tw")],
223
228
  { description: "市场区域,默认 cn" }
224
229
  )
225
230
  ),
@@ -264,7 +269,7 @@ export default definePluginEntry({
264
269
  api.registerTool({
265
270
  name: "get_stock_info",
266
271
  description:
267
- "获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,HK/US返回行业/公司简介",
272
+ "获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,其他市场返回行业/公司简介",
268
273
  parameters: Type.Object({
269
274
  symbol: Type.String({ description: "股票代码" }),
270
275
  }),
@@ -457,10 +462,10 @@ export default definePluginEntry({
457
462
  api.registerTool({
458
463
  name: "check_trading_day",
459
464
  description:
460
- "查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)三市场",
465
+ "查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)、JP(日股)、KR(韩股)、TW(台股)",
461
466
  parameters: Type.Object({
462
467
  market: Type.Union(
463
- [Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US")],
468
+ [Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US"), Type.Literal("JP"), Type.Literal("KR"), Type.Literal("TW")],
464
469
  { description: "市场" }
465
470
  ),
466
471
  date: Type.Optional(
@@ -477,10 +482,10 @@ export default definePluginEntry({
477
482
 
478
483
  api.registerTool({
479
484
  name: "get_trading_days",
480
- description: "获取最近/未来N个交易日列表。支持CN/HK/US三市场",
485
+ description: "获取最近/未来N个交易日列表。支持CN/HK/US/JP/KR/TW",
481
486
  parameters: Type.Object({
482
487
  market: Type.Union(
483
- [Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US")],
488
+ [Type.Literal("CN"), Type.Literal("HK"), Type.Literal("US"), Type.Literal("JP"), Type.Literal("KR"), Type.Literal("TW")],
484
489
  { description: "市场" }
485
490
  ),
486
491
  direction: Type.Optional(
@@ -757,5 +762,205 @@ export default definePluginEntry({
757
762
  return asText(out);
758
763
  },
759
764
  });
765
+
766
+ // --- Diagnostics & Capabilities ---
767
+
768
+ api.registerTool({
769
+ name: "diagnose_data_sources",
770
+ description:
771
+ "数据源诊断 — 检查当前环境可用的数据 provider(akshare/tushare/yfinance/finnhub/longbridge/alphavantage),输出每个市场的可用链路、缺失 env、warnings",
772
+ parameters: Type.Object({
773
+ market: Type.Optional(
774
+ Type.Union(
775
+ [
776
+ Type.Literal("A"),
777
+ Type.Literal("HK"),
778
+ Type.Literal("US"),
779
+ Type.Literal("JP"),
780
+ Type.Literal("KR"),
781
+ Type.Literal("TW"),
782
+ Type.Literal("all"),
783
+ ],
784
+ { description: "市场,默认 all" }
785
+ )
786
+ ),
787
+ }),
788
+ async execute(_id, params) {
789
+ const out = await runPy("diagnostics.py", [
790
+ "check",
791
+ "--market",
792
+ params.market ?? "all",
793
+ ]);
794
+ return asText(out);
795
+ },
796
+ });
797
+
798
+ api.registerTool({
799
+ name: "get_market_capabilities",
800
+ description:
801
+ "市场能力边界 — 返回指定市场支持/不支持的工具列表,避免 agent 对港股调 get_chip_distribution 或对美股调 get_capital_flow 后编造数据",
802
+ parameters: Type.Object({
803
+ market: Type.Optional(
804
+ Type.Union(
805
+ [Type.Literal("A"), Type.Literal("HK"), Type.Literal("US"), Type.Literal("JP"), Type.Literal("KR"), Type.Literal("TW")],
806
+ { description: "市场代码" }
807
+ )
808
+ ),
809
+ symbol: Type.Optional(
810
+ Type.String({ description: "股票代码(自动识别市场,与 market 二选一)" })
811
+ ),
812
+ }),
813
+ async execute(_id, params) {
814
+ const args = params.symbol
815
+ ? ["get", "--symbol", params.symbol]
816
+ : ["get", "--market", params.market ?? "A"];
817
+ const out = await runPy("capabilities.py", args);
818
+ return asText(out);
819
+ },
820
+ });
821
+
822
+ // --- Report Rendering ---
823
+
824
+ api.registerTool({
825
+ name: "render_stock_report",
826
+ description:
827
+ "股票分析报告渲染 — 将结构化 JSON(符合 schemas/report_schema.json)通过 j2 模板渲染为 Markdown。template: brief|full。仅渲染,不保存不推送",
828
+ parameters: Type.Object({
829
+ report: Type.Object({}, { additionalProperties: true, description: "结构化股票报告" }),
830
+ template: Type.Optional(
831
+ Type.Union([Type.Literal("brief"), Type.Literal("full")], {
832
+ description: "模板类型,默认 full",
833
+ })
834
+ ),
835
+ }),
836
+ async execute(_id, params) {
837
+ const b64 = Buffer.from(JSON.stringify(params.report), "utf-8").toString("base64");
838
+ const out = await runPy("report_renderer.py", [
839
+ "stock",
840
+ "--template",
841
+ params.template ?? "full",
842
+ "--input-b64",
843
+ b64,
844
+ ]);
845
+ return asText(out);
846
+ },
847
+ });
848
+
849
+ api.registerTool({
850
+ name: "render_market_report",
851
+ description:
852
+ "大盘复盘报告渲染 — 将结构化 JSON(符合 schemas/market_review_schema.json)通过 j2 模板渲染为 Markdown",
853
+ parameters: Type.Object({
854
+ report: Type.Object({}, { additionalProperties: true, description: "结构化市场复盘" }),
855
+ template: Type.Optional(
856
+ Type.Union([Type.Literal("full")], { description: "模板类型,默认 full" })
857
+ ),
858
+ }),
859
+ async execute(_id, params) {
860
+ const b64 = Buffer.from(JSON.stringify(params.report), "utf-8").toString("base64");
861
+ const out = await runPy("report_renderer.py", [
862
+ "market",
863
+ "--template",
864
+ params.template ?? "full",
865
+ "--input-b64",
866
+ b64,
867
+ ]);
868
+ return asText(out);
869
+ },
870
+ });
871
+
872
+ // --- Watchlist / Position / Alert Context ---
873
+
874
+ api.registerTool({
875
+ name: "build_watchlist_context",
876
+ description:
877
+ "自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析",
878
+ parameters: Type.Object({
879
+ symbols: Type.String({ description: "逗号分隔的股票代码列表" }),
880
+ include_market_review: Type.Optional(
881
+ Type.Boolean({ description: "是否附带各市场复盘,默认 false" })
882
+ ),
883
+ workers: Type.Optional(Type.Number({ description: "并发数,默认 3" })),
884
+ }),
885
+ async execute(_id, params) {
886
+ const args = [
887
+ "build",
888
+ params.symbols,
889
+ "--workers",
890
+ String(params.workers ?? 3),
891
+ ];
892
+ if (params.include_market_review) args.push("--include-market-review");
893
+ const out = await runPy("watchlist_context.py", args);
894
+ return asText(out);
895
+ },
896
+ });
897
+
898
+ api.registerTool({
899
+ name: "analyze_position_context",
900
+ description:
901
+ "持仓上下文分析 — 输入成本/仓位/止损止盈,结合现价和技术位输出浮盈亏、离止损距离、风险级别、操作建议。无状态、不存账户",
902
+ parameters: Type.Object({
903
+ symbol: Type.String({ description: "股票代码" }),
904
+ cost: Type.Number({ description: "成本价" }),
905
+ quantity: Type.Number({ description: "持仓数量" }),
906
+ stop_loss: Type.Optional(Type.Number({ description: "止损价" })),
907
+ take_profit: Type.Optional(Type.Number({ description: "止盈价" })),
908
+ }),
909
+ async execute(_id, params) {
910
+ const args = [
911
+ "analyze",
912
+ params.symbol,
913
+ "--cost",
914
+ String(params.cost),
915
+ "--quantity",
916
+ String(params.quantity),
917
+ ];
918
+ if (params.stop_loss !== undefined) {
919
+ args.push("--stop-loss", String(params.stop_loss));
920
+ }
921
+ if (params.take_profit !== undefined) {
922
+ args.push("--take-profit", String(params.take_profit));
923
+ }
924
+ const out = await runPy("position_context.py", args);
925
+ return asText(out);
926
+ },
927
+ });
928
+
929
+ api.registerTool({
930
+ name: "check_alert_rules",
931
+ description:
932
+ "无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型:price_below/price_above/change_pct_above/change_pct_below/volume_ratio_above/anomaly/risk_veto/risk_level_at_least。不做调度不存历史",
933
+ parameters: Type.Object({
934
+ symbol: Type.String({ description: "股票代码" }),
935
+ rules: Type.Array(
936
+ Type.Object({}, { additionalProperties: true }),
937
+ { description: "规则列表,每项 { type, value }" }
938
+ ),
939
+ }),
940
+ async execute(_id, params) {
941
+ const b64 = Buffer.from(JSON.stringify(params.rules), "utf-8").toString("base64");
942
+ const out = await runPy("alert_rules.py", [
943
+ "check",
944
+ params.symbol,
945
+ "--rules-b64",
946
+ b64,
947
+ ]);
948
+ return asText(out);
949
+ },
950
+ });
951
+
952
+ api.registerTool({
953
+ name: "parse_stock_list",
954
+ description:
955
+ "自选股/文本导入解析 — 从自然语言、CSV、Markdown 表格提取股票,自动识别 A 股 6 位代码、港股 xxxxx.HK、美股 ticker、日股 xxxx.T、韩股 xxxxxx.KS/KQ、台股 xxxx.TW,并调用 name_resolver 处理中文股票名",
956
+ parameters: Type.Object({
957
+ text: Type.String({ description: "待解析的文本" }),
958
+ }),
959
+ async execute(_id, params) {
960
+ const b64 = Buffer.from(String(params.text), "utf-8").toString("base64");
961
+ const out = await runPy("import_parser.py", ["parse", "--text-b64", b64]);
962
+ return asText(out);
963
+ },
964
+ });
760
965
  },
761
966
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "stock-analysis",
3
3
  "name": "Stock Analysis",
4
- "description": "Stock analysis, screening, and strategy backtesting across A/HK/US markets (akshare/yfinance/tushare)",
4
+ "description": "Stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets (akshare/yfinance/tushare)",
5
5
  "contracts": {
6
6
  "tools": [
7
7
  "get_kline",
@@ -34,7 +34,15 @@
34
34
  "detect_market_regime",
35
35
  "get_market_review",
36
36
  "run_watchlist_analysis",
37
- "detect_anomaly"
37
+ "detect_anomaly",
38
+ "diagnose_data_sources",
39
+ "get_market_capabilities",
40
+ "render_stock_report",
41
+ "render_market_report",
42
+ "build_watchlist_context",
43
+ "analyze_position_context",
44
+ "check_alert_rules",
45
+ "parse_stock_list"
38
46
  ]
39
47
  },
40
48
  "activation": {
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@weaxs/openclaw-stock-analysis",
3
- "version": "0.1.3",
4
- "description": "OpenClaw plugin for stock analysis, screening, and strategy backtesting across A/HK/US markets",
3
+ "version": "0.1.6",
4
+ "description": "OpenClaw plugin for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
7
7
  "openclaw": {
8
- "extensions": ["./index.ts"],
8
+ "extensions": [
9
+ "./index.ts"
10
+ ],
9
11
  "compat": {
10
12
  "pluginApi": ">=2026.3.24-beta.2",
11
13
  "minGatewayVersion": "2026.3.24-beta.2"
@@ -20,11 +22,13 @@
20
22
  },
21
23
  "files": [
22
24
  "index.ts",
25
+ "dist/",
23
26
  "openclaw.plugin.json",
24
27
  "README.md",
25
28
  "tools/",
26
29
  "skills/",
27
30
  "schemas/",
31
+ "templates/",
28
32
  "strategies/",
29
33
  "scripts/"
30
34
  ],
@@ -0,0 +1,176 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "MarketReviewReport",
4
+ "description": "结构化大盘复盘报告格式",
5
+ "type": "object",
6
+ "properties": {
7
+ "market": {
8
+ "type": "string",
9
+ "enum": ["A", "HK", "US"],
10
+ "description": "市场代码"
11
+ },
12
+ "market_cn": {
13
+ "type": "string",
14
+ "description": "市场中文名(A 股 / 港股 / 美股)"
15
+ },
16
+ "review_date": { "type": "string", "format": "date" },
17
+ "temperature": {
18
+ "type": "object",
19
+ "description": "市场温度(来自 market_review.review)",
20
+ "properties": {
21
+ "score": { "type": "number", "minimum": 0, "maximum": 100 },
22
+ "level": { "type": "string", "enum": ["constructive", "neutral", "weak"] },
23
+ "signal": { "type": "string", "enum": ["green", "yellow", "red"] }
24
+ },
25
+ "required": ["score", "signal"]
26
+ },
27
+ "strategy_stance": {
28
+ "type": "string",
29
+ "enum": ["offensive", "balanced", "defensive"],
30
+ "description": "建议策略姿态"
31
+ },
32
+ "regime": {
33
+ "type": "object",
34
+ "description": "市场阶段(来自 detect_market_regime)",
35
+ "properties": {
36
+ "regime": { "type": "string" },
37
+ "regime_cn": { "type": "string" },
38
+ "confidence": { "type": "number" },
39
+ "recommended_skills": { "type": "array", "items": { "type": "string" } }
40
+ }
41
+ },
42
+ "overview": {
43
+ "type": "object",
44
+ "description": "盘面总览",
45
+ "properties": {
46
+ "headline": { "type": "string", "description": "一句话总览" },
47
+ "indices": {
48
+ "type": "array",
49
+ "items": {
50
+ "type": "object",
51
+ "properties": {
52
+ "name": { "type": "string" },
53
+ "code": { "type": "string" },
54
+ "price": { "type": "number" },
55
+ "change_pct": { "type": "number" },
56
+ "volume": { "type": ["number", "string"] }
57
+ }
58
+ }
59
+ },
60
+ "breadth": {
61
+ "type": "object",
62
+ "description": "涨跌家数(仅 A 股)",
63
+ "properties": {
64
+ "up_count": { "type": "integer" },
65
+ "down_count": { "type": "integer" },
66
+ "limit_up_count": { "type": "integer" },
67
+ "limit_down_count": { "type": "integer" },
68
+ "turnover": { "type": ["number", "string"] },
69
+ "turnover_change": { "type": "string", "description": "放量 / 缩量 / 持平" }
70
+ }
71
+ }
72
+ }
73
+ },
74
+ "index_structure": {
75
+ "type": "object",
76
+ "description": "指数结构与分化",
77
+ "properties": {
78
+ "large_vs_small": { "type": "string", "description": "大盘 vs 中小盘表现差异" },
79
+ "blue_chip_vs_theme": { "type": "string", "description": "权重股 vs 题材股分化" },
80
+ "position_assessment": { "type": "string", "description": "指数位置(突破 / 回落 / 震荡)" }
81
+ }
82
+ },
83
+ "sectors": {
84
+ "type": "object",
85
+ "description": "板块主线(仅 A 股有完整数据)",
86
+ "properties": {
87
+ "leading": {
88
+ "type": "array",
89
+ "items": {
90
+ "type": "object",
91
+ "properties": {
92
+ "name": { "type": "string" },
93
+ "change_pct": { "type": "number" },
94
+ "logic": { "type": "string", "description": "上涨逻辑(政策 / 业绩 / 事件)" }
95
+ }
96
+ }
97
+ },
98
+ "lagging": {
99
+ "type": "array",
100
+ "items": {
101
+ "type": "object",
102
+ "properties": {
103
+ "name": { "type": "string" },
104
+ "change_pct": { "type": "number" },
105
+ "reason": { "type": "string" }
106
+ }
107
+ }
108
+ },
109
+ "main_storylines": {
110
+ "type": "array",
111
+ "items": {
112
+ "type": "object",
113
+ "properties": {
114
+ "theme": { "type": "string" },
115
+ "stage": { "type": "string", "description": "首日 / 加速 / 高潮 / 退潮" },
116
+ "sustainability": { "type": "string", "enum": ["high", "medium", "low"] }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ },
122
+ "capital_emotion": {
123
+ "type": "object",
124
+ "description": "资金与情绪",
125
+ "properties": {
126
+ "turnover_level": { "type": "string", "description": "成交额历史分位" },
127
+ "limit_ratio": { "type": "string", "description": "涨停 / 跌停比情绪解读" },
128
+ "money_effect": { "type": "string", "description": "赚钱效应判断" },
129
+ "consecutive_limit_height": { "type": "integer", "description": "连板高度(仅 A 股)" }
130
+ }
131
+ },
132
+ "catalysts": {
133
+ "type": "array",
134
+ "description": "消息催化",
135
+ "items": {
136
+ "type": "object",
137
+ "properties": {
138
+ "title": { "type": "string" },
139
+ "category": { "type": "string", "description": "政策 / 业绩 / 事件 / 国际 / 其他" },
140
+ "impact": { "type": "string", "description": "对市场的影响路径" },
141
+ "direction": { "type": "string", "enum": ["positive", "negative", "neutral"] }
142
+ }
143
+ }
144
+ },
145
+ "tomorrow_strategy": {
146
+ "type": "object",
147
+ "description": "明日策略",
148
+ "properties": {
149
+ "stance": { "type": "string", "enum": ["offensive", "balanced", "defensive"] },
150
+ "position_advice": { "type": "string", "description": "建议仓位区间" },
151
+ "focus_sectors": { "type": "array", "items": { "type": "string" } },
152
+ "avoid": { "type": "array", "items": { "type": "string" } },
153
+ "key_levels": {
154
+ "type": "object",
155
+ "properties": {
156
+ "support": { "type": ["number", "string"] },
157
+ "resistance": { "type": ["number", "string"] }
158
+ }
159
+ }
160
+ }
161
+ },
162
+ "risks": {
163
+ "type": "array",
164
+ "description": "风险提示",
165
+ "items": {
166
+ "type": "object",
167
+ "properties": {
168
+ "level": { "type": "string", "enum": ["high", "medium", "low"] },
169
+ "category": { "type": "string", "description": "系统性 / 板块 / 个股 / 外围" },
170
+ "description": { "type": "string" }
171
+ }
172
+ }
173
+ }
174
+ },
175
+ "required": ["market", "review_date", "temperature", "strategy_stance"]
176
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+ # Sync all manifest version fields to the version derived from the current
3
+ # git tag ($GITHUB_REF_NAME on GitHub Actions, e.g. "v0.1.5" → "0.1.5").
4
+ #
5
+ # Called by .github/workflows/publish.yml before each publish step. Changes
6
+ # are in-CI only — never committed back to the repo.
7
+ #
8
+ # Manifests updated:
9
+ # - pyproject.toml (PyPI package version)
10
+ # - package.json (npm root package)
11
+ # - package-lock.json (kept in lockstep so `npm publish` doesn't warn)
12
+ # - openclaw/package.json (OpenClaw npm package version)
13
+ #
14
+ # Idempotent: running twice with the same tag is a no-op.
15
+ set -euo pipefail
16
+
17
+ TAG="${1:-${GITHUB_REF_NAME:-}}"
18
+ if [[ -z "$TAG" ]]; then
19
+ echo "usage: $0 <tag> (or set GITHUB_REF_NAME)" >&2
20
+ exit 1
21
+ fi
22
+ VERSION="${TAG#v}"
23
+
24
+ # Basic shape check — semver-ish, e.g. 0.1.5 or 1.2.3-rc.1
25
+ if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.]+)?$ ]]; then
26
+ echo "sync-version: unexpected tag shape '$TAG' → version '$VERSION'" >&2
27
+ exit 1
28
+ fi
29
+
30
+ echo "sync-version: setting version to $VERSION (from tag $TAG)"
31
+
32
+ # pyproject.toml — the only `version = "..."` at file scope
33
+ python3 - "$VERSION" <<'PY'
34
+ import re, sys, pathlib
35
+ version = sys.argv[1]
36
+ p = pathlib.Path("pyproject.toml")
37
+ text = p.read_text()
38
+ new, n = re.subn(r'^version = "[^"]+"', f'version = "{version}"', text, count=1, flags=re.M)
39
+ if n != 1:
40
+ sys.exit(f"pyproject.toml: expected one version = line, got {n}")
41
+ p.write_text(new)
42
+ print(f" pyproject.toml: {n} substitution(s)")
43
+ PY
44
+
45
+ # npm root and openclaw sub-package
46
+ # `npm version` refuses in a workspace unless we bypass with --no-git-tag-version
47
+ # --allow-same-version keeps it idempotent when the tag already matches.
48
+ for dir in "." "openclaw"; do
49
+ if [[ -f "$dir/package.json" ]]; then
50
+ (cd "$dir" && npm version "$VERSION" --no-git-tag-version --allow-same-version) >/dev/null
51
+ echo " $dir/package.json: bumped"
52
+ fi
53
+ done
54
+
55
+ echo "sync-version: done"
@@ -0,0 +1,90 @@
1
+ {# Shared Jinja2 macros for stock-analysis-plugin report templates. #}
2
+
3
+ {% macro decision_emoji(decision) -%}
4
+ {%- if decision == 'strong_buy' -%}🟢🟢
5
+ {%- elif decision == 'buy' -%}🟢
6
+ {%- elif decision == 'hold' -%}⚪
7
+ {%- elif decision == 'sell' -%}🟡
8
+ {%- elif decision == 'strong_sell' -%}🔴
9
+ {%- else -%}❔
10
+ {%- endif -%}
11
+ {%- endmacro %}
12
+
13
+ {% macro decision_label(decision) -%}
14
+ {%- if decision == 'strong_buy' -%}强烈买入
15
+ {%- elif decision == 'buy' -%}买入
16
+ {%- elif decision == 'hold' -%}观望
17
+ {%- elif decision == 'sell' -%}卖出
18
+ {%- elif decision == 'strong_sell' -%}强烈卖出
19
+ {%- else -%}-
20
+ {%- endif -%}
21
+ {%- endmacro %}
22
+
23
+ {% macro confidence_label(c) -%}
24
+ {%- if c == 'high' -%}高
25
+ {%- elif c == 'medium' -%}中
26
+ {%- elif c == 'low' -%}低
27
+ {%- else -%}-
28
+ {%- endif -%}
29
+ {%- endmacro %}
30
+
31
+ {% macro signal_emoji(signal) -%}
32
+ {%- if signal == 'green' -%}🟢
33
+ {%- elif signal == 'yellow' -%}🟡
34
+ {%- elif signal == 'red' -%}🔴
35
+ {%- else -%}⚪
36
+ {%- endif -%}
37
+ {%- endmacro %}
38
+
39
+ {% macro signal_label(signal) -%}
40
+ {%- if signal == 'green' -%}绿灯(进攻)
41
+ {%- elif signal == 'yellow' -%}黄灯(均衡)
42
+ {%- elif signal == 'red' -%}红灯(防守)
43
+ {%- else -%}-
44
+ {%- endif -%}
45
+ {%- endmacro %}
46
+
47
+ {% macro stance_label(stance) -%}
48
+ {%- if stance == 'offensive' -%}进攻
49
+ {%- elif stance == 'balanced' -%}均衡
50
+ {%- elif stance == 'defensive' -%}防守
51
+ {%- else -%}-
52
+ {%- endif -%}
53
+ {%- endmacro %}
54
+
55
+ {% macro risk_emoji(level) -%}
56
+ {%- if level == 'high' -%}🔴
57
+ {%- elif level == 'medium' -%}🟡
58
+ {%- elif level == 'low' -%}🟢
59
+ {%- else -%}⚪
60
+ {%- endif -%}
61
+ {%- endmacro %}
62
+
63
+ {% macro change_pct(v) -%}
64
+ {%- if v is none or v is not number -%}-
65
+ {%- elif v > 0 -%}+{{ '%.2f'|format(v) }}%
66
+ {%- else -%}{{ '%.2f'|format(v) }}%
67
+ {%- endif -%}
68
+ {%- endmacro %}
69
+
70
+ {% macro fmt_num(v, digits=2) -%}
71
+ {%- if v is none -%}-
72
+ {%- elif v is number -%}{{ ('%%.%df' % digits)|format(v) }}
73
+ {%- else -%}{{ v }}
74
+ {%- endif -%}
75
+ {%- endmacro %}
76
+
77
+ {% macro market_cn(m) -%}
78
+ {%- if m == 'A' -%}A 股
79
+ {%- elif m == 'HK' -%}港股
80
+ {%- elif m == 'US' -%}美股
81
+ {%- else -%}{{ m }}
82
+ {%- endif -%}
83
+ {%- endmacro %}
84
+
85
+ {% macro direction_emoji(d) -%}
86
+ {%- if d == 'positive' -%}✅
87
+ {%- elif d == 'negative' -%}⚠️
88
+ {%- else -%}ℹ️
89
+ {%- endif -%}
90
+ {%- endmacro %}