stock-analysis-plugin 0.2.6 → 0.2.8

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 (36) hide show
  1. package/README.md +88 -15
  2. package/package.json +2 -1
  3. package/pi/index.ts +867 -72
  4. package/schemas/market_review_schema.json +12 -5
  5. package/schemas/report_schema.json +65 -1
  6. package/scripts/cli-timeout.mjs +27 -0
  7. package/scripts/json-input.mjs +26 -0
  8. package/skills/bull-trend/SKILL.md +11 -1
  9. package/skills/bull-trend/references/monthly-trend-strategy.md +47 -0
  10. package/skills/bull-trend/references/trend-horizons.md +43 -0
  11. package/skills/bull-trend/references/trend-temperature.md +57 -0
  12. package/skills/bull-trend/scripts/market_trend.py +78 -0
  13. package/skills/event-driven/SKILL.md +4 -0
  14. package/skills/growth-quality/SKILL.md +4 -0
  15. package/skills/market-review/SKILL.md +2 -0
  16. package/skills/stock-analysis/SKILL.md +17 -3
  17. package/skills/stock-analysis/references/stateless-analysis.md +66 -0
  18. package/skills/stock-screener/SKILL.md +5 -1
  19. package/skills/strategy-backtest/SKILL.md +19 -0
  20. package/templates/market_review/full.md.j2 +7 -0
  21. package/templates/stock_analysis/_evidence.md.j2 +11 -0
  22. package/templates/stock_analysis/brief.md.j2 +2 -0
  23. package/templates/stock_analysis/full.md.j2 +2 -0
  24. package/tools/_subproc.py +66 -11
  25. package/tools/backtest.py +143 -19
  26. package/tools/capabilities.py +12 -0
  27. package/tools/cli_budgets.json +27 -0
  28. package/tools/gather.py +4 -6
  29. package/tools/market_review.py +30 -9
  30. package/tools/screener.py +57 -15
  31. package/tools/signal_tracker.py +77 -6
  32. package/tools/stateless_analysis.py +630 -0
  33. package/tools/stock_data.py +90 -15
  34. package/tools/technical.py +186 -0
  35. package/tools/trend_strategy.py +365 -0
  36. package/tools/watchlist_context.py +18 -7
package/pi/index.ts CHANGED
@@ -1,8 +1,51 @@
1
+ import { withJsonInput } from "../scripts/json-input.mjs";
1
2
  import type { ExtensionAPI } from "pi-agent";
2
3
  import { existsSync } from "fs";
3
4
  import { fileURLToPath } from "url";
4
5
 
6
+ import { commandTimeout } from "../scripts/cli-timeout.mjs";
7
+
5
8
  export default (pi: ExtensionAPI) => {
9
+ const tools: Parameters<ExtensionAPI["registerTool"]>[0][] = [];
10
+ const registerTool: ExtensionAPI["registerTool"] = (tool) => {
11
+ tools.push(tool);
12
+ pi.registerTool({ ...tool, defaultActive: false });
13
+ };
14
+ let discoveryEnabled: boolean | undefined;
15
+ const exposeAllTools = () => {
16
+ for (const tool of tools) pi.registerTool(tool);
17
+ discoveryEnabled = false;
18
+ };
19
+ const initializeDiscovery = () => {
20
+ if (discoveryEnabled !== undefined) return;
21
+ // Exposure metadata distinguishes native discovery from older tool-list APIs.
22
+ if (!pi.getAllTools || !pi.getActiveTools || !pi.setActiveTools
23
+ || !pi.getAllTools().some(tool => tool.name === "tool_search" && tool.exposure === "model-only")) {
24
+ exposeAllTools();
25
+ return;
26
+ }
27
+ pi.setActiveTools([...new Set([...pi.getActiveTools(), "tool_search"])]);
28
+ if (!pi.getActiveTools().includes("tool_search")) {
29
+ exposeAllTools();
30
+ return;
31
+ }
32
+ for (const tool of tools) pi.registerTool({ ...tool, exposure: "deferred" });
33
+ discoveryEnabled = true;
34
+ };
35
+ pi.on("session_start", initializeDiscovery);
36
+ pi.on("before_agent_start", () => {
37
+ initializeDiscovery();
38
+ if (discoveryEnabled && !pi.getActiveTools?.().includes("tool_search")) {
39
+ exposeAllTools();
40
+ }
41
+ return discoveryEnabled ? {
42
+ message: {
43
+ customType: "stock-analysis-discovery",
44
+ content: "Stock analysis tools are available through tool_search. Search using English keywords or exact tool names (e.g. get_quote, get_financials, screen_stocks, run_backtest); its search does not tokenize Chinese. Load the tools needed for the task, then call them normally.",
45
+ display: false,
46
+ },
47
+ } : undefined;
48
+ });
6
49
  // Resolve the plugin root robustly: __dirname under jiti/CJS-style loaders,
7
50
  // else import.meta.url under native ESM (where __dirname is undefined).
8
51
  const baseDir =
@@ -15,14 +58,717 @@ export default (pi: ExtensionAPI) => {
15
58
  const venvPython = `${baseDir}/.venv/${isWin ? "Scripts/python.exe" : "bin/python3"}`;
16
59
  // Fallback: on Windows "python3" is usually the Microsoft Store stub — prefer "python".
17
60
  const python = existsSync(venvPython) ? venvPython : isWin ? "python" : "python3";
18
- const py = (script: string, args: string[]) =>
19
- pi.exec(python, [`${toolsDir}/${script}`, ...args]);
61
+ const py = async (script: string, args: string[]) => {
62
+ const result = await pi.exec(python, [`${toolsDir}/${script}`, ...args], { timeout: commandTimeout(script, args) });
63
+ if (result.killed || !result.stdout.trim()) {
64
+ return {...result, stdout: JSON.stringify({error: result.killed ? "Python command timed out" : "Python command returned no JSON"})};
65
+ }
66
+ return result;
67
+ };
20
68
  const asText = (text: string) => ({
21
69
  content: [{ type: "text" as const, text }],
22
70
  details: {},
23
71
  });
24
72
 
25
- pi.registerTool({
73
+ registerTool({
74
+ name: "compare_stocks",
75
+ description: "无状态同行指标比较:先用现有财务/行情工具取数,再传companies;仅相同unit/basis/period可排序,缺失不填零,不生成买卖综合分。",
76
+ parameters: {
77
+ "type": "object",
78
+ "properties": {
79
+ "companies": {
80
+ "type": "array",
81
+ "items": {
82
+ "type": "object",
83
+ "properties": {
84
+ "symbol": {
85
+ "type": "string",
86
+ "description": "唯一股票代码"
87
+ },
88
+ "period": {
89
+ "type": "string",
90
+ "description": "统一可比期间;财务用报告期,估值用估值日"
91
+ },
92
+ "metrics": {
93
+ "type": "array",
94
+ "items": {
95
+ "type": "object",
96
+ "properties": {
97
+ "name": {
98
+ "type": "string",
99
+ "description": "指标名,如pe/roe/net_income"
100
+ },
101
+ "value": {
102
+ "anyOf": [
103
+ {
104
+ "type": "number"
105
+ },
106
+ {
107
+ "type": "null"
108
+ }
109
+ ],
110
+ "description": "有限数值;缺失为null"
111
+ },
112
+ "unit": {
113
+ "type": "string",
114
+ "description": "精确单位,如multiple/percent/fraction/CNY/USD"
115
+ },
116
+ "basis": {
117
+ "type": "string",
118
+ "description": "口径,如TTM/annual/consolidated;区分累计与单季"
119
+ },
120
+ "source": {
121
+ "type": "string",
122
+ "description": "原始证据URL或字段路径"
123
+ }
124
+ },
125
+ "required": [
126
+ "name",
127
+ "value",
128
+ "unit",
129
+ "basis"
130
+ ],
131
+ "additionalProperties": false
132
+ },
133
+ "description": "结构化指标,单位、口径明确,缺失不填零"
134
+ }
135
+ },
136
+ "required": [
137
+ "symbol",
138
+ "period",
139
+ "metrics"
140
+ ],
141
+ "additionalProperties": false
142
+ },
143
+ "description": "2..30家公司,调用方确认可比性"
144
+ }
145
+ },
146
+ "required": [
147
+ "companies"
148
+ ],
149
+ "additionalProperties": false
150
+ },
151
+ async execute(_id, params) {
152
+ return asText(await withJsonInput(params, async (path: string) =>
153
+ (await py("stateless_analysis.py", ["peers", "--input", path])).stdout));
154
+ },
155
+ });
156
+
157
+ registerTool({
158
+ name: "analyze_disclosure_changes",
159
+ description: "无状态公告财报比较:传新旧正文及指标,返回变更行号、来源与财务变化;负/零基数增长率为null。不下载PDF、不代替经济解读。",
160
+ parameters: {
161
+ "type": "object",
162
+ "properties": {
163
+ "previous": {
164
+ "type": "object",
165
+ "properties": {
166
+ "text": {
167
+ "type": "string",
168
+ "description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"
169
+ },
170
+ "source": {
171
+ "type": "string",
172
+ "description": "原文URL或文档标识"
173
+ },
174
+ "period": {
175
+ "type": "string",
176
+ "description": "报告期,如2025年度"
177
+ },
178
+ "metrics": {
179
+ "type": "array",
180
+ "items": {
181
+ "type": "object",
182
+ "properties": {
183
+ "name": {
184
+ "type": "string",
185
+ "description": "指标名,如pe/roe/net_income"
186
+ },
187
+ "value": {
188
+ "anyOf": [
189
+ {
190
+ "type": "number"
191
+ },
192
+ {
193
+ "type": "null"
194
+ }
195
+ ],
196
+ "description": "有限数值;缺失为null"
197
+ },
198
+ "unit": {
199
+ "type": "string",
200
+ "description": "精确单位,如multiple/percent/fraction/CNY/USD"
201
+ },
202
+ "basis": {
203
+ "type": "string",
204
+ "description": "口径,如TTM/annual/consolidated;区分累计与单季"
205
+ },
206
+ "source": {
207
+ "type": "string",
208
+ "description": "原始证据URL或字段路径"
209
+ }
210
+ },
211
+ "required": [
212
+ "name",
213
+ "value",
214
+ "unit",
215
+ "basis"
216
+ ],
217
+ "additionalProperties": false
218
+ },
219
+ "description": "结构化指标,单位、口径明确,缺失不填零"
220
+ }
221
+ },
222
+ "required": [
223
+ "text",
224
+ "source",
225
+ "period",
226
+ "metrics"
227
+ ],
228
+ "additionalProperties": false
229
+ },
230
+ "current": {
231
+ "type": "object",
232
+ "properties": {
233
+ "text": {
234
+ "type": "string",
235
+ "description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"
236
+ },
237
+ "source": {
238
+ "type": "string",
239
+ "description": "原文URL或文档标识"
240
+ },
241
+ "period": {
242
+ "type": "string",
243
+ "description": "报告期,如2025年度"
244
+ },
245
+ "metrics": {
246
+ "type": "array",
247
+ "items": {
248
+ "type": "object",
249
+ "properties": {
250
+ "name": {
251
+ "type": "string",
252
+ "description": "指标名,如pe/roe/net_income"
253
+ },
254
+ "value": {
255
+ "anyOf": [
256
+ {
257
+ "type": "number"
258
+ },
259
+ {
260
+ "type": "null"
261
+ }
262
+ ],
263
+ "description": "有限数值;缺失为null"
264
+ },
265
+ "unit": {
266
+ "type": "string",
267
+ "description": "精确单位,如multiple/percent/fraction/CNY/USD"
268
+ },
269
+ "basis": {
270
+ "type": "string",
271
+ "description": "口径,如TTM/annual/consolidated;区分累计与单季"
272
+ },
273
+ "source": {
274
+ "type": "string",
275
+ "description": "原始证据URL或字段路径"
276
+ }
277
+ },
278
+ "required": [
279
+ "name",
280
+ "value",
281
+ "unit",
282
+ "basis"
283
+ ],
284
+ "additionalProperties": false
285
+ },
286
+ "description": "结构化指标,单位、口径明确,缺失不填零"
287
+ }
288
+ },
289
+ "required": [
290
+ "text",
291
+ "source",
292
+ "period",
293
+ "metrics"
294
+ ],
295
+ "additionalProperties": false
296
+ },
297
+ "max_changes": {
298
+ "type": "number",
299
+ "description": "变化上限1..100,默认30"
300
+ }
301
+ },
302
+ "required": [
303
+ "previous",
304
+ "current"
305
+ ],
306
+ "additionalProperties": false
307
+ },
308
+ async execute(_id, params) {
309
+ return asText(await withJsonInput(params, async (path: string) =>
310
+ (await py("stateless_analysis.py", ["disclosure", "--input", path])).stdout));
311
+ },
312
+ });
313
+
314
+ registerTool({
315
+ name: "analyze_portfolio_risk",
316
+ description: "无状态现货多头组合风险:输入持仓、基准币种现金与汇率,返回集中度、币种/行业敞口、价格盈亏和止损情景。缺汇率报错;不保存账户。",
317
+ parameters: {
318
+ "type": "object",
319
+ "properties": {
320
+ "positions": {
321
+ "type": "array",
322
+ "items": {
323
+ "type": "object",
324
+ "properties": {
325
+ "symbol": {
326
+ "type": "string",
327
+ "description": "唯一代码,重复持仓先汇总"
328
+ },
329
+ "quantity": {
330
+ "type": "number",
331
+ "description": "正持仓数量"
332
+ },
333
+ "price": {
334
+ "type": "number",
335
+ "description": "正现价"
336
+ },
337
+ "currency": {
338
+ "type": "string",
339
+ "description": "持仓币种,如CNY/USD/HKD"
340
+ },
341
+ "cost": {
342
+ "type": "number",
343
+ "description": "同币种正成本价,可选"
344
+ },
345
+ "stop_price": {
346
+ "type": "number",
347
+ "description": "同币种正止损价,可选"
348
+ },
349
+ "sector": {
350
+ "type": "string",
351
+ "description": "统一行业分类,可选"
352
+ },
353
+ "as_of": {
354
+ "type": "string",
355
+ "description": "实际估值时点,建议ISO8601"
356
+ }
357
+ },
358
+ "required": [
359
+ "symbol",
360
+ "quantity",
361
+ "price",
362
+ "currency"
363
+ ],
364
+ "additionalProperties": false
365
+ },
366
+ "description": "1..100个现货多头持仓"
367
+ },
368
+ "base_currency": {
369
+ "type": "string",
370
+ "description": "基准币种"
371
+ },
372
+ "cash": {
373
+ "type": "number",
374
+ "description": "基准币种现金,非负"
375
+ },
376
+ "fx_rates": {
377
+ "type": "array",
378
+ "items": {
379
+ "type": "object",
380
+ "properties": {
381
+ "currency": {
382
+ "type": "string",
383
+ "description": "唯一非基准币种"
384
+ },
385
+ "rate": {
386
+ "type": "number",
387
+ "description": "一单位该币种对应多少基准币种,正数"
388
+ }
389
+ },
390
+ "required": [
391
+ "currency",
392
+ "rate"
393
+ ],
394
+ "additionalProperties": false
395
+ },
396
+ "description": "显式现价汇率;基准币种隐含1,不得重复"
397
+ },
398
+ "histories": {
399
+ "type": "array",
400
+ "items": {
401
+ "type": "object",
402
+ "properties": {
403
+ "symbol": {
404
+ "type": "string",
405
+ "description": "对应唯一持仓股票"
406
+ },
407
+ "prices": {
408
+ "type": "array",
409
+ "items": {
410
+ "type": "object",
411
+ "properties": {
412
+ "date": {
413
+ "type": "string",
414
+ "description": "YYYY-MM-DD,唯一日期"
415
+ },
416
+ "close": {
417
+ "type": "number",
418
+ "description": "正有限收盘价"
419
+ }
420
+ },
421
+ "required": [
422
+ "date",
423
+ "close"
424
+ ],
425
+ "additionalProperties": false
426
+ },
427
+ "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
428
+ }
429
+ },
430
+ "required": [
431
+ "symbol",
432
+ "prices"
433
+ ],
434
+ "additionalProperties": false
435
+ },
436
+ "description": "可选历史,共同日期本币价格收益相关性,不计汇率"
437
+ }
438
+ },
439
+ "required": [
440
+ "positions",
441
+ "base_currency",
442
+ "cash"
443
+ ],
444
+ "additionalProperties": false
445
+ },
446
+ async execute(_id, params) {
447
+ return asText(await withJsonInput(params, async (path: string) =>
448
+ (await py("stateless_analysis.py", ["portfolio", "--input", path])).stdout));
449
+ },
450
+ });
451
+
452
+ registerTool({
453
+ name: "calculate_position_size",
454
+ description: "无状态多头仓位预算:同币种金额,按现金/风险预算/最大仓位/交易单位取最小数量,双边费用和滑点参与止损情景;不执行交易。",
455
+ parameters: {
456
+ "type": "object",
457
+ "properties": {
458
+ "equity": {
459
+ "type": "number",
460
+ "description": "总权益,正数"
461
+ },
462
+ "cash": {
463
+ "type": "number",
464
+ "description": "可用现金,0..equity"
465
+ },
466
+ "entry_price": {
467
+ "type": "number",
468
+ "description": "计划入场价,正数"
469
+ },
470
+ "stop_price": {
471
+ "type": "number",
472
+ "description": "正止损价,低于入场价"
473
+ },
474
+ "risk_fraction": {
475
+ "type": "number",
476
+ "description": "单笔风险占权益比例0..1,如0.01"
477
+ },
478
+ "lot_size": {
479
+ "type": "number",
480
+ "description": "正整数交易单位,用户确认,不猜港股每手数量"
481
+ },
482
+ "max_position_fraction": {
483
+ "type": "number",
484
+ "description": "本次买入最大资金占比0..1,默认1;已有同股持仓先扣减额度"
485
+ },
486
+ "fee_rate": {
487
+ "type": "number",
488
+ "description": "每边比例费用0..0.1,默认0;不含未提供税费/最低收费"
489
+ },
490
+ "slippage_rate": {
491
+ "type": "number",
492
+ "description": "每边滑点0..0.1,默认0"
493
+ }
494
+ },
495
+ "required": [
496
+ "equity",
497
+ "cash",
498
+ "entry_price",
499
+ "stop_price",
500
+ "risk_fraction",
501
+ "lot_size"
502
+ ],
503
+ "additionalProperties": false
504
+ },
505
+ async execute(_id, params) {
506
+ return asText(await withJsonInput(params, async (path: string) =>
507
+ (await py("stateless_analysis.py", ["position_size", "--input", path])).stdout));
508
+ },
509
+ });
510
+
511
+ registerTool({
512
+ name: "analyze_event_study",
513
+ description: "无状态事件研究:提供同市场股票及基准完整价格、事件日期;事件前一交易日收盘为基点,计算交易日窗口收益差。缺窗口/基准为null,标注重叠,不推断因果。",
514
+ parameters: {
515
+ "type": "object",
516
+ "properties": {
517
+ "prices": {
518
+ "type": "array",
519
+ "items": {
520
+ "type": "object",
521
+ "properties": {
522
+ "date": {
523
+ "type": "string",
524
+ "description": "YYYY-MM-DD,唯一日期"
525
+ },
526
+ "close": {
527
+ "type": "number",
528
+ "description": "正有限收盘价"
529
+ }
530
+ },
531
+ "required": [
532
+ "date",
533
+ "close"
534
+ ],
535
+ "additionalProperties": false
536
+ },
537
+ "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
538
+ },
539
+ "benchmark_prices": {
540
+ "type": "array",
541
+ "items": {
542
+ "type": "object",
543
+ "properties": {
544
+ "date": {
545
+ "type": "string",
546
+ "description": "YYYY-MM-DD,唯一日期"
547
+ },
548
+ "close": {
549
+ "type": "number",
550
+ "description": "正有限收盘价"
551
+ }
552
+ },
553
+ "required": [
554
+ "date",
555
+ "close"
556
+ ],
557
+ "additionalProperties": false
558
+ },
559
+ "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
560
+ },
561
+ "event_dates": {
562
+ "type": "array",
563
+ "items": {
564
+ "type": "string",
565
+ "description": "YYYY-MM-DD,盘后公告传下一交易日"
566
+ },
567
+ "description": "1..100个唯一事件日"
568
+ },
569
+ "price_basis": {
570
+ "type": "string",
571
+ "description": "仅显式prices模式必需;代码模式报告实际提供方标记,缺失为unknown,须核实"
572
+ },
573
+ "horizons": {
574
+ "type": "array",
575
+ "items": {
576
+ "type": "number",
577
+ "description": "0=事件日,1=下一交易日;整数0..250"
578
+ },
579
+ "description": "1..20个窗口,默认0/1/5/10/20"
580
+ },
581
+ "start_date": {
582
+ "type": "string",
583
+ "description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"
584
+ },
585
+ "end_date": {
586
+ "type": "string",
587
+ "description": "代码模式必需,YYYY-MM-DD,晚于start_date"
588
+ },
589
+ "symbol": {
590
+ "type": "string",
591
+ "description": "股票代码;与benchmark/start_date/end_date一起直接取数,和prices模式互斥"
592
+ },
593
+ "benchmark": {
594
+ "type": "string",
595
+ "description": "同市场基准代码;与symbol一起使用"
596
+ }
597
+ },
598
+ "required": [
599
+ "event_dates"
600
+ ],
601
+ "additionalProperties": false
602
+ },
603
+ async execute(_id, params) {
604
+ return asText(await withJsonInput(params, async (path: string) =>
605
+ (await py("stateless_analysis.py", ["event_study", "--input", path])).stdout));
606
+ },
607
+ });
608
+
609
+ registerTool({
610
+ name: "validate_backtest",
611
+ description: "无状态回测稳健性:输入历史OHLCV和完整候选DSL;滚动训练选参数、后续不重叠窗口验证,列出全部样本内敏感性及跨标的结果。仅next_open,不自动优化或保存。",
612
+ parameters: {
613
+ "type": "object",
614
+ "properties": {
615
+ "datasets": {
616
+ "type": "array",
617
+ "items": {
618
+ "type": "object",
619
+ "properties": {
620
+ "symbol": {
621
+ "type": "string",
622
+ "description": "唯一股票代码"
623
+ },
624
+ "price_basis": {
625
+ "type": "string",
626
+ "description": "已核实复权/原始价格口径"
627
+ },
628
+ "bars": {
629
+ "type": "array",
630
+ "items": {
631
+ "type": "object",
632
+ "properties": {
633
+ "date": {
634
+ "type": "string",
635
+ "description": "YYYY-MM-DD"
636
+ },
637
+ "open": {
638
+ "type": "number",
639
+ "description": "有限OHLCV;价格为正、volume非负"
640
+ },
641
+ "high": {
642
+ "type": "number",
643
+ "description": "有限OHLCV;价格为正、volume非负"
644
+ },
645
+ "low": {
646
+ "type": "number",
647
+ "description": "有限OHLCV;价格为正、volume非负"
648
+ },
649
+ "close": {
650
+ "type": "number",
651
+ "description": "有限OHLCV;价格为正、volume非负"
652
+ },
653
+ "volume": {
654
+ "type": "number",
655
+ "description": "有限OHLCV;价格为正、volume非负"
656
+ }
657
+ },
658
+ "required": [
659
+ "date",
660
+ "open",
661
+ "high",
662
+ "low",
663
+ "close",
664
+ "volume"
665
+ ],
666
+ "additionalProperties": false
667
+ },
668
+ "description": "日期递增完整OHLCV,每组最多2000条,至少train_bars+test_bars"
669
+ }
670
+ },
671
+ "required": [
672
+ "symbol",
673
+ "price_basis",
674
+ "bars"
675
+ ],
676
+ "additionalProperties": false
677
+ },
678
+ "description": "1..5个标的,复用get_kline取数"
679
+ },
680
+ "strategies": {
681
+ "type": "array",
682
+ "items": {
683
+ "type": "object",
684
+ "properties": {
685
+ "name": {
686
+ "type": "string",
687
+ "description": "唯一候选名"
688
+ },
689
+ "strategy": {
690
+ "type": "object",
691
+ "additionalProperties": true,
692
+ "description": "完整既有YAML DSL对应JSON,允许parameters引用;仅next_open"
693
+ }
694
+ },
695
+ "required": [
696
+ "name",
697
+ "strategy"
698
+ ],
699
+ "additionalProperties": false
700
+ },
701
+ "description": "1..5个预先确定的候选,禁止测试结果回调参数"
702
+ },
703
+ "train_bars": {
704
+ "type": "number",
705
+ "description": "训练交易日数30..1000,默认126"
706
+ },
707
+ "test_bars": {
708
+ "type": "number",
709
+ "description": "测试交易日数30..1000,默认63"
710
+ },
711
+ "capital": {
712
+ "type": "number",
713
+ "description": "每窗口初始资金,默认1000000"
714
+ },
715
+ "start_date": {
716
+ "type": "string",
717
+ "description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"
718
+ },
719
+ "end_date": {
720
+ "type": "string",
721
+ "description": "代码模式必需,YYYY-MM-DD,晚于start_date"
722
+ },
723
+ "symbols": {
724
+ "type": "array",
725
+ "items": {
726
+ "type": "string"
727
+ },
728
+ "description": "1..5个唯一股票代码,配合start_date/end_date直接取数;和datasets互斥"
729
+ }
730
+ },
731
+ "required": [
732
+ "strategies"
733
+ ],
734
+ "additionalProperties": false
735
+ },
736
+ async execute(_id, params) {
737
+ return asText(await withJsonInput(params, async (path: string) =>
738
+ (await py("stateless_analysis.py", ["robustness", "--input", path])).stdout));
739
+ },
740
+ });
741
+
742
+ registerTool({
743
+ name: "compare_analysis_snapshots",
744
+ description: "无状态快照比较:传新旧JSON,返回JSON Pointer及新增/删除/变化/失效/恢复;不保存快照。数组整体比较,调用前按symbol对齐。",
745
+ parameters: {
746
+ "type": "object",
747
+ "properties": {
748
+ "previous": {
749
+ "type": "object",
750
+ "additionalProperties": true,
751
+ "description": "JSON对象,详见共享Skill与README"
752
+ },
753
+ "current": {
754
+ "type": "object",
755
+ "additionalProperties": true,
756
+ "description": "JSON对象,详见共享Skill与README"
757
+ }
758
+ },
759
+ "required": [
760
+ "previous",
761
+ "current"
762
+ ],
763
+ "additionalProperties": false
764
+ },
765
+ async execute(_id, params) {
766
+ return asText(await withJsonInput(params, async (path: string) =>
767
+ (await py("stateless_analysis.py", ["snapshot", "--input", path])).stdout));
768
+ },
769
+ });
770
+
771
+ registerTool({
26
772
  name: "get_announcements",
27
773
  description: "查询A股巨潮公告标题、日期、类型和原文PDF链接;按日期范围/类别筛选,默认近90天,top=1..500。第一版不提取正文,truncated提示截断。",
28
774
  parameters: {
@@ -71,7 +817,7 @@ export default (pi: ExtensionAPI) => {
71
817
  },
72
818
  });
73
819
 
74
- pi.registerTool({
820
+ registerTool({
75
821
  name: "get_us_holdings",
76
822
  description: "查询SEC 13F:mode=auto默认有13F申报时查机构,否则按发行人CIK反查持仓机构;manager/issuer可显式指定。发行人通过官方13D/G精确映射CUSIP,扫描最新已发布13F窗口,处理重述/补充修订,返回实际报告期、截止日及映射覆盖。首次约100MB下载,后续缓存;无映射明确报错,不做名称猜测。需SEC_USER_AGENT含真实联系邮箱,不是实时或全部证券持仓。",
77
823
  parameters: {
@@ -93,7 +839,7 @@ export default (pi: ExtensionAPI) => {
93
839
  },
94
840
  });
95
841
 
96
- pi.registerTool({
842
+ registerTool({
97
843
  name: "get_insider_trades",
98
844
  description: "查询美股发行人近期Form 4/4-A内部人交易(SEC官方XML),保留人员职务、交易代码、买卖方向、数量、价格、脚注和衍生品标志。需SEC_USER_AGENT含真实联系邮箱;days按申报日期筛选,top限制文件数,修订勿重复计数。",
99
845
  parameters: {
@@ -124,7 +870,7 @@ export default (pi: ExtensionAPI) => {
124
870
 
125
871
  // --- Data Tools ---
126
872
 
127
- pi.registerTool({
873
+ registerTool({
128
874
  name: "get_valuation_history",
129
875
  description: "查询A/HK股票历史PE-TTM/PB、当前正值分位和10/25/50/75/90分位Band,返回实际采样区间;亏损估值分位为null。years=1..10,按天缓存。HK配置LIXINGER_TOKEN时优先理杏仁非金融公司日历史,失败降级百度,不混接来源。",
130
876
  parameters: {
@@ -149,7 +895,7 @@ export default (pi: ExtensionAPI) => {
149
895
  },
150
896
  });
151
897
 
152
- pi.registerTool({
898
+ registerTool({
153
899
  name: "get_index_valuation",
154
900
  description: "查询中国指数估值历史分位与Band;乐咕乐股PE/PB优先,中证官方历史补充滚动PE并保留近期PE1口径。缺PB时可用LIXINGER_TOKEN补充理杏仁mcw历史,来源与算法分别标明,不混接同一指标。",
155
901
  parameters: {
@@ -174,7 +920,7 @@ export default (pi: ExtensionAPI) => {
174
920
  },
175
921
  });
176
922
 
177
- pi.registerTool({
923
+ registerTool({
178
924
  name: "get_earnings_calendar",
179
925
  description: "查询财报日历:A股report_date必填季度期末,返回预约/修订/实际披露与业绩预告;HK需symbol,优先HKEX已公告业绩审批董事会排期(不是实际披露日),缺失时返回供应商日期。HK可按已知财政期末过滤,未知期次另列。",
180
926
  parameters: {
@@ -201,7 +947,7 @@ export default (pi: ExtensionAPI) => {
201
947
  },
202
948
  });
203
949
 
204
- pi.registerTool({
950
+ registerTool({
205
951
  name: "get_shareholder_structure",
206
952
  description: "查询A股股东户数、十大流通股东变化及沪深交易所季度北向合计持股;官方总量优先,十大HKSCC名义持股仅兜底且标明口径。HK返回港交所南向记录。缺失不当零,期末不等于已公布。",
207
953
  parameters: {
@@ -226,7 +972,7 @@ export default (pi: ExtensionAPI) => {
226
972
  },
227
973
  });
228
974
 
229
- pi.registerTool({
975
+ registerTool({
230
976
  name: "get_etf_details",
231
977
  description: "查询A股ETF净值折溢价、规模、披露持仓及沪深完整PCF申赎篮子;篮子不是实际持仓。include_full_holdings=true另取最近可得半年度/年度披露股票表,含数量/市值/报告期,非实时全资产组合;benchmark用于跟踪误差。",
232
978
  parameters: {
@@ -256,7 +1002,7 @@ export default (pi: ExtensionAPI) => {
256
1002
  },
257
1003
  });
258
1004
 
259
- pi.registerTool({
1005
+ registerTool({
260
1006
  name: "get_dividends",
261
1007
  description: "查询A/HK分红历史、除息日历、已实施TTM股息与连续年数。mode=ranking省略symbol,market=A查报告期排行,market=HK查HKEX/LSEG年度股息率排行(report_date须年末);排行均非当前TTM收益率。缺失不按零。",
262
1008
  parameters: {
@@ -297,10 +1043,10 @@ export default (pi: ExtensionAPI) => {
297
1043
  },
298
1044
  });
299
1045
 
300
- pi.registerTool({
1046
+ registerTool({
301
1047
  name: "get_kline",
302
1048
  description:
303
- "获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF。A股股票/ETF返回前复权价格,每条记录 adjusted=qfq;sh000xxx/sz399xxx 指数返回原始点位,adjusted=none。需要历史价格自行计算或画图时用;只问指标用 get_technical_analysis,只问现价用 get_quote",
1049
+ "获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF。A股股票/ETF返回前复权价格,每条记录 adjusted=qfq;sh000xxx/sz399xxx 指数返回原始点位,adjusted=none。需要历史价格自行计算或画图时用;只问指标用 get_technical_analysis,只问现价用 get_quote。每条记录附 source、UTC fetched_at、data_as_of 和 adjusted;非A股复权口径可能为total_return/qfq/unknown,未知不能假定已复权。部分来源附 adjustment_factor(复权价格/原始价格);缺失不能猜测换算系数。",
304
1050
  parameters: {
305
1051
  type: "object",
306
1052
  properties: {
@@ -333,10 +1079,10 @@ export default (pi: ExtensionAPI) => {
333
1079
  },
334
1080
  });
335
1081
 
336
- pi.registerTool({
1082
+ registerTool({
337
1083
  name: "get_quote",
338
1084
  description:
339
- "获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价",
1085
+ "获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价。返回 source、UTC fetched_at 和提供方 data_as_of(未知为null);as_of_basis区分提供方时间与交易日历推断,采集时间不等于行情时间。",
340
1086
  parameters: {
341
1087
  type: "object",
342
1088
  properties: {
@@ -353,7 +1099,7 @@ export default (pi: ExtensionAPI) => {
353
1099
  },
354
1100
  });
355
1101
 
356
- pi.registerTool({
1102
+ registerTool({
357
1103
  name: "get_capital_flow",
358
1104
  description:
359
1105
  "获取A股资金流向(主力/超大单/大单/中单/小单净流入)。detail=个股每日明细,summary=多日汇总+趋势,sector_flow=板块资金流排行。可配合 get_chip_distribution 验证主力行为",
@@ -382,7 +1128,7 @@ export default (pi: ExtensionAPI) => {
382
1128
  },
383
1129
  });
384
1130
 
385
- pi.registerTool({
1131
+ registerTool({
386
1132
  name: "get_news",
387
1133
  description: "获取个股最近N天财经新闻快讯(轻量、无需配置)。需要深度全网情报用 search_comprehensive_intel,按主题搜索用 search_stock_news,读文章全文用 extract_article",
388
1134
  parameters: {
@@ -405,7 +1151,7 @@ export default (pi: ExtensionAPI) => {
405
1151
  },
406
1152
  });
407
1153
 
408
- pi.registerTool({
1154
+ registerTool({
409
1155
  name: "get_financials",
410
1156
  description:
411
1157
  "获取股票财务摘要及历史趋势,按天缓存。A股annual=true与periods=10取十年年报;港股可配置LIXINGER_TOKEN取非金融公司财务序列,保留币种/披露日/实际财年,历史比率单位percent。有效Yahoo顶层快照按整组保留,currency为财报币种、market_cap_currency为市值币种、snapshot_source标明来源;缺失值及report_date不混入历史数值/日期。缺token或无权限降级原有来源并标注不足,不补造缺失。估值历史用get_valuation_history,披露排期用get_earnings_calendar",
@@ -437,10 +1183,10 @@ export default (pi: ExtensionAPI) => {
437
1183
 
438
1184
  // --- Analysis Tools ---
439
1185
 
440
- pi.registerTool({
1186
+ registerTool({
441
1187
  name: "get_technical_analysis",
442
1188
  description:
443
- "获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 + 趋势/偏离度/支撑压力位;多周期共振时 resonance.direction ∈ aligned_bullish/aligned_bearish/divergent)。个股技术面综合判断与买卖时机分析的首选;只要均线数值或自定义周期用 calculate_ma,专问量价用 get_volume_analysis,扫当日异动用 detect_anomaly",
1189
+ "获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 + 趋势/偏离度/支撑压力位;附 trend_temperature(实验性EMA差/ATR描述;direction为均线方向;validation_status=not_validated,非星球指标,七档不作入场依据;另附 trend_horizons:21/63/252根日K月度动量,建议count=360,非概率、未验证);多周期共振时 resonance.direction ∈ aligned_bullish/aligned_bearish/divergent)。个股技术面综合判断与买卖时机分析的首选;只要均线数值或自定义周期用 calculate_ma,专问量价用 get_volume_analysis,扫当日异动用 detect_anomaly",
444
1190
  parameters: {
445
1191
  type: "object",
446
1192
  properties: {
@@ -478,7 +1224,7 @@ export default (pi: ExtensionAPI) => {
478
1224
  },
479
1225
  });
480
1226
 
481
- pi.registerTool({
1227
+ registerTool({
482
1228
  name: "analyze_pattern",
483
1229
  description:
484
1230
  "K线形态识别 — 检测十字星、锤子线、吞没、启明星、黄昏星、双底、20日突破等12+种经典形态。综合技术面判断用 get_technical_analysis",
@@ -516,7 +1262,7 @@ export default (pi: ExtensionAPI) => {
516
1262
 
517
1263
  // --- Market Tools ---
518
1264
 
519
- pi.registerTool({
1265
+ registerTool({
520
1266
  name: "get_market_indices",
521
1267
  description:
522
1268
  "获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500;JP: 日经225/东证;KR: KOSPI/KOSDAQ;TW: 台湾加权。大盘复盘用 get_market_review 一站式获取",
@@ -540,7 +1286,7 @@ export default (pi: ExtensionAPI) => {
540
1286
  },
541
1287
  });
542
1288
 
543
- pi.registerTool({
1289
+ registerTool({
544
1290
  name: "get_sector_rankings",
545
1291
  description: "获取A股板块涨跌幅排行(含领涨股、涨跌家数等)。board_type=industry(默认)为行业板块,board_type=concept 时为概念板块排行。支持查看涨幅榜/跌幅榜/双向",
546
1292
  parameters: {
@@ -576,7 +1322,7 @@ export default (pi: ExtensionAPI) => {
576
1322
  },
577
1323
  });
578
1324
 
579
- pi.registerTool({
1325
+ registerTool({
580
1326
  name: "get_sector_constituents",
581
1327
  description:
582
1328
  "查询A股板块成分股(正向映射:板块→股票列表)。板块名支持模糊匹配(如「创新药」自动解析到精确板块名),东财行业/概念 + 新浪多源 failover,结果按用户目录缓存7天。仅支持A股;反向查个股所属板块用 resolve_stock_sectors",
@@ -606,7 +1352,7 @@ export default (pi: ExtensionAPI) => {
606
1352
  },
607
1353
  });
608
1354
 
609
- pi.registerTool({
1355
+ registerTool({
610
1356
  name: "resolve_stock_sectors",
611
1357
  description:
612
1358
  "查询个股所属板块(反向映射:个股→板块)。A股返回东财行业 + efinance 概念/板块(雪球行业兜底,需 XUEQIU_TOKEN),港股返回 yfinance GICS 英文 sector/industry 口径。板块级情报(如「创新药回调」)映射到池内个股时调本工具;正向查板块成分股用 get_sector_constituents",
@@ -626,7 +1372,7 @@ export default (pi: ExtensionAPI) => {
626
1372
  },
627
1373
  });
628
1374
 
629
- pi.registerTool({
1375
+ registerTool({
630
1376
  name: "get_stock_info",
631
1377
  description:
632
1378
  "获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,其他市场返回行业/公司简介",
@@ -646,7 +1392,7 @@ export default (pi: ExtensionAPI) => {
646
1392
  },
647
1393
  });
648
1394
 
649
- pi.registerTool({
1395
+ registerTool({
650
1396
  name: "get_chip_distribution",
651
1397
  description:
652
1398
  "获取A股筹码分布数据(获利比例、平均成本、90%/70%成本集中度)。仅支持A股。与 get_capital_flow 配合验证主力行为",
@@ -666,7 +1412,7 @@ export default (pi: ExtensionAPI) => {
666
1412
  },
667
1413
  });
668
1414
 
669
- pi.registerTool({
1415
+ registerTool({
670
1416
  name: "get_market_stats",
671
1417
  description:
672
1418
  "获取A股市场整体统计(涨跌家数、涨停跌停数、平均涨幅、涨跌Top5、总成交额)。用于衡量市场整体情绪与温度",
@@ -680,7 +1426,7 @@ export default (pi: ExtensionAPI) => {
680
1426
  },
681
1427
  });
682
1428
 
683
- pi.registerTool({
1429
+ registerTool({
684
1430
  name: "get_limit_up_pool",
685
1431
  description:
686
1432
  "获取A股涨停池/涨停板复盘——当日涨停个股,含连板数、封板资金、炸板次数、首末次封板时间、所属行业。短线情绪与龙头战法核心数据",
@@ -702,7 +1448,7 @@ export default (pi: ExtensionAPI) => {
702
1448
  },
703
1449
  });
704
1450
 
705
- pi.registerTool({
1451
+ registerTool({
706
1452
  name: "get_dragon_tiger",
707
1453
  description:
708
1454
  "获取A股龙虎榜——上榜个股净买额/买入额/卖出额/上榜原因/解读,可按个股过滤",
@@ -735,7 +1481,7 @@ export default (pi: ExtensionAPI) => {
735
1481
  },
736
1482
  });
737
1483
 
738
- pi.registerTool({
1484
+ registerTool({
739
1485
  name: "get_hot_stocks",
740
1486
  description: "获取A股全市场人气热搜榜(东方财富人气榜)",
741
1487
  parameters: {
@@ -753,7 +1499,7 @@ export default (pi: ExtensionAPI) => {
753
1499
  },
754
1500
  });
755
1501
 
756
- pi.registerTool({
1502
+ registerTool({
757
1503
  name: "get_margin_trading",
758
1504
  description:
759
1505
  "获取A股个股融资融券明细(融资余额/融资买入额/融券余量等,上交所/深交所官方数据按交易所分流),返回最近N个交易日序列(最新在前)。金额单位为元,short_*_shares 单位为股。include_ratio=true追加同日融资买入/成交额百分比(margin_buy_ratio_pct),缺少同日元口径成交额则为null。仅两融标的有数据,非两融标的返回错误",
@@ -778,7 +1524,7 @@ export default (pi: ExtensionAPI) => {
778
1524
  },
779
1525
  });
780
1526
 
781
- pi.registerTool({
1527
+ registerTool({
782
1528
  name: "get_northbound_flow",
783
1529
  description:
784
1530
  "获取北向资金市场级净买入序列(最新在前,单位亿元)。数据口径:东方财富沪深港通历史数据;2024-08-16 起交易所停止披露日度净买额,仅 2024-08 之前历史数据可查(近期小 days 窗口会返回停披错误,加大 days 可取历史)",
@@ -797,7 +1543,7 @@ export default (pi: ExtensionAPI) => {
797
1543
  },
798
1544
  });
799
1545
 
800
- pi.registerTool({
1546
+ registerTool({
801
1547
  name: "get_fundamental_context",
802
1548
  description:
803
1549
  "获取A股基本面上下文(估值 PE/PB/市值 + 营收/净利增速 + ROE/毛利率/净利率 + 分红历史)。用于评估公司质地与长期持有价值",
@@ -819,10 +1565,10 @@ export default (pi: ExtensionAPI) => {
819
1565
 
820
1566
  // --- Screener & Backtest ---
821
1567
 
822
- pi.registerTool({
1568
+ registerTool({
823
1569
  name: "screen_stocks",
824
1570
  description:
825
- "全市场股票筛选(AlphaSift L1 多因子硬筛 + 市场情绪调节)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分,可用 l2 开启质量/成长/动量/波动率/资金流增强。显式筛选条件缺少数据时报error,filters_applied只列实际执行的条件",
1571
+ "全市场股票筛选(AlphaSift L1 多因子硬筛 + 市场情绪调节)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分,可用 l2 开启质量/成长/动量/波动率/资金流增强。显式筛选条件缺少数据时报error,filters_applied只列实际执行的条件。候选factor_coverage列出可用/缺失因子、加权覆盖率和effective_weights;L1与L2均按可用因子归一化后排序,缺失/非有限值不按零分计;L2另返回effective_scores供结合市场系数复算final,按可用因子重归一化,高分不代表数据完整。选股预算按候选数量及采集批次计算,top须为正整数。",
826
1572
  parameters: {
827
1573
  type: "object",
828
1574
  properties: {
@@ -859,10 +1605,59 @@ export default (pi: ExtensionAPI) => {
859
1605
  },
860
1606
  });
861
1607
 
862
- pi.registerTool({
1608
+ registerTool({
1609
+ name: "analyze_trend_strategy",
1610
+ description: "月度右侧趋势策略:直接传同市场A/HK/US股票代码,自动获取日K,输出月度新入/持有/退出与逆波动预算。as_of默认最近已收盘交易日,持仓可选且不保存,不自动下单;跨样本仍not_validated。",
1611
+ parameters: {
1612
+ "type": "object",
1613
+ "properties": {
1614
+ "symbols": {
1615
+ "type": "array",
1616
+ "items": {
1617
+ "type": "string"
1618
+ },
1619
+ "minItems": 1,
1620
+ "maxItems": 100,
1621
+ "description": "同一市场的完整股票池,1..100只;A如600036,HK如0700.HK,US如AAPL"
1622
+ },
1623
+ "as_of": {
1624
+ "type": "string",
1625
+ "description": "可选已收盘截止日期YYYY-MM-DD,默认该市场最近已收盘交易日"
1626
+ },
1627
+ "held_symbols": {
1628
+ "type": "array",
1629
+ "items": {
1630
+ "type": "string"
1631
+ },
1632
+ "description": "可选,as_of时真实持股代码,必须在股票池中;省略代表初始空仓,不保存账户"
1633
+ },
1634
+ "pending_exit_symbols": {
1635
+ "type": "array",
1636
+ "items": {
1637
+ "type": "string"
1638
+ },
1639
+ "description": "可选,真实持股中此前已锁定且未成交的退出代码"
1640
+ },
1641
+ "slots": {
1642
+ "type": "number",
1643
+ "description": "可选固定容量K,默认ceil(N/3),不得小于真实持股数量"
1644
+ }
1645
+ },
1646
+ "required": [
1647
+ "symbols"
1648
+ ],
1649
+ "additionalProperties": false
1650
+ },
1651
+ async execute(_id, params) {
1652
+ return asText(await withJsonInput(params, async (path: string) =>
1653
+ (await py("trend_strategy.py", ["fetch", "--input", path])).stdout));
1654
+ },
1655
+ });
1656
+
1657
+ registerTool({
863
1658
  name: "run_backtest",
864
1659
  description:
865
- "策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标。只想知道单个技术信号的历史胜率用更轻量的 evaluate_signal。period为实际数据期间,requested_period保留请求期间,warnings提示覆盖差异;年化按实际期间计算",
1660
+ "策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标。只想知道单个技术信号的历史胜率用更轻量的 evaluate_signal。period为实际数据期间,requested_period保留请求期间,warnings提示覆盖差异;年化按实际期间计算。默认前日收盘信号、次日开盘成交;YAML simulation.execution=same_close可复现旧假设。execution返回模型、阻止成交次数和未模拟约束;零成交量及带历史限价的一字板不成交。支持 monthly_momentum:月初首根有效日K收盘观察过去period根对数收益,次日开盘;长周期需预热。",
866
1661
  parameters: {
867
1662
  type: "object",
868
1663
  properties: {
@@ -903,7 +1698,7 @@ export default (pi: ExtensionAPI) => {
903
1698
  },
904
1699
  });
905
1700
 
906
- pi.registerTool({
1701
+ registerTool({
907
1702
  name: "evaluate_signal",
908
1703
  description:
909
1704
  "技术信号历史准确率评估 — 回溯历史数据,统计某个技术信号触发后N日的胜率和平均收益。支持9种信号:macd_golden_cross/macd_death_cross/rsi_oversold/rsi_overbought/breakout_20d/breakdown_20d/volume_surge/ma_golden_cross/ma_death_cross。要完整模拟交易过程用 run_backtest",
@@ -956,7 +1751,7 @@ export default (pi: ExtensionAPI) => {
956
1751
 
957
1752
  // --- Name Resolution ---
958
1753
 
959
- pi.registerTool({
1754
+ registerTool({
960
1755
  name: "resolve_stock_name",
961
1756
  description:
962
1757
  "股票名称智能解析 — 输入中文名(贵州茅台)、拼音(guizhou maotai/gzmt)、部分代码,返回匹配的股票代码。仅支持A股。用户给出中文名/拼音/部分代码时先调本工具换成代码再调其他工具",
@@ -987,7 +1782,7 @@ export default (pi: ExtensionAPI) => {
987
1782
 
988
1783
  // --- Trading Calendar ---
989
1784
 
990
- pi.registerTool({
1785
+ registerTool({
991
1786
  name: "check_trading_day",
992
1787
  description:
993
1788
  "查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)、JP(日股)、KR(韩股)、TW(台股)",
@@ -1016,7 +1811,7 @@ export default (pi: ExtensionAPI) => {
1016
1811
  },
1017
1812
  });
1018
1813
 
1019
- pi.registerTool({
1814
+ registerTool({
1020
1815
  name: "get_trading_days",
1021
1816
  description:
1022
1817
  "获取最近/未来N个交易日列表。支持CN/HK/US/JP/KR/TW",
@@ -1056,7 +1851,7 @@ export default (pi: ExtensionAPI) => {
1056
1851
  },
1057
1852
  });
1058
1853
 
1059
- pi.registerTool({
1854
+ registerTool({
1060
1855
  name: "get_trading_phase",
1061
1856
  description:
1062
1857
  "查询某市场当前交易时段(盘前/早盘/午间休市/午盘/交易中/盘后/休市),用于正确解读实时行情的盘中语义。支持CN/HK/US/JP/KR/TW",
@@ -1079,7 +1874,7 @@ export default (pi: ExtensionAPI) => {
1079
1874
 
1080
1875
  // --- Standalone MA Calculator ---
1081
1876
 
1082
- pi.registerTool({
1877
+ registerTool({
1083
1878
  name: "calculate_ma",
1084
1879
  description:
1085
1880
  "独立均线计算器 — 支持任意周期MA(5/10/20/30/60/120/250或自定义)+ 偏离度 + 均线排列 + 金叉死叉检测。只要均线数值或需要30/120/250等非默认周期时用本工具;综合技术面分析用 get_technical_analysis",
@@ -1119,7 +1914,7 @@ export default (pi: ExtensionAPI) => {
1119
1914
 
1120
1915
  // --- Volume-Price Analysis ---
1121
1916
 
1122
- pi.registerTool({
1917
+ registerTool({
1123
1918
  name: "get_volume_analysis",
1124
1919
  description:
1125
1920
  "独立量价分析 — 量价相关性、上涨/下跌日成交量对比、量能趋势、量价模式解读(放量上涨/缩量回调等)。综合技术面判断用 get_technical_analysis,扫当日异动用 detect_anomaly",
@@ -1157,7 +1952,7 @@ export default (pi: ExtensionAPI) => {
1157
1952
 
1158
1953
  // --- Search Intelligence ---
1159
1954
 
1160
- pi.registerTool({
1955
+ registerTool({
1161
1956
  name: "search_stock_news",
1162
1957
  description:
1163
1958
  "多引擎股票新闻搜索(Tavily/Brave/SerpAPI/Bocha/SearXNG)。需配置至少一个搜索源的 Key 或 SearXNG URL。get_news 快讯不够或要按主题搜索时用;深度6维情报用 search_comprehensive_intel",
@@ -1186,7 +1981,7 @@ export default (pi: ExtensionAPI) => {
1186
1981
  },
1187
1982
  });
1188
1983
 
1189
- pi.registerTool({
1984
+ registerTool({
1190
1985
  name: "search_comprehensive_intel",
1191
1986
  description:
1192
1987
  "股票综合情报搜索 — 从6个维度(新闻/公告/行情分析/风险/业绩/行业)搜索综合信息。用于个股的深入研究/全面调研;快速看新闻用 get_news",
@@ -1214,7 +2009,7 @@ export default (pi: ExtensionAPI) => {
1214
2009
  },
1215
2010
  });
1216
2011
 
1217
- pi.registerTool({
2012
+ registerTool({
1218
2013
  name: "get_social_sentiment",
1219
2014
  description:
1220
2015
  "获取股票社交媒体情绪数据。A股:东方财富股吧热度+雪球讨论热度(无需配置);美股/港股:Reddit/X/Polymarket情绪(需 SENTIMENT_API_KEY)。自动按市场选数据源。面向个股维度;全市场热门讨论用 get_trending_sentiment",
@@ -1234,7 +2029,7 @@ export default (pi: ExtensionAPI) => {
1234
2029
  },
1235
2030
  });
1236
2031
 
1237
- pi.registerTool({
2032
+ registerTool({
1238
2033
  name: "get_trending_sentiment",
1239
2034
  description:
1240
2035
  "获取社交媒体热门趋势(Reddit/X/Polymarket热门股票讨论)。适用于发现市场热点;查个股情绪用 get_social_sentiment",
@@ -1248,7 +2043,7 @@ export default (pi: ExtensionAPI) => {
1248
2043
  },
1249
2044
  });
1250
2045
 
1251
- pi.registerTool({
2046
+ registerTool({
1252
2047
  name: "extract_article",
1253
2048
  description:
1254
2049
  "网页文章全文提取 — 输入URL,提取文章标题、正文(最多3000字)、作者、发布日期等。配合 get_news/search_stock_news 的搜索结果做深度阅读",
@@ -1268,7 +2063,7 @@ export default (pi: ExtensionAPI) => {
1268
2063
  },
1269
2064
  });
1270
2065
 
1271
- pi.registerTool({
2066
+ registerTool({
1272
2067
  name: "screen_risk",
1273
2068
  description:
1274
2069
  "A股风险专项筛查 — 检查估值、技术预警、解禁、减持、业绩预警、监管和行业政策,返回风险评级和 veto_buy。新闻搜索命中是待核实线索,不是已证实风险。data_complete和warnings标明覆盖;数据不足时risk_level=unknown,risk_score或veto_buy可为null,不能视为低风险",
@@ -1296,7 +2091,7 @@ export default (pi: ExtensionAPI) => {
1296
2091
  },
1297
2092
  });
1298
2093
 
1299
- pi.registerTool({
2094
+ registerTool({
1300
2095
  name: "detect_market_regime",
1301
2096
  description:
1302
2097
  "市场状态检测 — 分析大盘指数判断当前市场阶段(上涨趋势/下跌趋势/横盘震荡/高波动/板块热点),并推荐适合的分析策略",
@@ -1317,10 +2112,10 @@ export default (pi: ExtensionAPI) => {
1317
2112
  },
1318
2113
  });
1319
2114
 
1320
- pi.registerTool({
2115
+ registerTool({
1321
2116
  name: "get_market_review",
1322
2117
  description:
1323
- "大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议。复盘类需求的首选,无需再分别调指数/统计/板块工具",
2118
+ "大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议。复盘类需求的首选,无需再分别调指数/统计/板块工具。数据不足时温度score及strategy_stance为null,信号unknown;warnings/data_quality说明限制",
1324
2119
  parameters: {
1325
2120
  type: "object",
1326
2121
  properties: {
@@ -1338,7 +2133,7 @@ export default (pi: ExtensionAPI) => {
1338
2133
  },
1339
2134
  });
1340
2135
 
1341
- pi.registerTool({
2136
+ registerTool({
1342
2137
  name: "run_watchlist_analysis",
1343
2138
  description:
1344
2139
  "批量自选股分析 — 对多只股票并行采集行情/技术/资金/风险等数据,返回汇总结果。适用于每日定时分析自选股列表",
@@ -1367,7 +2162,7 @@ export default (pi: ExtensionAPI) => {
1367
2162
  },
1368
2163
  });
1369
2164
 
1370
- pi.registerTool({
2165
+ registerTool({
1371
2166
  name: "detect_anomaly",
1372
2167
  description:
1373
2168
  "异常/事件检测 — 一键扫描股票当前所有异动信号(MACD金叉死叉、RSI超买超卖、20日突破、放量异动、涨跌停、布林突破、KDJ极值、资金异动等),返回结构化异常列表。当日异动归因的首选;综合技术面判断用 get_technical_analysis",
@@ -1389,7 +2184,7 @@ export default (pi: ExtensionAPI) => {
1389
2184
 
1390
2185
  // --- Diagnostics & Capabilities ---
1391
2186
 
1392
- pi.registerTool({
2187
+ registerTool({
1393
2188
  name: "diagnose_data_sources",
1394
2189
  description:
1395
2190
  "数据源诊断 — 检查当前环境各数据 provider 的包与凭据就绪情况(不探测网络可达性),输出每个市场的可用链路、缺失 env、warnings。工具拿不到数据或报错时调用排查",
@@ -1409,7 +2204,7 @@ export default (pi: ExtensionAPI) => {
1409
2204
  },
1410
2205
  });
1411
2206
 
1412
- pi.registerTool({
2207
+ registerTool({
1413
2208
  name: "get_market_capabilities",
1414
2209
  description:
1415
2210
  "市场能力边界 — 返回指定市场支持/不支持的工具列表。不确定某市场能否用某工具(如港股的筹码分布、美股的资金流)时先调本工具,避免调用不支持的工具后编造数据",
@@ -1431,10 +2226,10 @@ export default (pi: ExtensionAPI) => {
1431
2226
 
1432
2227
  // --- Report Rendering ---
1433
2228
 
1434
- pi.registerTool({
2229
+ registerTool({
1435
2230
  name: "render_stock_report",
1436
2231
  description:
1437
- "股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full。全部分析完成后的最后一步调用。仅渲染,不保存不推送",
2232
+ "股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full。全部分析完成后的最后一步调用。仅渲染,不保存不推送。report可包含evidence(path/label/value/source/as_of)与data_quality(flags/limitations),brief/full均展示证据和限制。",
1438
2233
  parameters: {
1439
2234
  type: "object",
1440
2235
  properties: {
@@ -1463,7 +2258,7 @@ export default (pi: ExtensionAPI) => {
1463
2258
  },
1464
2259
  });
1465
2260
 
1466
- pi.registerTool({
2261
+ registerTool({
1467
2262
  name: "render_market_report",
1468
2263
  description:
1469
2264
  "大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json 为准。save=true 时把报告对象追加归档到本地 JSONL(默认不保存不推送),纵向对比用 get_review_history",
@@ -1487,7 +2282,7 @@ export default (pi: ExtensionAPI) => {
1487
2282
  },
1488
2283
  });
1489
2284
 
1490
- pi.registerTool({
2285
+ registerTool({
1491
2286
  name: "get_review_history",
1492
2287
  description:
1493
2288
  "复盘归档历史 — 读取本地 JSONL 归档的最近 N 条市场复盘(最新在前),用于纵向对比(温度/姿态/主线变化)。归档由 render_market_report 的 save=true 写入,空存档返回空列表",
@@ -1505,10 +2300,10 @@ export default (pi: ExtensionAPI) => {
1505
2300
 
1506
2301
  // --- Watchlist / Position / Alert Context ---
1507
2302
 
1508
- pi.registerTool({
2303
+ registerTool({
1509
2304
  name: "build_watchlist_context",
1510
2305
  description:
1511
- "自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析",
2306
+ "自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析。异动检查失败时anomaly_status=unavailable、anomaly_count=null,保留anomaly_error/warnings;汇总计入partial",
1512
2307
  parameters: {
1513
2308
  type: "object",
1514
2309
  properties: {
@@ -1533,7 +2328,7 @@ export default (pi: ExtensionAPI) => {
1533
2328
  },
1534
2329
  });
1535
2330
 
1536
- pi.registerTool({
2331
+ registerTool({
1537
2332
  name: "analyze_position_context",
1538
2333
  description:
1539
2334
  "持仓上下文分析 — 输入成本/仓位/止损止盈,结合现价和技术位输出浮盈亏、离止损距离、风险级别、操作建议。无状态、不存账户",
@@ -1563,7 +2358,7 @@ export default (pi: ExtensionAPI) => {
1563
2358
  },
1564
2359
  });
1565
2360
 
1566
- pi.registerTool({
2361
+ registerTool({
1567
2362
  name: "check_alert_rules",
1568
2363
  description:
1569
2364
  "无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型:price_below/price_above/change_pct_above/change_pct_below/volume_ratio_above/anomaly/risk_veto/risk_level_at_least。不做调度不存历史。依赖数据不可用时evaluated条目含error,meta.warnings提示缺失,triggered=false不代表检查成功",
@@ -1592,7 +2387,7 @@ export default (pi: ExtensionAPI) => {
1592
2387
  },
1593
2388
  });
1594
2389
 
1595
- pi.registerTool({
2390
+ registerTool({
1596
2391
  name: "record_signal",
1597
2392
  description:
1598
2393
  "记录一条 AI 分析建议信号(方向/入场价/目标价/止损价/持有期限),供后续胜率评估。信号持久化在本地 JSONL($STOCK_SIGNAL_STORE 或 ~/.stock-analysis/signals.jsonl),宿主 Agent 自行决定何时 record/evaluate",
@@ -1632,10 +2427,10 @@ export default (pi: ExtensionAPI) => {
1632
2427
  },
1633
2428
  });
1634
2429
 
1635
- pi.registerTool({
2430
+ registerTool({
1636
2431
  name: "evaluate_signals",
1637
2432
  description:
1638
- "评估到期信号:拉取记录日之后的日K,判定 target_hit/stop_hit/timeout 并计算收益,回写存储。记录建议用 record_signal,胜率复盘用 get_signal_summary。历史K线未覆盖记录日时skipped_no_data并保持未结算,不能用较新行情代替",
2433
+ "评估到期信号:拉取记录日之后的日K,判定 target_hit/stop_hit/timeout 并计算收益,回写存储。记录建议用 record_signal,胜率复盘用 get_signal_summary。历史K线未覆盖记录日时skipped_no_data并保持未结算,不能用较新行情代替。原始信号价与复权K线须有可核实的adjustment_factor,缺失则skipped_price_basis保持未结算。CLI预算300秒,截止前返回并保存已完成结果;complete/deferred/warnings说明未处理记录,下次可重试",
1639
2434
  parameters: {
1640
2435
  type: "object",
1641
2436
  properties: {
@@ -1651,10 +2446,10 @@ export default (pi: ExtensionAPI) => {
1651
2446
  },
1652
2447
  });
1653
2448
 
1654
- pi.registerTool({
2449
+ registerTool({
1655
2450
  name: "get_signal_summary",
1656
2451
  description:
1657
- "信号胜率汇总(可按 source/symbol/status 过滤):胜率、平均收益、结果分布与明细",
2452
+ "信号胜率汇总(可按 source/symbol/status 过滤):胜率、平均收益、结果分布与明细。by_source附avg_return_pct、return_samples和sample_warning;仅观察性复盘,样本少不能认定策略有效。",
1658
2453
  parameters: {
1659
2454
  type: "object",
1660
2455
  properties: {
@@ -1679,7 +2474,7 @@ export default (pi: ExtensionAPI) => {
1679
2474
  },
1680
2475
  });
1681
2476
 
1682
- pi.registerTool({
2477
+ registerTool({
1683
2478
  name: "parse_stock_list",
1684
2479
  description:
1685
2480
  "自选股/文本导入解析 — 从自然语言、CSV、Markdown 表格提取股票,自动识别 A 股 6 位代码、港股 xxxxx.HK、美股 ticker、日股 xxxx.T、韩股 xxxxxx.KS/KQ、台股 xxxx.TW,并调用 name_resolver 处理中文股票名",