stock-analysis-plugin 0.2.11 → 0.2.13

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 (54) hide show
  1. package/README.md +234 -382
  2. package/docs/mcp.md +60 -0
  3. package/hermes/__init__.py +35 -0
  4. package/hermes/plugin.yaml +132 -0
  5. package/hermes/schemas.py +6 -0
  6. package/hermes/tools.py +647 -0
  7. package/mcp_host/__init__.py +1 -0
  8. package/mcp_host/__main__.py +3 -0
  9. package/mcp_host/server.py +222 -0
  10. package/package.json +7 -1
  11. package/pi/index.ts +52 -2906
  12. package/scripts/cli-json.mjs +23 -0
  13. package/scripts/exec-process.mjs +89 -0
  14. package/scripts/setup-python.mjs +37 -4
  15. package/scripts/tool-calls.mjs +493 -0
  16. package/skills/bull-trend/SKILL.md +2 -2
  17. package/skills/bull-trend/references/fat-tails.md +76 -3
  18. package/skills/bull-trend/scripts/tail_analysis.py +92 -3
  19. package/skills/event-driven/SKILL.md +2 -2
  20. package/skills/growth-quality/SKILL.md +1 -1
  21. package/skills/market-review/SKILL.md +1 -0
  22. package/skills/stock-analysis/SKILL.md +12 -7
  23. package/skills/stock-analysis/references/stateless-analysis.md +9 -1
  24. package/skills/stock-screener/SKILL.md +1 -1
  25. package/skills/strategy-backtest/SKILL.md +1 -1
  26. package/tools/_cache.py +13 -0
  27. package/tools/_subproc.py +46 -0
  28. package/tools/alert_rules.py +2 -2
  29. package/tools/backtest.py +3 -3
  30. package/tools/capabilities.py +33 -9
  31. package/tools/cli_budgets.json +1 -0
  32. package/tools/credit_data.py +293 -0
  33. package/tools/diagnostics.py +3 -4
  34. package/tools/gather.py +2 -6
  35. package/tools/import_parser.py +3 -4
  36. package/tools/lixinger.py +119 -27
  37. package/tools/market_regime.py +5 -2
  38. package/tools/market_review.py +5 -6
  39. package/tools/name_resolver.py +45 -33
  40. package/tools/report_renderer.py +3 -3
  41. package/tools/requirements.txt +5 -4
  42. package/tools/risk_screening.py +3 -2
  43. package/tools/screener.py +41 -30
  44. package/tools/search_intel.py +79 -10
  45. package/tools/sec_edgar.py +268 -1
  46. package/tools/sec_holders.py +6 -0
  47. package/tools/signal_tracker.py +5 -5
  48. package/tools/stateless_analysis.py +132 -19
  49. package/tools/stock_data.py +1020 -817
  50. package/tools/tiaa_disclosures.py +4 -0
  51. package/tools/tool_schemas.json +2734 -0
  52. package/tools/trading_calendar.py +65 -30
  53. package/tools/value_data.py +423 -175
  54. package/tools/watchlist.py +43 -5
package/pi/index.ts CHANGED
@@ -1,13 +1,47 @@
1
- import { withJsonInput } from "../scripts/json-input.mjs";
2
1
  import type { ExtensionAPI } from "pi-agent";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { existsSync, readdirSync } from "node:fs";
3
4
  import { fileURLToPath } from "url";
4
5
 
6
+ import { cliJson, failureMessage, withoutNulls } from "../scripts/cli-json.mjs";
5
7
  import { commandTimeout } from "../scripts/cli-timeout.mjs";
8
+ import { execFileTree } from "../scripts/exec-process.mjs";
9
+ import { callTool, TOOL_SCHEMAS } from "../scripts/tool-calls.mjs";
6
10
  import { resolvePython } from "../scripts/venv-python.mjs";
7
11
 
12
+ type ProcessResult = { stdout: string; stderr?: string; code: number | string; killed: boolean; truncated?: boolean };
13
+ type ProcessExecutor = (python: string, args: string[], options: { timeout: number; signal?: AbortSignal }) => Promise<ProcessResult>;
14
+
15
+ export const __defaultProcessExecutor: ProcessExecutor = async (python, args, { timeout, signal }) => {
16
+ try {
17
+ const stdout = await execFileTree(python, args, { timeoutMs: timeout, signal });
18
+ return { stdout, stderr: "", code: 0, killed: false, truncated: false };
19
+ } catch (error) {
20
+ const failed = error as { stdout?: string; code?: unknown; killed?: boolean; name?: string };
21
+ return {
22
+ stdout: failed.stdout ?? "",
23
+ stderr: "",
24
+ code: failed.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" ? failed.code : typeof failed.code === "number" ? failed.code : 1,
25
+ killed: failed.killed ?? failed.name === "AbortError",
26
+ truncated: failed.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER",
27
+ };
28
+ }
29
+ };
30
+ let processExecutor = __defaultProcessExecutor;
31
+ export function __setProcessExecutor(fn: ProcessExecutor) {
32
+ processExecutor = fn;
33
+ }
34
+
8
35
  export default (pi: ExtensionAPI) => {
9
36
  const tools: Parameters<ExtensionAPI["registerTool"]>[0][] = [];
10
- const registerTool: ExtensionAPI["registerTool"] = (tool) => {
37
+ // Pi passes the call's AbortSignal as execute's third argument; py() forwards it to the process executor.
38
+ const callSignal = new AsyncLocalStorage<AbortSignal | undefined>();
39
+ const registerTool: ExtensionAPI["registerTool"] = (definition) => {
40
+ const tool = {
41
+ ...definition,
42
+ execute: (id: string, params: unknown, ...rest: unknown[]) =>
43
+ callSignal.run(rest[0] instanceof AbortSignal ? rest[0] : undefined, () => definition.execute(id, withoutNulls(params), ...rest)),
44
+ };
11
45
  tools.push(tool);
12
46
  pi.registerTool({ ...tool, defaultActive: false });
13
47
  };
@@ -55,2920 +89,32 @@ export default (pi: ExtensionAPI) => {
55
89
  const toolsDir = `${baseDir}/tools`;
56
90
  const python = resolvePython(baseDir);
57
91
  const py = async (script: string, args: string[]) => {
58
- const result = await pi.exec(python, [`${toolsDir}/${script}`, ...args], { timeout: commandTimeout(script, args) });
59
- if (result.killed || !result.stdout.trim()) {
60
- return {...result, stdout: JSON.stringify({error: result.killed ? "Python command timed out" : "Python command returned no JSON"})};
61
- }
62
- return result;
92
+ const result = await processExecutor(python, [`${toolsDir}/${script}`, ...args], { timeout: commandTimeout(script, args), signal: callSignal.getStore() });
93
+ const failure = result.killed || result.code !== 0 ? failureMessage(result) : undefined;
94
+ return { ...result, stdout: cliJson(result.stdout, failure) };
63
95
  };
64
96
  const asText = (text: string) => ({
65
97
  content: [{ type: "text" as const, text }],
66
98
  details: {},
67
99
  });
68
100
 
69
- registerTool({
70
- name: "compare_stocks",
71
- description: "无状态同行指标比较:先用现有财务/行情工具取数,再传companies;仅相同unit/basis/period可排序,缺失不填零,不生成买卖综合分。",
72
- parameters: {
73
- "type": "object",
74
- "properties": {
75
- "companies": {
76
- "type": "array",
77
- "items": {
78
- "type": "object",
79
- "properties": {
80
- "symbol": {
81
- "type": "string",
82
- "description": "唯一股票代码"
83
- },
84
- "period": {
85
- "type": "string",
86
- "description": "统一可比期间;财务用报告期,估值用估值日"
87
- },
88
- "metrics": {
89
- "type": "array",
90
- "items": {
91
- "type": "object",
92
- "properties": {
93
- "name": {
94
- "type": "string",
95
- "description": "指标名,如pe/roe/net_income"
96
- },
97
- "value": {
98
- "anyOf": [
99
- {
100
- "type": "number"
101
- },
102
- {
103
- "type": "null"
104
- }
105
- ],
106
- "description": "有限数值;缺失为null"
107
- },
108
- "unit": {
109
- "type": "string",
110
- "description": "精确单位,如multiple/percent/fraction/CNY/USD"
111
- },
112
- "basis": {
113
- "type": "string",
114
- "description": "口径,如TTM/annual/consolidated;区分累计与单季"
115
- },
116
- "source": {
117
- "type": "string",
118
- "description": "原始证据URL或字段路径"
119
- }
120
- },
121
- "required": [
122
- "name",
123
- "value",
124
- "unit",
125
- "basis"
126
- ],
127
- "additionalProperties": false
128
- },
129
- "description": "结构化指标,单位、口径明确,缺失不填零"
130
- }
131
- },
132
- "required": [
133
- "symbol",
134
- "period",
135
- "metrics"
136
- ],
137
- "additionalProperties": false
138
- },
139
- "description": "2..30家公司,调用方确认可比性"
140
- }
141
- },
142
- "required": [
143
- "companies"
144
- ],
145
- "additionalProperties": false
146
- },
147
- async execute(_id, params) {
148
- return asText(await withJsonInput(params, async (path: string) =>
149
- (await py("stateless_analysis.py", ["peers", "--input", path])).stdout));
150
- },
151
- });
152
-
153
- registerTool({
154
- name: "analyze_disclosure_changes",
155
- description: "无状态公告财报比较:传新旧正文及指标,返回变更行号、来源与财务变化;负/零基数增长率为null。不下载PDF、不代替经济解读。",
156
- parameters: {
157
- "type": "object",
158
- "properties": {
159
- "previous": {
160
- "type": "object",
161
- "properties": {
162
- "text": {
163
- "type": "string",
164
- "description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"
165
- },
166
- "source": {
167
- "type": "string",
168
- "description": "原文URL或文档标识"
169
- },
170
- "period": {
171
- "type": "string",
172
- "description": "报告期,如2025年度"
173
- },
174
- "metrics": {
175
- "type": "array",
176
- "items": {
177
- "type": "object",
178
- "properties": {
179
- "name": {
180
- "type": "string",
181
- "description": "指标名,如pe/roe/net_income"
182
- },
183
- "value": {
184
- "anyOf": [
185
- {
186
- "type": "number"
187
- },
188
- {
189
- "type": "null"
190
- }
191
- ],
192
- "description": "有限数值;缺失为null"
193
- },
194
- "unit": {
195
- "type": "string",
196
- "description": "精确单位,如multiple/percent/fraction/CNY/USD"
197
- },
198
- "basis": {
199
- "type": "string",
200
- "description": "口径,如TTM/annual/consolidated;区分累计与单季"
201
- },
202
- "source": {
203
- "type": "string",
204
- "description": "原始证据URL或字段路径"
205
- }
206
- },
207
- "required": [
208
- "name",
209
- "value",
210
- "unit",
211
- "basis"
212
- ],
213
- "additionalProperties": false
214
- },
215
- "description": "结构化指标,单位、口径明确,缺失不填零"
216
- }
217
- },
218
- "required": [
219
- "text",
220
- "source",
221
- "period",
222
- "metrics"
223
- ],
224
- "additionalProperties": false
225
- },
226
- "current": {
227
- "type": "object",
228
- "properties": {
229
- "text": {
230
- "type": "string",
231
- "description": "已核实正文,最多200000字符;保留换行,PDF需宿主提取"
232
- },
233
- "source": {
234
- "type": "string",
235
- "description": "原文URL或文档标识"
236
- },
237
- "period": {
238
- "type": "string",
239
- "description": "报告期,如2025年度"
240
- },
241
- "metrics": {
242
- "type": "array",
243
- "items": {
244
- "type": "object",
245
- "properties": {
246
- "name": {
247
- "type": "string",
248
- "description": "指标名,如pe/roe/net_income"
249
- },
250
- "value": {
251
- "anyOf": [
252
- {
253
- "type": "number"
254
- },
255
- {
256
- "type": "null"
257
- }
258
- ],
259
- "description": "有限数值;缺失为null"
260
- },
261
- "unit": {
262
- "type": "string",
263
- "description": "精确单位,如multiple/percent/fraction/CNY/USD"
264
- },
265
- "basis": {
266
- "type": "string",
267
- "description": "口径,如TTM/annual/consolidated;区分累计与单季"
268
- },
269
- "source": {
270
- "type": "string",
271
- "description": "原始证据URL或字段路径"
272
- }
273
- },
274
- "required": [
275
- "name",
276
- "value",
277
- "unit",
278
- "basis"
279
- ],
280
- "additionalProperties": false
281
- },
282
- "description": "结构化指标,单位、口径明确,缺失不填零"
283
- }
284
- },
285
- "required": [
286
- "text",
287
- "source",
288
- "period",
289
- "metrics"
290
- ],
291
- "additionalProperties": false
292
- },
293
- "max_changes": {
294
- "type": "number",
295
- "description": "变化上限1..100,默认30"
296
- }
297
- },
298
- "required": [
299
- "previous",
300
- "current"
301
- ],
302
- "additionalProperties": false
303
- },
304
- async execute(_id, params) {
305
- return asText(await withJsonInput(params, async (path: string) =>
306
- (await py("stateless_analysis.py", ["disclosure", "--input", path])).stdout));
307
- },
308
- });
309
-
310
- registerTool({
311
- name: "analyze_portfolio_risk",
312
- description: "无状态现货多头组合风险与压力测试:输入持仓、基准币种现金与汇率,返回集中度、币种/行业敞口、价格盈亏、止损情景及可选市场/行业/个股/汇率冲击损益。缺汇率报错;不保存账户。",
313
- parameters: {
314
- "type": "object",
315
- "properties": {
316
- "positions": {
317
- "type": "array",
318
- "items": {
319
- "type": "object",
320
- "properties": {
321
- "symbol": {
322
- "type": "string",
323
- "description": "唯一代码,重复持仓先汇总"
324
- },
325
- "quantity": {
326
- "type": "number",
327
- "description": "正持仓数量"
328
- },
329
- "price": {
330
- "type": "number",
331
- "description": "正现价"
332
- },
333
- "currency": {
334
- "type": "string",
335
- "description": "持仓币种,如CNY/USD/HKD"
336
- },
337
- "cost": {
338
- "type": "number",
339
- "description": "同币种正成本价,可选"
340
- },
341
- "stop_price": {
342
- "type": "number",
343
- "description": "同币种正止损价,可选"
344
- },
345
- "sector": {
346
- "type": "string",
347
- "description": "统一行业分类,可选"
348
- },
349
- "as_of": {
350
- "type": "string",
351
- "description": "实际估值时点,建议ISO8601"
352
- }
353
- },
354
- "required": [
355
- "symbol",
356
- "quantity",
357
- "price",
358
- "currency"
359
- ],
360
- "additionalProperties": false
361
- },
362
- "description": "1..100个现货多头持仓"
363
- },
364
- "base_currency": {
365
- "type": "string",
366
- "description": "基准币种"
367
- },
368
- "cash": {
369
- "type": "number",
370
- "description": "基准币种现金,非负"
371
- },
372
- "fx_rates": {
373
- "type": "array",
374
- "items": {
375
- "type": "object",
376
- "properties": {
377
- "currency": {
378
- "type": "string",
379
- "description": "唯一非基准币种"
380
- },
381
- "rate": {
382
- "type": "number",
383
- "description": "一单位该币种对应多少基准币种,正数"
384
- }
385
- },
386
- "required": [
387
- "currency",
388
- "rate"
389
- ],
390
- "additionalProperties": false
391
- },
392
- "description": "显式现价汇率;基准币种隐含1,不得重复"
393
- },
394
- "histories": {
395
- "type": "array",
396
- "items": {
397
- "type": "object",
398
- "properties": {
399
- "symbol": {
400
- "type": "string",
401
- "description": "对应唯一持仓股票"
402
- },
403
- "prices": {
404
- "type": "array",
405
- "items": {
406
- "type": "object",
407
- "properties": {
408
- "date": {
409
- "type": "string",
410
- "description": "YYYY-MM-DD,唯一日期"
411
- },
412
- "close": {
413
- "type": "number",
414
- "description": "正有限收盘价"
415
- }
416
- },
417
- "required": [
418
- "date",
419
- "close"
420
- ],
421
- "additionalProperties": false
422
- },
423
- "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
424
- }
425
- },
426
- "required": [
427
- "symbol",
428
- "prices"
429
- ],
430
- "additionalProperties": false
431
- },
432
- "description": "可选历史,共同日期本币价格收益相关性,不计汇率"
433
- },
434
- "stress_scenarios": {
435
- "type": "array",
436
- "items": {
437
- "type": "object",
438
- "properties": {
439
- "name": {
440
- "type": "string",
441
- "description": "情景名称"
442
- },
443
- "market_shock": {
444
- "type": "number",
445
- "description": "全市场资产价格冲击比例,如-0.1"
446
- },
447
- "sector_shocks": {
448
- "type": "array",
449
- "items": {
450
- "type": "object",
451
- "properties": {
452
- "sector": {
453
- "type": "string",
454
- "description": "与持仓一致的行业名称"
455
- },
456
- "shock": {
457
- "type": "number",
458
- "description": "行业价格冲击比例"
459
- }
460
- },
461
- "required": ["sector", "shock"],
462
- "additionalProperties": false
463
- },
464
- "description": "可选行业冲击"
465
- },
466
- "symbol_shocks": {
467
- "type": "array",
468
- "items": {
469
- "type": "object",
470
- "properties": {
471
- "symbol": {
472
- "type": "string",
473
- "description": "持仓标的代码"
474
- },
475
- "shock": {
476
- "type": "number",
477
- "description": "标的价格冲击比例"
478
- }
479
- },
480
- "required": ["symbol", "shock"],
481
- "additionalProperties": false
482
- },
483
- "description": "可选个股冲击"
484
- },
485
- "currency_shocks": {
486
- "type": "array",
487
- "items": {
488
- "type": "object",
489
- "properties": {
490
- "currency": {
491
- "type": "string",
492
- "description": "持仓中的非基准币种;基准币种不可相对自身冲击"
493
- },
494
- "shock": {
495
- "type": "number",
496
- "description": "相对基准币种的汇率冲击比例"
497
- }
498
- },
499
- "required": ["currency", "shock"],
500
- "additionalProperties": false
501
- },
502
- "description": "可选汇率冲击"
503
- }
504
- },
505
- "required": ["name"],
506
- "additionalProperties": false
507
- },
508
- "description": "可选压力情景;所有冲击均为比例,由共享核心计算"
509
- }
510
- },
511
- "required": [
512
- "positions",
513
- "base_currency",
514
- "cash"
515
- ],
516
- "additionalProperties": false
517
- },
518
- async execute(_id, params) {
519
- return asText(await withJsonInput(params, async (path: string) =>
520
- (await py("stateless_analysis.py", ["portfolio", "--input", path])).stdout));
521
- },
522
- });
523
-
524
- registerTool({
525
- name: "plan_portfolio_rebalance",
526
- description: "无状态组合调仓计划:按当前持仓、目标权重、现金、汇率、整手、费用和换手约束生成先卖后买清单;不保存账户或提交订单。",
527
- parameters: {
528
- "type": "object",
529
- "properties": {
530
- "base_currency": {
531
- "type": "string",
532
- "description": "基准币种"
533
- },
534
- "cash": {
535
- "type": "number",
536
- "description": "基准币种现金,非负"
537
- },
538
- "positions": {
539
- "type": "array",
540
- "items": {
541
- "type": "object",
542
- "properties": {
543
- "symbol": {
544
- "type": "string",
545
- "description": "唯一代码,重复持仓先汇总"
546
- },
547
- "quantity": {
548
- "type": "number",
549
- "description": "正持仓数量"
550
- },
551
- "price": {
552
- "type": "number",
553
- "description": "正现价"
554
- },
555
- "currency": {
556
- "type": "string",
557
- "description": "持仓币种,如CNY/USD/HKD"
558
- },
559
- "cost": {
560
- "type": "number",
561
- "description": "同币种正成本价,可选;调仓计算不使用"
562
- },
563
- "stop_price": {
564
- "type": "number",
565
- "description": "同币种正止损价,可选;调仓计算不使用"
566
- },
567
- "sector": {
568
- "type": "string",
569
- "description": "统一行业分类,可选"
570
- },
571
- "as_of": {
572
- "type": "string",
573
- "description": "实际估值时点,建议ISO8601"
574
- }
575
- },
576
- "required": [
577
- "symbol",
578
- "quantity",
579
- "price",
580
- "currency"
581
- ],
582
- "additionalProperties": false
583
- },
584
- "description": "0..100个现货多头持仓,空数组表示纯现金建仓"
585
- },
586
- "targets": {
587
- "type": "array",
588
- "items": {
589
- "type": "object",
590
- "properties": {
591
- "symbol": {
592
- "type": "string",
593
- "description": "目标标的代码"
594
- },
595
- "weight": {
596
- "type": "number",
597
- "description": "目标权重;大于0时lot_size必填"
598
- },
599
- "price": {
600
- "type": "number",
601
- "description": "正目标价格;当前未持有的新标的必填"
602
- },
603
- "currency": {
604
- "type": "string",
605
- "description": "目标币种;当前未持有的新标的必填"
606
- },
607
- "sector": {
608
- "type": "string",
609
- "description": "统一行业分类,可选"
610
- },
611
- "as_of": {
612
- "type": "string",
613
- "description": "实际估值时点,建议ISO8601"
614
- },
615
- "lot_size": {
616
- "type": "number",
617
- "description": "正整数交易单位;weight>0时必填"
618
- }
619
- },
620
- "required": ["symbol", "weight"],
621
- "additionalProperties": false
622
- },
623
- "description": "1..100个目标;新标的price/currency必填"
624
- },
625
- "fx_rates": {
626
- "type": "array",
627
- "items": {
628
- "type": "object",
629
- "properties": {
630
- "currency": {
631
- "type": "string",
632
- "description": "唯一非基准币种"
633
- },
634
- "rate": {
635
- "type": "number",
636
- "description": "一单位该币种对应多少基准币种,正数"
637
- }
638
- },
639
- "required": [
640
- "currency",
641
- "rate"
642
- ],
643
- "additionalProperties": false
644
- },
645
- "description": "显式现价汇率;基准币种隐含1,不得重复"
646
- },
647
- "fee_rate": {
648
- "type": "number",
649
- "description": "每边比例费用0..0.1,默认0;不含未提供税费/最低收费"
650
- },
651
- "slippage_rate": {
652
- "type": "number",
653
- "description": "每边滑点0..0.1,默认0"
654
- },
655
- "max_turnover_fraction": {
656
- "type": "number",
657
- "description": "非负最大总换手,按买卖参考金额合计/初始权益;默认不限制,可大于1"
658
- }
659
- },
660
- "required": [
661
- "base_currency",
662
- "cash",
663
- "positions",
664
- "targets"
665
- ],
666
- "additionalProperties": false
667
- },
668
- async execute(_id, params) {
669
- return asText(await withJsonInput(params, async (path: string) =>
670
- (await py("stateless_analysis.py", ["rebalance", "--input", path])).stdout));
671
- },
672
- });
673
-
674
- registerTool({
675
- name: "calculate_position_size",
676
- description: "无状态多头仓位预算:同币种金额,按现金/风险预算/最大仓位/交易单位取最小数量,双边费用和滑点参与止损情景;不执行交易。",
677
- parameters: {
678
- "type": "object",
679
- "properties": {
680
- "equity": {
681
- "type": "number",
682
- "description": "总权益,正数"
683
- },
684
- "cash": {
685
- "type": "number",
686
- "description": "可用现金,0..equity"
687
- },
688
- "entry_price": {
689
- "type": "number",
690
- "description": "计划入场价,正数"
691
- },
692
- "stop_price": {
693
- "type": "number",
694
- "description": "正止损价,低于入场价"
695
- },
696
- "risk_fraction": {
697
- "type": "number",
698
- "description": "单笔风险占权益比例0..1,如0.01"
699
- },
700
- "lot_size": {
701
- "type": "number",
702
- "description": "正整数交易单位,用户确认,不猜港股每手数量"
703
- },
704
- "max_position_fraction": {
705
- "type": "number",
706
- "description": "本次买入最大资金占比0..1,默认1;已有同股持仓先扣减额度"
707
- },
708
- "fee_rate": {
709
- "type": "number",
710
- "description": "每边比例费用0..0.1,默认0;不含未提供税费/最低收费"
711
- },
712
- "slippage_rate": {
713
- "type": "number",
714
- "description": "每边滑点0..0.1,默认0"
715
- }
101
+ for (const { name, description, parameters } of TOOL_SCHEMAS) {
102
+ registerTool({
103
+ name,
104
+ description,
105
+ parameters,
106
+ async execute(_id, params) {
107
+ return asText(await callTool(name, params, async (script: string, args: string[]) => (await py(script, args)).stdout));
716
108
  },
717
- "required": [
718
- "equity",
719
- "cash",
720
- "entry_price",
721
- "stop_price",
722
- "risk_fraction",
723
- "lot_size"
724
- ],
725
- "additionalProperties": false
726
- },
727
- async execute(_id, params) {
728
- return asText(await withJsonInput(params, async (path: string) =>
729
- (await py("stateless_analysis.py", ["position_size", "--input", path])).stdout));
730
- },
731
- });
732
-
733
- registerTool({
734
- name: "analyze_event_study",
735
- description: "无状态事件研究:提供同市场股票及基准完整价格、事件日期;事件前一交易日收盘为基点,计算交易日窗口收益差。缺窗口/基准为null,标注重叠,不推断因果。",
736
- parameters: {
737
- "type": "object",
738
- "properties": {
739
- "prices": {
740
- "type": "array",
741
- "items": {
742
- "type": "object",
743
- "properties": {
744
- "date": {
745
- "type": "string",
746
- "description": "YYYY-MM-DD,唯一日期"
747
- },
748
- "close": {
749
- "type": "number",
750
- "description": "正有限收盘价"
751
- }
752
- },
753
- "required": [
754
- "date",
755
- "close"
756
- ],
757
- "additionalProperties": false
758
- },
759
- "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
760
- },
761
- "benchmark_prices": {
762
- "type": "array",
763
- "items": {
764
- "type": "object",
765
- "properties": {
766
- "date": {
767
- "type": "string",
768
- "description": "YYYY-MM-DD,唯一日期"
769
- },
770
- "close": {
771
- "type": "number",
772
- "description": "正有限收盘价"
773
- }
774
- },
775
- "required": [
776
- "date",
777
- "close"
778
- ],
779
- "additionalProperties": false
780
- },
781
- "description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"
782
- },
783
- "event_dates": {
784
- "type": "array",
785
- "items": {
786
- "type": "string",
787
- "description": "YYYY-MM-DD,盘后公告传下一交易日"
788
- },
789
- "description": "1..100个唯一事件日"
790
- },
791
- "price_basis": {
792
- "type": "string",
793
- "description": "仅显式prices模式必需;代码模式报告实际提供方标记,缺失为unknown,须核实"
794
- },
795
- "horizons": {
796
- "type": "array",
797
- "items": {
798
- "type": "number",
799
- "description": "0=事件日,1=下一交易日;整数0..250"
800
- },
801
- "description": "1..20个窗口,默认0/1/5/10/20"
802
- },
803
- "start_date": {
804
- "type": "string",
805
- "description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"
806
- },
807
- "end_date": {
808
- "type": "string",
809
- "description": "代码模式必需,YYYY-MM-DD,晚于start_date"
810
- },
811
- "symbol": {
812
- "type": "string",
813
- "description": "股票代码;与benchmark/start_date/end_date一起直接取数,和prices模式互斥"
814
- },
815
- "benchmark": {
816
- "type": "string",
817
- "description": "同市场基准代码;与symbol一起使用"
818
- }
819
- },
820
- "required": [
821
- "event_dates"
822
- ],
823
- "additionalProperties": false
824
- },
825
- async execute(_id, params) {
826
- return asText(await withJsonInput(params, async (path: string) =>
827
- (await py("stateless_analysis.py", ["event_study", "--input", path])).stdout));
828
- },
829
- });
830
-
831
- registerTool({
832
- name: "validate_backtest",
833
- description: "无状态回测稳健性:输入历史OHLCV和完整候选DSL;滚动训练选参数、后续不重叠窗口验证,列出全部样本内敏感性及跨标的结果。仅next_open,不自动优化或保存。",
834
- parameters: {
835
- "type": "object",
836
- "properties": {
837
- "datasets": {
838
- "type": "array",
839
- "items": {
840
- "type": "object",
841
- "properties": {
842
- "symbol": {
843
- "type": "string",
844
- "description": "唯一股票代码"
845
- },
846
- "price_basis": {
847
- "type": "string",
848
- "description": "已核实复权/原始价格口径"
849
- },
850
- "bars": {
851
- "type": "array",
852
- "items": {
853
- "type": "object",
854
- "properties": {
855
- "date": {
856
- "type": "string",
857
- "description": "YYYY-MM-DD"
858
- },
859
- "open": {
860
- "type": "number",
861
- "description": "有限OHLCV;价格为正、volume非负"
862
- },
863
- "high": {
864
- "type": "number",
865
- "description": "有限OHLCV;价格为正、volume非负"
866
- },
867
- "low": {
868
- "type": "number",
869
- "description": "有限OHLCV;价格为正、volume非负"
870
- },
871
- "close": {
872
- "type": "number",
873
- "description": "有限OHLCV;价格为正、volume非负"
874
- },
875
- "volume": {
876
- "type": "number",
877
- "description": "有限OHLCV;价格为正、volume非负"
878
- }
879
- },
880
- "required": [
881
- "date",
882
- "open",
883
- "high",
884
- "low",
885
- "close",
886
- "volume"
887
- ],
888
- "additionalProperties": false
889
- },
890
- "description": "日期递增完整OHLCV,每组最多2000条,至少train_bars+test_bars"
891
- }
892
- },
893
- "required": [
894
- "symbol",
895
- "price_basis",
896
- "bars"
897
- ],
898
- "additionalProperties": false
899
- },
900
- "description": "1..5个标的,复用get_kline取数"
901
- },
902
- "strategies": {
903
- "type": "array",
904
- "items": {
905
- "type": "object",
906
- "properties": {
907
- "name": {
908
- "type": "string",
909
- "description": "唯一候选名"
910
- },
911
- "strategy": {
912
- "type": "object",
913
- "additionalProperties": true,
914
- "description": "完整既有YAML DSL对应JSON,允许parameters引用;仅next_open"
915
- }
916
- },
917
- "required": [
918
- "name",
919
- "strategy"
920
- ],
921
- "additionalProperties": false
922
- },
923
- "description": "1..5个预先确定的候选,禁止测试结果回调参数"
924
- },
925
- "train_bars": {
926
- "type": "number",
927
- "description": "训练交易日数30..1000,默认126"
928
- },
929
- "test_bars": {
930
- "type": "number",
931
- "description": "测试交易日数30..1000,默认63"
932
- },
933
- "capital": {
934
- "type": "number",
935
- "description": "每窗口初始资金,默认1000000"
936
- },
937
- "start_date": {
938
- "type": "string",
939
- "description": "代码模式必需,YYYY-MM-DD,包含事件前基准日或训练窗口"
940
- },
941
- "end_date": {
942
- "type": "string",
943
- "description": "代码模式必需,YYYY-MM-DD,晚于start_date"
944
- },
945
- "symbols": {
946
- "type": "array",
947
- "items": {
948
- "type": "string"
949
- },
950
- "description": "1..5个唯一股票代码,配合start_date/end_date直接取数;和datasets互斥"
951
- }
952
- },
953
- "required": [
954
- "strategies"
955
- ],
956
- "additionalProperties": false
957
- },
958
- async execute(_id, params) {
959
- return asText(await withJsonInput(params, async (path: string) =>
960
- (await py("stateless_analysis.py", ["robustness", "--input", path])).stdout));
961
- },
962
- });
963
-
964
- registerTool({
965
- name: "compare_analysis_snapshots",
966
- description: "无状态快照比较:传新旧JSON,返回JSON Pointer及新增/删除/变化/失效/恢复;不保存快照。数组整体比较,调用前按symbol对齐。",
967
- parameters: {
968
- "type": "object",
969
- "properties": {
970
- "previous": {
971
- "type": "object",
972
- "additionalProperties": true,
973
- "description": "JSON对象,详见共享Skill与README"
974
- },
975
- "current": {
976
- "type": "object",
977
- "additionalProperties": true,
978
- "description": "JSON对象,详见共享Skill与README"
979
- }
980
- },
981
- "required": [
982
- "previous",
983
- "current"
984
- ],
985
- "additionalProperties": false
986
- },
987
- async execute(_id, params) {
988
- return asText(await withJsonInput(params, async (path: string) =>
989
- (await py("stateless_analysis.py", ["snapshot", "--input", path])).stdout));
990
- },
991
- });
992
-
993
- registerTool({
994
- name: "get_announcements",
995
- description: "查询A股巨潮公告标题、日期、类型和原文PDF链接;按日期范围/类别筛选,默认近90天,top=1..500。第一版不提取正文,truncated提示截断。",
996
- parameters: {
997
- "type": "object",
998
- "properties": {
999
- "symbol": {
1000
- "type": "string",
1001
- "description": "A股代码"
1002
- },
1003
- "category": {
1004
- "type": "string",
1005
- "enum": [
1006
- "all",
1007
- "forecast",
1008
- "express",
1009
- "annual",
1010
- "interim",
1011
- "quarterly",
1012
- "reduction",
1013
- "issuance",
1014
- "inquiry",
1015
- "dividend"
1016
- ],
1017
- "description": "公告类别,默认all"
1018
- },
1019
- "start_date": {
1020
- "type": "string",
1021
- "description": "开始日期YYYY-MM-DD,默认结束日期前90天"
1022
- },
1023
- "end_date": {
1024
- "type": "string",
1025
- "description": "结束日期YYYY-MM-DD,默认今天"
1026
- },
1027
- "top": {
1028
- "type": "number",
1029
- "description": "最多条数1..500,默认50"
1030
- }
1031
- },
1032
- "required": [
1033
- "symbol"
1034
- ]
1035
- },
1036
- async execute(_id, p) {
1037
- const result = await py("value_data.py", ["announcements", p.symbol, "--category", p.category ?? "all", "--start-date", p.start_date ?? "", "--end-date", p.end_date ?? "", "--top", String(p.top ?? 50)]);
1038
- return asText(result.stdout);
1039
- },
1040
- });
1041
-
1042
- registerTool({
1043
- name: "get_us_holdings",
1044
- description: "查询SEC 13F:mode=auto默认有13F申报时查机构,否则按发行人CIK反查持仓机构;manager/issuer可显式指定。发行人通过官方13D/G精确映射CUSIP,扫描最新已发布13F窗口,处理重述/补充修订,返回实际报告期、截止日及映射覆盖。首次约100MB下载,后续缓存;无映射明确报错,不做名称猜测。需SEC_USER_AGENT含真实联系邮箱,不是实时或全部证券持仓。",
1045
- parameters: {
1046
- "type": "object",
1047
- "properties": {
1048
- "cik": {
1049
- "type": "string",
1050
- "description": "机构或发行人CIK,1..10位数字,如0001067983/0000320193"
1051
- },
1052
- "mode": {"type": "string", "enum": ["auto", "manager", "issuer"], "description": "默认auto;manager查机构组合,issuer反查发行人持仓机构"}
1053
- },
1054
- "required": [
1055
- "cik"
1056
- ]
1057
- },
1058
- async execute(_id, p) {
1059
- const result = await py("sec_edgar.py", ["holdings", p.cik, ...(p.mode ? ["--mode", p.mode] : [])]);
1060
- return asText(result.stdout);
1061
- },
1062
- });
1063
-
1064
- registerTool({
1065
- name: "get_insider_trades",
1066
- description: "查询美股发行人近期Form 4/4-A内部人交易(SEC官方XML),保留人员职务、交易代码、买卖方向、数量、价格、脚注和衍生品标志。需SEC_USER_AGENT含真实联系邮箱;days按申报日期筛选,top限制文件数,修订勿重复计数。",
1067
- parameters: {
1068
- "type": "object",
1069
- "properties": {
1070
- "symbol": {
1071
- "type": "string",
1072
- "description": "美股ticker或发行人CIK"
1073
- },
1074
- "days": {
1075
- "type": "number",
1076
- "description": "申报日期窗口1..365天,默认90"
1077
- },
1078
- "top": {
1079
- "type": "number",
1080
- "description": "最多解析Form 4文件数1..20,默认10"
1081
- }
1082
- },
1083
- "required": [
1084
- "symbol"
1085
- ]
1086
- },
1087
- async execute(_id, p) {
1088
- const result = await py("sec_edgar.py", ["insider_trades", p.symbol, "--days", String(p.days ?? 90), "--top", String(p.top ?? 10)]);
1089
- return asText(result.stdout);
1090
- },
1091
- });
1092
-
1093
- // --- Data Tools ---
1094
-
1095
- registerTool({
1096
- name: "get_valuation_history",
1097
- description: "查询A/HK股票历史PE-TTM/PB、当前正值分位和10/25/50/75/90分位Band,返回实际采样区间;亏损估值分位为null。years=1..10,按天缓存。HK配置LIXINGER_TOKEN时优先理杏仁非金融公司日历史,失败降级百度,不混接来源。",
1098
- parameters: {
1099
- "type": "object",
1100
- "properties": {
1101
- "symbol": {
1102
- "type": "string",
1103
- "description": "A股代码或港股.HK代码"
1104
- },
1105
- "years": {
1106
- "type": "number",
1107
- "description": "历史窗口年数1..10,默认5"
1108
- }
1109
- },
1110
- "required": [
1111
- "symbol"
1112
- ]
1113
- },
1114
- async execute(_id, p) {
1115
- const result = await py("value_data.py", ["valuation_history", p.symbol, "--years", String(p.years ?? 5)]);
1116
- return asText(result.stdout);
1117
- },
1118
- });
1119
-
1120
- registerTool({
1121
- name: "get_index_valuation",
1122
- description: "查询中国指数估值历史分位与Band;乐咕乐股PE/PB优先,中证官方历史补充滚动PE并保留近期PE1口径。缺PB时可用LIXINGER_TOKEN补充理杏仁mcw历史,来源与算法分别标明,不混接同一指标。",
1123
- parameters: {
1124
- "type": "object",
1125
- "properties": {
1126
- "symbol": {
1127
- "type": "string",
1128
- "description": "指数代码或名称,如000300、沪深300、000985"
1129
- },
1130
- "years": {
1131
- "type": "number",
1132
- "description": "历史窗口年数1..10,默认5"
1133
- }
1134
- },
1135
- "required": [
1136
- "symbol"
1137
- ]
1138
- },
1139
- async execute(_id, p) {
1140
- const result = await py("value_data.py", ["index_valuation", p.symbol, "--years", String(p.years ?? 5)]);
1141
- return asText(result.stdout);
1142
- },
1143
- });
1144
-
1145
- registerTool({
1146
- name: "get_earnings_calendar",
1147
- description: "查询财报日历:A股report_date必填季度期末,返回预约/修订/实际披露与业绩预告;HK需symbol,优先HKEX已公告业绩审批董事会排期(不是实际披露日),缺失时返回供应商日期。HK可按已知财政期末过滤,未知期次另列。",
1148
- parameters: {
1149
- "type": "object",
1150
- "properties": {
1151
- "report_date": {
1152
- "type": "string",
1153
- "description": "A股必填季度期末YYYY-MM-DD;HK可选已公告财政期末,未知期次另列"
1154
- },
1155
- "symbol": {
1156
- "type": "string",
1157
- "description": "A股代码可选(省略查全市场);HK必须提供港股.HK代码"
1158
- },
1159
- "top": {
1160
- "type": "number",
1161
- "description": "每类最多返回条数1..500,默认50"
1162
- }
1163
- },
1164
- "required": []
1165
- },
1166
- async execute(_id, p) {
1167
- const result = await py("value_data.py", ["earnings_calendar", "--report-date", p.report_date ?? "", "--symbol", p.symbol ?? "", "--top", String(p.top ?? 50)]);
1168
- return asText(result.stdout);
1169
- },
1170
- });
1171
-
1172
- registerTool({
1173
- name: "get_shareholder_structure",
1174
- description: "查询A股股东户数、十大流通股东变化及沪深交易所季度北向合计持股;官方总量优先,十大HKSCC名义持股仅兜底且标明口径。HK返回港交所南向记录。缺失不当零,期末不等于已公布。",
1175
- parameters: {
1176
- "type": "object",
1177
- "properties": {
1178
- "symbol": {
1179
- "type": "string",
1180
- "description": "A股代码或港股.HK代码"
1181
- },
1182
- "report_date": {
1183
- "type": "string",
1184
- "description": "A股报告期YYYY-MM-DD;省略时北向使用最新已公布季度,十大股东使用最新财报期;HK忽略"
1185
- }
1186
- },
1187
- "required": [
1188
- "symbol"
1189
- ]
1190
- },
1191
- async execute(_id, p) {
1192
- const result = await py("value_data.py", ["shareholder_structure", p.symbol, "--report-date", p.report_date ?? ""]);
1193
- return asText(result.stdout);
1194
- },
1195
- });
1196
-
1197
- registerTool({
1198
- name: "get_etf_details",
1199
- description: "查询A股ETF净值折溢价、规模、披露持仓及沪深完整PCF申赎篮子;篮子不是实际持仓。include_full_holdings=true另取最近可得半年度/年度披露股票表,含数量/市值/报告期,非实时全资产组合;benchmark用于跟踪误差。",
1200
- parameters: {
1201
- "type": "object",
1202
- "properties": {
1203
- "include_full_holdings": {"type": "boolean", "description": "显式请求半年度/年度全部披露股票表,默认false;不是实时全资产组合"},
1204
- "symbol": {
1205
- "type": "string",
1206
- "description": "A股ETF代码,如510300"
1207
- },
1208
- "benchmark": {
1209
- "type": "string",
1210
- "description": "可选基准代码,如sh000300;不猜测基准"
1211
- },
1212
- "days": {
1213
- "type": "number",
1214
- "description": "净值窗口交易日数10..252,默认60"
1215
- }
1216
- },
1217
- "required": [
1218
- "symbol"
1219
- ]
1220
- },
1221
- async execute(_id, p) {
1222
- const result = await py("value_data.py", ["etf_details", p.symbol, "--benchmark", p.benchmark ?? "", "--days", String(p.days ?? 60), ...(p.include_full_holdings ? ["--include-full-holdings"] : [])]);
1223
- return asText(result.stdout);
1224
- },
1225
- });
1226
-
1227
- registerTool({
1228
- name: "get_dividends",
1229
- description: "查询A/HK分红历史、除息日历、已实施TTM股息与连续年数。mode=ranking省略symbol,market=A查报告期排行,market=HK查HKEX/LSEG年度股息率排行(report_date须年末);排行均非当前TTM收益率。缺失不按零。",
1230
- parameters: {
1231
- "type": "object",
1232
- "properties": {
1233
- "market": {"type": "string", "enum": ["A", "HK"], "description": "仅ranking选择市场,默认A;历史/除息日历由symbol决定"},
1234
- "symbol": {
1235
- "type": "string",
1236
- "description": "history/calendar必填A股或港股.HK代码;ranking省略"
1237
- },
1238
- "mode": {
1239
- "type": "string",
1240
- "description": "history默认;calendar未来已公布除息事件;ranking按market查询A/HK排行",
1241
- "enum": [
1242
- "history",
1243
- "calendar",
1244
- "ranking"
1245
- ]
1246
- },
1247
- "report_date": {
1248
- "type": "string",
1249
- "description": "ranking报告期YYYY-MM-DD,默认上一年年末;HK仅年度年末日期"
1250
- },
1251
- "years": {
1252
- "type": "number",
1253
- "description": "历史窗口年数1..20,默认10"
1254
- },
1255
- "top": {
1256
- "type": "number",
1257
- "description": "排名条数1..500,默认20"
1258
- }
1259
- },
1260
- "required": []
1261
- },
1262
- async execute(_id, p) {
1263
- const result = await py("value_data.py", ["dividends", "--market", p.market ?? "A", "--symbol", p.symbol ?? "", "--mode", p.mode ?? "history", "--report-date", p.report_date ?? "", "--years", String(p.years ?? 10), "--top", String(p.top ?? 20)]);
1264
- return asText(result.stdout);
1265
- },
1266
- });
1267
-
1268
- registerTool({
1269
- name: "get_kline",
1270
- description:
1271
- "获取股票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(复权价格/原始价格);缺失不能猜测换算系数。",
1272
- parameters: {
1273
- type: "object",
1274
- properties: {
1275
- symbol: {
1276
- type: "string",
1277
- description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)、7203.T(日股)、005930.KS(韩股)、2330.TW(台股)",
1278
- },
1279
- period: {
1280
- type: "string",
1281
- enum: ["daily", "weekly", "monthly"],
1282
- description: "K线周期,默认 daily",
1283
- },
1284
- count: {
1285
- type: "number",
1286
- description: "返回数据条数,默认 60",
1287
- },
1288
- },
1289
- required: ["symbol"],
1290
- },
1291
- async execute(_id, { symbol, period = "daily", count = 60 }) {
1292
- const result = await py("stock_data.py", [
1293
- "kline",
1294
- symbol,
1295
- "--period",
1296
- period,
1297
- "--count",
1298
- String(count),
1299
- ]);
1300
- return asText(result.stdout);
1301
- },
1302
- });
1303
-
1304
- registerTool({
1305
- name: "get_quote",
1306
- description:
1307
- "获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价。返回 source、UTC fetched_at 和提供方 data_as_of(未知为null);as_of_basis区分提供方时间与交易日历推断,采集时间不等于行情时间。场外基金用 get_fund_quote;TIAAxxxxxx 返回投顾组合识别、advisor_org 与无统一净值提示;长钱/海外长钱/稳钱另有有知有行 official_disclosures(partial=true,非实时完整持仓);其他组合搜索可用时为 search_partial,否则 unsupported_provider。",
1308
- parameters: {
1309
- type: "object",
1310
- properties: {
1311
- symbol: {
1312
- type: "string",
1313
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1314
- },
1315
- },
1316
- required: ["symbol"],
1317
- },
1318
- async execute(_id, { symbol }) {
1319
- const result = await py("stock_data.py", ["quote", symbol]);
1320
- return asText(result.stdout);
1321
- },
1322
- });
1323
-
1324
- registerTool({
1325
- name: "get_fund_quote",
1326
- description:
1327
- "获取场外公募基金净值(6位基金代码,如018147)。nav 是已披露日终净值,非实时价;返回 accumulated_nav(累计净值)、change_pct(日涨跌幅)、nav_date(净值日期)。estimated_nav 为估算净值,可能为 null,不能当作实时价;QDII 净值可能滞后 1-2 交易日。",
1328
- parameters: {
1329
- type: "object",
1330
- properties: {
1331
- symbol: {
1332
- type: "string",
1333
- description: "6位场外公募基金代码,如 018147",
1334
- },
1335
- },
1336
- required: ["symbol"],
1337
- },
1338
- async execute(_id, { symbol }) {
1339
- const result = await py("stock_data.py", ["fund_quote", symbol]);
1340
- return asText(result.stdout);
1341
- },
1342
- });
1343
-
1344
- registerTool({
1345
- name: "get_capital_flow",
1346
- description:
1347
- "获取A股资金流向(主力/超大单/大单/中单/小单净流入)。detail=个股每日明细,summary=多日汇总+趋势,sector_flow=板块资金流排行。可配合 get_chip_distribution 验证主力行为",
1348
- parameters: {
1349
- type: "object",
1350
- properties: {
1351
- symbol: {
1352
- type: "string",
1353
- description: "A股股票代码(detail/summary模式必填),如 600519",
1354
- },
1355
- mode: {
1356
- type: "string",
1357
- enum: ["detail", "summary", "sector_flow"],
1358
- description: "模式:detail=每日明细(默认),summary=多日汇总,sector_flow=板块排行",
1359
- },
1360
- },
1361
- },
1362
- async execute(_id, { symbol = "", mode = "detail" }) {
1363
- const result = await py("stock_data.py", [
1364
- "capital_flow",
1365
- ...(symbol ? [symbol] : []),
1366
- "--mode",
1367
- mode,
1368
- ]);
1369
- return asText(result.stdout);
1370
- },
1371
- });
1372
-
1373
- registerTool({
1374
- name: "get_news",
1375
- description: "获取个股最近N天财经新闻快讯(轻量、无需配置)。需要深度全网情报用 search_comprehensive_intel,按主题搜索用 search_stock_news,读文章全文用 extract_article",
1376
- parameters: {
1377
- type: "object",
1378
- properties: {
1379
- symbol: {
1380
- type: "string",
1381
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1382
- },
1383
- days: {
1384
- type: "number",
1385
- description: "获取最近几天的新闻,默认 3",
1386
- },
1387
- },
1388
- required: ["symbol"],
1389
- },
1390
- async execute(_id, { symbol, days = 3 }) {
1391
- const result = await py("stock_data.py", ["news", symbol, "--days", String(days)]);
1392
- return asText(result.stdout);
1393
- },
1394
- });
1395
-
1396
- registerTool({
1397
- name: "get_financials",
1398
- description:
1399
- "获取股票财务摘要及历史趋势,按天缓存。A股annual=true与periods=10取十年年报;港股可配置LIXINGER_TOKEN取非金融公司财务序列,保留币种/披露日/实际财年,历史比率单位percent。有效Yahoo顶层快照按整组保留,currency为财报币种、market_cap_currency为市值币种、snapshot_source标明来源;缺失值及report_date不混入历史数值/日期。缺token或无权限降级原有来源并标注不足,不补造缺失。估值历史用get_valuation_history,披露排期用get_earnings_calendar",
1400
- parameters: {
1401
- type: "object",
1402
- properties: {
1403
- symbol: {
1404
- type: "string",
1405
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1406
- },
1407
- annual: { type: "boolean", description: "只取年度报告,默认false" },
1408
- periods: {
1409
- type: "number",
1410
- description: "返回最近N个报告期1..40,默认1;annual=true时periods=10请求10年年报",
1411
- },
1412
- },
1413
- required: ["symbol"],
1414
- },
1415
- async execute(_id, { symbol, periods = 1, annual = false }) {
1416
- const result = await py("stock_data.py", [
1417
- "financials",
1418
- symbol,
1419
- ...(periods !== 1 ? ["--periods", String(periods)] : []),
1420
- ...(annual ? ["--annual"] : []),
1421
- ]);
1422
- return asText(result.stdout);
1423
- },
1424
- });
1425
-
1426
- // --- Analysis Tools ---
1427
-
1428
- registerTool({
1429
- name: "get_technical_analysis",
1430
- description:
1431
- "获取股票技术面分析(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",
1432
- parameters: {
1433
- type: "object",
1434
- properties: {
1435
- symbol: {
1436
- type: "string",
1437
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1438
- },
1439
- period: {
1440
- type: "string",
1441
- enum: ["daily", "weekly", "monthly"],
1442
- description: "分析周期,默认 daily",
1443
- },
1444
- count: {
1445
- type: "number",
1446
- description: "用于计算指标的K线条数,默认 120",
1447
- },
1448
- periods: {
1449
- type: "string",
1450
- description: '多周期共振分析,逗号分隔的周期列表,如 "daily,weekly";不传则只分析 period 指定的单周期',
1451
- },
1452
- },
1453
- required: ["symbol"],
1454
- },
1455
- async execute(_id, { symbol, period = "daily", count = 120, periods }) {
1456
- const result = await py("technical.py", [
1457
- "analyze",
1458
- symbol,
1459
- "--period",
1460
- period,
1461
- "--count",
1462
- String(count),
1463
- ...(periods ? ["--periods", periods] : []),
1464
- ]);
1465
- return asText(result.stdout);
1466
- },
1467
- });
1468
-
1469
- registerTool({
1470
- name: "analyze_pattern",
1471
- description:
1472
- "K线形态识别 — 检测十字星、锤子线、吞没、启明星、黄昏星、双底、20日突破等12+种经典形态。综合技术面判断用 get_technical_analysis",
1473
- parameters: {
1474
- type: "object",
1475
- properties: {
1476
- symbol: {
1477
- type: "string",
1478
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1479
- },
1480
- period: {
1481
- type: "string",
1482
- enum: ["daily", "weekly", "monthly"],
1483
- description: "K线周期,默认 daily",
1484
- },
1485
- days: {
1486
- type: "number",
1487
- description: "分析的K线天数,默认 60",
1488
- },
1489
- },
1490
- required: ["symbol"],
1491
- },
1492
- async execute(_id, { symbol, period = "daily", days = 60 }) {
1493
- const result = await py("pattern.py", [
1494
- "analyze",
1495
- symbol,
1496
- "--period",
1497
- period,
1498
- "--days",
1499
- String(days),
1500
- ]);
1501
- return asText(result.stdout);
1502
- },
1503
- });
1504
-
1505
- // --- Market Tools ---
1506
-
1507
- registerTool({
1508
- name: "get_market_indices",
1509
- description:
1510
- "获取主要市场指数行情。CN: 上证/深证/创业板/科创50/沪深300;HK: 恒生/国企/科技;US: 道琼斯/纳斯达克/标普500;JP: 日经225/东证;KR: KOSPI/KOSDAQ;TW: 台湾加权。大盘复盘用 get_market_review 一站式获取",
1511
- parameters: {
1512
- type: "object",
1513
- properties: {
1514
- region: {
1515
- type: "string",
1516
- enum: ["cn", "hk", "us", "jp", "kr", "tw"],
1517
- description: "市场区域,默认 cn",
1518
- },
1519
- },
1520
- },
1521
- async execute(_id, { region = "cn" }) {
1522
- const result = await py("stock_data.py", [
1523
- "market_indices",
1524
- "--region",
1525
- region,
1526
- ]);
1527
- return asText(result.stdout);
1528
- },
1529
- });
1530
-
1531
- registerTool({
1532
- name: "get_sector_rankings",
1533
- description: "获取A股板块涨跌幅排行(含领涨股、涨跌家数等)。board_type=industry(默认)为行业板块,board_type=concept 时为概念板块排行。支持查看涨幅榜/跌幅榜/双向",
1534
- parameters: {
1535
- type: "object",
1536
- properties: {
1537
- top: {
1538
- type: "number",
1539
- description: "返回排名前N的板块,默认 10",
1540
- },
1541
- direction: {
1542
- type: "string",
1543
- enum: ["top", "bottom", "both"],
1544
- description: "top=涨幅榜(默认),bottom=跌幅榜,both=双向",
1545
- },
1546
- board_type: {
1547
- type: "string",
1548
- enum: ["industry", "concept"],
1549
- description: "板块类型:industry=行业(默认),concept=概念",
1550
- },
1551
- },
1552
- },
1553
- async execute(_id, { top = 10, direction = "top", board_type = "industry" }) {
1554
- const result = await py("stock_data.py", [
1555
- "sector_rankings",
1556
- "--top",
1557
- String(top),
1558
- "--direction",
1559
- direction,
1560
- "--board-type",
1561
- board_type,
1562
- ]);
1563
- return asText(result.stdout);
1564
- },
1565
- });
1566
-
1567
- registerTool({
1568
- name: "get_sector_constituents",
1569
- description:
1570
- "查询A股板块成分股(正向映射:板块→股票列表)。板块名支持模糊匹配(如「创新药」自动解析到精确板块名),东财行业/概念 + 新浪多源 failover,结果按用户目录缓存7天。仅支持A股;反向查个股所属板块用 resolve_stock_sectors",
1571
- parameters: {
1572
- type: "object",
1573
- properties: {
1574
- sector: {
1575
- type: "string",
1576
- description: "板块名称(可模糊,如 创新药、半导体)",
1577
- },
1578
- board_type: {
1579
- type: "string",
1580
- enum: ["industry", "concept", "auto"],
1581
- description: "板块类型:industry=行业,concept=概念,auto=自动(默认)",
1582
- },
1583
- },
1584
- required: ["sector"],
1585
- },
1586
- async execute(_id, { sector, board_type = "auto" }) {
1587
- const result = await py("stock_data.py", [
1588
- "sector_constituents",
1589
- sector,
1590
- "--board-type",
1591
- board_type,
1592
- ]);
1593
- return asText(result.stdout);
1594
- },
1595
- });
1596
-
1597
- registerTool({
1598
- name: "resolve_stock_sectors",
1599
- description:
1600
- "查询个股所属板块(反向映射:个股→板块)。A股返回东财行业 + efinance 概念/板块(雪球行业兜底,需 XUEQIU_TOKEN),港股返回 yfinance GICS 英文 sector/industry 口径。板块级情报(如「创新药回调」)映射到池内个股时调本工具;正向查板块成分股用 get_sector_constituents",
1601
- parameters: {
1602
- type: "object",
1603
- properties: {
1604
- symbol: {
1605
- type: "string",
1606
- description: "股票代码(A股如 600519,港股如 00700.HK)",
1607
- },
1608
- },
1609
- required: ["symbol"],
1610
- },
1611
- async execute(_id, { symbol }) {
1612
- const result = await py("stock_data.py", ["resolve_stock_sectors", symbol]);
1613
- return asText(result.stdout);
1614
- },
1615
- });
1616
-
1617
- registerTool({
1618
- name: "get_stock_info",
1619
- description:
1620
- "获取股票基本信息(行业、板块、上市日期、总股本等)。A股返回板块/行业,其他市场返回行业/公司简介",
1621
- parameters: {
1622
- type: "object",
1623
- properties: {
1624
- symbol: {
1625
- type: "string",
1626
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
1627
- },
1628
- },
1629
- required: ["symbol"],
1630
- },
1631
- async execute(_id, { symbol }) {
1632
- const result = await py("stock_data.py", ["stock_info", symbol]);
1633
- return asText(result.stdout);
1634
- },
1635
- });
1636
-
1637
- registerTool({
1638
- name: "get_chip_distribution",
1639
- description:
1640
- "获取A股筹码分布数据(获利比例、平均成本、90%/70%成本集中度)。仅支持A股。与 get_capital_flow 配合验证主力行为",
1641
- parameters: {
1642
- type: "object",
1643
- properties: {
1644
- symbol: {
1645
- type: "string",
1646
- description: "A股股票代码,如 600519",
1647
- },
1648
- },
1649
- required: ["symbol"],
1650
- },
1651
- async execute(_id, { symbol }) {
1652
- const result = await py("stock_data.py", ["chip_distribution", symbol]);
1653
- return asText(result.stdout);
1654
- },
1655
- });
1656
-
1657
- registerTool({
1658
- name: "get_market_stats",
1659
- description:
1660
- "获取A股市场整体统计(涨跌家数、涨停跌停数、平均涨幅、涨跌Top5、总成交额)。用于衡量市场整体情绪与温度",
1661
- parameters: {
1662
- type: "object",
1663
- properties: {},
1664
- },
1665
- async execute() {
1666
- const result = await py("stock_data.py", ["market_stats"]);
1667
- return asText(result.stdout);
1668
- },
1669
- });
1670
-
1671
- registerTool({
1672
- name: "get_limit_up_pool",
1673
- description:
1674
- "获取A股涨停池/涨停板复盘——当日涨停个股,含连板数、封板资金、炸板次数、首末次封板时间、所属行业。短线情绪与龙头战法核心数据",
1675
- parameters: {
1676
- type: "object",
1677
- properties: {
1678
- date: {
1679
- type: "string",
1680
- description: "日期(YYYYMMDD),默认当日;非交易日或未来日期自动回退到最近交易日(返回含 requested_date 与 stale 标注)",
1681
- },
1682
- },
1683
- },
1684
- async execute(_id, { date }) {
1685
- const result = await py("stock_data.py", [
1686
- "limit_up_pool",
1687
- ...(date ? ["--date", date] : []),
1688
- ]);
1689
- return asText(result.stdout);
1690
- },
1691
- });
1692
-
1693
- registerTool({
1694
- name: "get_dragon_tiger",
1695
- description:
1696
- "获取A股龙虎榜——上榜个股净买额/买入额/卖出额/上榜原因/解读,可按个股过滤",
1697
- parameters: {
1698
- type: "object",
1699
- properties: {
1700
- date: {
1701
- type: "string",
1702
- description: "日期(YYYY-MM-DD),默认当日;非交易日或未来日期自动回退到最近交易日(返回含 requested_date 与 stale 标注)",
1703
- },
1704
- symbol: {
1705
- type: "string",
1706
- description: "A股股票代码(可选,按个股过滤),如 600519",
1707
- },
1708
- top: {
1709
- type: "number",
1710
- description: "返回前N条,默认 20",
1711
- },
1712
- },
1713
- },
1714
- async execute(_id, { date, symbol, top = 20 }) {
1715
- const result = await py("stock_data.py", [
1716
- "dragon_tiger",
1717
- ...(date ? ["--date", date] : []),
1718
- ...(symbol ? ["--symbol", symbol] : []),
1719
- "--top",
1720
- String(top),
1721
- ]);
1722
- return asText(result.stdout);
1723
- },
1724
- });
1725
-
1726
- registerTool({
1727
- name: "get_hot_stocks",
1728
- description: "获取A股全市场人气热搜榜(东方财富人气榜)",
1729
- parameters: {
1730
- type: "object",
1731
- properties: {
1732
- top: {
1733
- type: "number",
1734
- description: "返回前N只,默认 20",
1735
- },
1736
- },
1737
- },
1738
- async execute(_id, { top = 20 }) {
1739
- const result = await py("stock_data.py", ["hot_stocks", "--top", String(top)]);
1740
- return asText(result.stdout);
1741
- },
1742
- });
1743
-
1744
- registerTool({
1745
- name: "get_margin_trading",
1746
- description:
1747
- "获取A股个股融资融券明细(融资余额/融资买入额/融券余量等,上交所/深交所官方数据按交易所分流),返回最近N个交易日序列(最新在前)。金额单位为元,short_*_shares 单位为股。include_ratio=true追加同日融资买入/成交额百分比(margin_buy_ratio_pct),缺少同日元口径成交额则为null。仅两融标的有数据,非两融标的返回错误",
1748
- parameters: {
1749
- type: "object",
1750
- properties: {
1751
- symbol: {
1752
- type: "string",
1753
- description: "A股股票代码,如 600519",
1754
- },
1755
- include_ratio: { type: "boolean", description: "追加同日融资买入占比,默认false" },
1756
- days: {
1757
- type: "number",
1758
- description: "返回最近N个交易日,默认 10",
1759
- },
1760
- },
1761
- required: ["symbol"],
1762
- },
1763
- async execute(_id, { symbol, days = 10, include_ratio = false }) {
1764
- const result = await py("stock_data.py", ["margin_trading", symbol, "--days", String(days), ...(include_ratio ? ["--include-ratio"] : [])]);
1765
- return asText(result.stdout);
1766
- },
1767
- });
1768
-
1769
- registerTool({
1770
- name: "get_northbound_flow",
1771
- description:
1772
- "获取北向资金市场级净买入序列(最新在前,单位亿元)。数据口径:东方财富沪深港通历史数据;2024-08-16 起交易所停止披露日度净买额,仅 2024-08 之前历史数据可查(近期小 days 窗口会返回停披错误,加大 days 可取历史)",
1773
- parameters: {
1774
- type: "object",
1775
- properties: {
1776
- days: {
1777
- type: "number",
1778
- description: "返回最近N个交易日,默认 10",
1779
- },
1780
- },
1781
- },
1782
- async execute(_id, { days = 10 }) {
1783
- const result = await py("stock_data.py", ["northbound_flow", "--days", String(days)]);
1784
- return asText(result.stdout);
1785
- },
1786
- });
1787
-
1788
- registerTool({
1789
- name: "get_fundamental_context",
1790
- description:
1791
- "获取A股基本面上下文(估值 PE/PB/市值 + 营收/净利增速 + ROE/毛利率/净利率 + 分红历史)。用于评估公司质地与长期持有价值",
1792
- parameters: {
1793
- type: "object",
1794
- properties: {
1795
- symbol: {
1796
- type: "string",
1797
- description: "A股股票代码,如 600519",
1798
- },
1799
- },
1800
- required: ["symbol"],
1801
- },
1802
- async execute(_id, { symbol }) {
1803
- const result = await py("stock_data.py", ["fundamental_context", symbol]);
1804
- return asText(result.stdout);
1805
- },
1806
- });
1807
-
1808
- // --- Screener & Backtest ---
1809
-
1810
- registerTool({
1811
- name: "screen_stocks",
1812
- description:
1813
- "全市场股票筛选(AlphaSift L1 多因子硬筛 + 市场情绪调节)。按PE/PB/市值/换手率/涨跌幅/量比等因子过滤和评分,可用 l2 开启质量/成长/动量/波动率/资金流增强。显式筛选条件缺少数据时报error,filters_applied只列实际执行的条件。候选factor_coverage列出可用/缺失因子、加权覆盖率和effective_weights;L1与L2均按可用因子归一化后排序,缺失/非有限值不按零分计;L2另返回effective_scores供结合市场系数复算final,按可用因子重归一化,高分不代表数据完整。选股预算按候选数量及采集批次计算,top须为正整数。",
1814
- parameters: {
1815
- type: "object",
1816
- properties: {
1817
- market: {
1818
- type: "string",
1819
- enum: ["A", "HK", "US"],
1820
- description: "市场,默认 A",
1821
- },
1822
- top: {
1823
- type: "number",
1824
- description: "返回排名前N的股票,默认 20",
1825
- },
1826
- config: {
1827
- type: "string",
1828
- description: "自定义筛选配置YAML文件路径,不填用默认配置",
1829
- },
1830
- l2: {
1831
- type: "boolean",
1832
- description: "开启L2量化增强(质量/成长/真实动量/波动率/资金流因子,逐股抓取数据较慢),默认关闭",
1833
- },
1834
- },
1835
- },
1836
- async execute(_id, { market = "A", top = 20, config, l2 = false }) {
1837
- const result = await py("screener.py", [
1838
- "screen",
1839
- "--market",
1840
- market,
1841
- "--top",
1842
- String(top),
1843
- ...(config ? ["--config", config] : []),
1844
- ...(l2 ? ["--l2"] : []),
1845
- ]);
1846
- return asText(result.stdout);
1847
- },
1848
- });
1849
-
1850
- registerTool({
1851
- name: "calculate_rotation_metrics",
1852
- description: "行业轮动数值复核:输入真实MC-dropout样本和/或历史成交计数,计算集中度和原始配权;不训练模型、不生成买入信号,零历史不补默认值。",
1853
- parameters: {
1854
- "type": "object",
1855
- "properties": {
1856
- "prediction_samples": {
1857
- "type": "array",
1858
- "items": {
1859
- "type": "object",
1860
- "properties": {
1861
- "symbol": {
1862
- "type": "string",
1863
- "description": "唯一标的标识"
1864
- },
1865
- "samples": {
1866
- "type": "array",
1867
- "items": {
1868
- "type": "number",
1869
- "description": "同一模型/标的/时间的有限线性输出,不是价格或收益率"
1870
- },
1871
- "description": "2..100000个真实MC-dropout预测;不得用随机数或动量代替"
1872
- }
1873
- },
1874
- "required": [
1875
- "symbol",
1876
- "samples"
1877
- ],
1878
- "additionalProperties": false
1879
- },
1880
- "description": "1..100组,总样本<=100000;和trade_counts至少提供一项"
1881
- },
1882
- "trade_counts": {
1883
- "type": "array",
1884
- "items": {
1885
- "type": "object",
1886
- "properties": {
1887
- "symbol": {
1888
- "type": "string",
1889
- "description": "唯一标的标识;代码别名须先统一"
1890
- },
1891
- "buys": {
1892
- "type": "number",
1893
- "description": "此前已平仓买入周数,非负整数"
1894
- },
1895
- "wins": {
1896
- "type": "number",
1897
- "description": "此前盈利平仓次数,0..buys"
1898
- },
1899
- "streak": {
1900
- "type": "number",
1901
- "description": "此前连续盈利交易次数,0..wins"
1902
- }
1903
- },
1904
- "required": [
1905
- "symbol",
1906
- "buys",
1907
- "wins",
1908
- "streak"
1909
- ],
1910
- "additionalProperties": false
1911
- },
1912
- "description": "1..100条已完成历史成交计数;不得使用决策后的交易"
1913
- }
1914
- },
1915
- "required": [],
1916
- "additionalProperties": false
1917
- },
1918
- async execute(_id, params) {
1919
- return asText(await withJsonInput(params, async (path: string) =>
1920
- (await py("sector_rotation.py", ["analyze", "--input", path])).stdout));
1921
- },
1922
- });
1923
-
1924
- registerTool({
1925
- name: "backtest_rotation_allocation",
1926
- description: "行业轮动配权分项回测:代码自动取行情,或传明确币种/复权OHLCV;相同每周全池买卖下比较等权与历史配权。按市场和报价币种独立资金,支持A/HK/US/JP/KR/TW;不是完整论文深度模型或跨币种共享资金回测。",
1927
- parameters: {
1928
- "type": "object",
1929
- "properties": {
1930
- "symbols": {
1931
- "type": "array",
1932
- "items": {
1933
- "type": "string",
1934
- "description": "唯一股票/ETF代码,按插件代码格式"
1935
- },
1936
- "description": "1..20只自动取数,与datasets互斥;任一失败整池停止"
1937
- },
1938
- "datasets": {
1939
- "type": "array",
1940
- "items": {
1941
- "type": "object",
1942
- "properties": {
1943
- "symbol": {
1944
- "type": "string",
1945
- "description": "A六位代码/HK如2800.HK/US如XLK/JP如1306.T/KR如069500.KS/TW如0050.TW"
1946
- },
1947
- "currency": {
1948
- "type": "string",
1949
- "description": "已核实报价币种三字母代码,不按上市地猜测"
1950
- },
1951
- "price_basis": {
1952
- "type": "string",
1953
- "enum": [
1954
- "qfq",
1955
- "total_return",
1956
- "split_adjusted"
1957
- ],
1958
- "description": "已核实且一致的复权口径"
1959
- },
1960
- "bars": {
1961
- "type": "array",
1962
- "items": {
1963
- "type": "object",
1964
- "properties": {
1965
- "date": {
1966
- "type": "string",
1967
- "description": "YYYY-MM-DD"
1968
- },
1969
- "open": {
1970
- "type": "number",
1971
- "description": "有限正OHLC价格;volume非负"
1972
- },
1973
- "high": {
1974
- "type": "number",
1975
- "description": "有限正OHLC价格;volume非负"
1976
- },
1977
- "low": {
1978
- "type": "number",
1979
- "description": "有限正OHLC价格;volume非负"
1980
- },
1981
- "close": {
1982
- "type": "number",
1983
- "description": "有限正OHLC价格;volume非负"
1984
- },
1985
- "volume": {
1986
- "type": "number",
1987
- "description": "有限正OHLC价格;volume非负"
1988
- },
1989
- "adjusted": {
1990
- "type": "string",
1991
- "description": "可选逐bar复权标记,存在时必须与price_basis一致"
1992
- },
1993
- "source": {
1994
- "type": "string",
1995
- "description": "可选行情来源标识,用于数据覆盖报告"
1996
- }
1997
- },
1998
- "required": [
1999
- "date",
2000
- "open",
2001
- "high",
2002
- "low",
2003
- "close",
2004
- "volume"
2005
- ],
2006
- "additionalProperties": false
2007
- },
2008
- "description": "递增唯一daily OHLCV,2..20000行,包含评估前预热;总量<=100000"
2009
- }
2010
- },
2011
- "required": [
2012
- "symbol",
2013
- "currency",
2014
- "price_basis",
2015
- "bars"
2016
- ],
2017
- "additionalProperties": false
2018
- },
2019
- "description": "1..20个离线数据集,与symbols互斥;8MiB JSON输入上限"
2020
- },
2021
- "start_date": {
2022
- "type": "string",
2023
- "description": "评估起始YYYY-MM-DD;跨边界周不交易,不能用评估期收益初始化配权"
2024
- },
2025
- "end_date": {
2026
- "type": "string",
2027
- "description": "已收盘截止YYYY-MM-DD;不完整末周不成交"
2028
- },
2029
- "history_start_date": {
2030
- "type": "string",
2031
- "description": "仅代码模式;默认评估前一年,必须早于start_date"
2032
- },
2033
- "warmup_weeks": {
2034
- "type": "number",
2035
- "description": "评估前完整历史交易周1..104整数,默认26;不足停止"
2036
- },
2037
- "capital": {
2038
- "type": "number",
2039
- "description": "每市场/报价币种分组独立初始资金,默认1000000,不是混合池总额"
2040
- },
2041
- "cost_per_side": {
2042
- "type": "number",
2043
- "description": "每边比例成本0..0.1,默认0.001;买入预算含费用"
2044
- }
2045
- },
2046
- "required": [
2047
- "start_date",
2048
- "end_date"
2049
- ],
2050
- "additionalProperties": false
2051
- },
2052
- async execute(_id, params) {
2053
- return asText(await withJsonInput(params, async (path: string) =>
2054
- (await py("sector_rotation.py", ["backtest", "--input", path])).stdout));
2055
- },
2056
- });
2057
-
2058
- registerTool({
2059
- name: "analyze_trend_strategy",
2060
- description: "月度右侧趋势策略:直接传同市场A/HK/US股票代码,自动获取日K,输出月度新入/持有/退出与逆波动预算。as_of默认最近已收盘交易日,持仓可选且不保存,不自动下单;跨样本仍not_validated。",
2061
- parameters: {
2062
- "type": "object",
2063
- "properties": {
2064
- "symbols": {
2065
- "type": "array",
2066
- "items": {
2067
- "type": "string"
2068
- },
2069
- "description": "同一市场的完整股票池,1..100只;A如600036,HK如0700.HK,US如AAPL"
2070
- },
2071
- "as_of": {
2072
- "type": "string",
2073
- "description": "可选已收盘截止日期YYYY-MM-DD,默认该市场最近已收盘交易日"
2074
- },
2075
- "held_symbols": {
2076
- "type": "array",
2077
- "items": {
2078
- "type": "string"
2079
- },
2080
- "description": "可选,as_of时真实持股代码,必须在股票池中;省略代表初始空仓,不保存账户"
2081
- },
2082
- "pending_exit_symbols": {
2083
- "type": "array",
2084
- "items": {
2085
- "type": "string"
2086
- },
2087
- "description": "可选,真实持股中此前已锁定且未成交的退出代码"
2088
- },
2089
- "slots": {
2090
- "type": "number",
2091
- "description": "可选固定容量K,默认ceil(N/3),不得小于真实持股数量"
2092
- }
2093
- },
2094
- "required": [
2095
- "symbols"
2096
- ],
2097
- "additionalProperties": false
2098
- },
2099
- async execute(_id, params) {
2100
- return asText(await withJsonInput(params, async (path: string) =>
2101
- (await py("trend_strategy.py", ["fetch", "--input", path])).stdout));
2102
- },
2103
- });
2104
-
2105
- registerTool({
2106
- name: "run_backtest",
2107
- description:
2108
- "策略回测(AlphaEvo)。读取YAML策略定义,在历史数据上模拟交易,输出收益率/回撤/胜率等指标。只想知道单个技术信号的历史胜率用更轻量的 evaluate_signal。period为实际数据期间,requested_period保留请求期间,warnings提示覆盖差异;年化按实际期间计算。默认前日收盘信号、次日开盘成交;YAML simulation.execution=same_close可复现旧假设。execution返回模型、阻止成交次数和未模拟约束;零成交量及带历史限价的一字板不成交。支持 monthly_momentum:月初首根有效日K收盘观察过去period根对数收益,次日开盘;长周期需预热。",
2109
- parameters: {
2110
- type: "object",
2111
- properties: {
2112
- strategy: {
2113
- type: "string",
2114
- description: "策略YAML文件路径",
2115
- },
2116
- symbol: {
2117
- type: "string",
2118
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2119
- },
2120
- start: {
2121
- type: "string",
2122
- description: "回测起始日期,格式 YYYY-MM-DD",
2123
- },
2124
- end: {
2125
- type: "string",
2126
- description: "回测结束日期,格式 YYYY-MM-DD",
2127
- },
2128
- capital: {
2129
- type: "number",
2130
- description: "初始资金,默认 1000000",
2131
- },
2132
- },
2133
- required: ["strategy", "symbol"],
2134
- },
2135
- async execute(_id, { strategy, symbol, start, end, capital = 1000000 }) {
2136
- const result = await py("backtest.py", [
2137
- "run",
2138
- strategy,
2139
- symbol,
2140
- ...(start ? ["--start", start] : []),
2141
- ...(end ? ["--end", end] : []),
2142
- "--capital",
2143
- String(capital),
2144
- ]);
2145
- return asText(result.stdout);
2146
- },
2147
- });
2148
-
2149
- registerTool({
2150
- name: "evaluate_signal",
2151
- description:
2152
- "技术信号历史准确率评估 — 回溯历史数据,统计某个技术信号触发后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",
2153
- parameters: {
2154
- type: "object",
2155
- properties: {
2156
- symbol: {
2157
- type: "string",
2158
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2159
- },
2160
- signal: {
2161
- type: "string",
2162
- enum: [
2163
- "macd_golden_cross",
2164
- "macd_death_cross",
2165
- "rsi_oversold",
2166
- "rsi_overbought",
2167
- "breakout_20d",
2168
- "breakdown_20d",
2169
- "volume_surge",
2170
- "ma_golden_cross",
2171
- "ma_death_cross",
2172
- ],
2173
- description: "信号名称",
2174
- },
2175
- forward_days: {
2176
- type: "string",
2177
- description: "逗号分隔的前瞻天数,默认 3,5,10",
2178
- },
2179
- lookback: {
2180
- type: "number",
2181
- description: "回溯K线条数,默认 250(约1年)",
2182
- },
2183
- },
2184
- required: ["symbol", "signal"],
2185
- },
2186
- async execute(_id, { symbol, signal, forward_days = "3,5,10", lookback = 250 }) {
2187
- const result = await py("backtest.py", [
2188
- "evaluate_signal",
2189
- symbol,
2190
- signal,
2191
- "--forward",
2192
- String(forward_days),
2193
- "--lookback",
2194
- String(lookback),
2195
- ]);
2196
- return asText(result.stdout);
2197
- },
2198
- });
2199
-
2200
- // --- Name Resolution ---
2201
-
2202
- registerTool({
2203
- name: "resolve_stock_name",
2204
- description:
2205
- "股票名称智能解析 — 输入中文名(贵州茅台)、拼音(guizhou maotai/gzmt)、部分代码,返回匹配的股票代码。仅支持A股。用户给出中文名/拼音/部分代码时先调本工具换成代码再调其他工具",
2206
- parameters: {
2207
- type: "object",
2208
- properties: {
2209
- query: {
2210
- type: "string",
2211
- description: "股票名称、拼音、拼音首字母或部分代码",
2212
- },
2213
- top: {
2214
- type: "number",
2215
- description: "返回匹配数量,默认 5",
2216
- },
2217
- },
2218
- required: ["query"],
2219
- },
2220
- async execute(_id, { query, top = 5 }) {
2221
- const result = await py("name_resolver.py", [
2222
- "resolve",
2223
- query,
2224
- "--top",
2225
- String(top),
2226
- ]);
2227
- return asText(result.stdout);
2228
- },
2229
- });
2230
-
2231
- // --- Trading Calendar ---
2232
-
2233
- registerTool({
2234
- name: "check_trading_day",
2235
- description:
2236
- "查询某日是否为交易日。支持CN(A股)、HK(港股)、US(美股)、JP(日股)、KR(韩股)、TW(台股)",
2237
- parameters: {
2238
- type: "object",
2239
- properties: {
2240
- market: {
2241
- type: "string",
2242
- enum: ["CN", "HK", "US", "JP", "KR", "TW"],
2243
- description: "市场",
2244
- },
2245
- date: {
2246
- type: "string",
2247
- description: "日期(YYYY-MM-DD),不填则查今天",
2248
- },
2249
- },
2250
- required: ["market"],
2251
- },
2252
- async execute(_id, { market, date }) {
2253
- const result = await py("trading_calendar.py", [
2254
- "check",
2255
- market,
2256
- ...(date ? ["--date", date] : []),
2257
- ]);
2258
- return asText(result.stdout);
2259
- },
2260
- });
2261
-
2262
- registerTool({
2263
- name: "get_trading_days",
2264
- description:
2265
- "获取最近/未来N个交易日列表。支持CN/HK/US/JP/KR/TW",
2266
- parameters: {
2267
- type: "object",
2268
- properties: {
2269
- market: {
2270
- type: "string",
2271
- enum: ["CN", "HK", "US", "JP", "KR", "TW"],
2272
- description: "市场",
2273
- },
2274
- direction: {
2275
- type: "string",
2276
- enum: ["next", "prev"],
2277
- description: "next=未来交易日, prev=过去交易日",
2278
- },
2279
- count: {
2280
- type: "number",
2281
- description: "返回天数,默认 5",
2282
- },
2283
- date: {
2284
- type: "string",
2285
- description: "起始日期(YYYY-MM-DD),默认今天",
2286
- },
2287
- },
2288
- required: ["market"],
2289
- },
2290
- async execute(_id, { market, direction = "next", count = 5, date }) {
2291
- const result = await py("trading_calendar.py", [
2292
- direction,
2293
- market,
2294
- "--count",
2295
- String(count),
2296
- ...(date ? ["--date", date] : []),
2297
- ]);
2298
- return asText(result.stdout);
2299
- },
2300
- });
2301
-
2302
- registerTool({
2303
- name: "get_trading_phase",
2304
- description:
2305
- "查询某市场当前交易时段(盘前/早盘/午间休市/午盘/交易中/盘后/休市),用于正确解读实时行情的盘中语义。支持CN/HK/US/JP/KR/TW",
2306
- parameters: {
2307
- type: "object",
2308
- properties: {
2309
- market: {
2310
- type: "string",
2311
- enum: ["CN", "HK", "US", "JP", "KR", "TW"],
2312
- description: "市场",
2313
- },
2314
- },
2315
- required: ["market"],
2316
- },
2317
- async execute(_id, { market }) {
2318
- const result = await py("trading_calendar.py", ["phase", market]);
2319
- return asText(result.stdout);
2320
- },
2321
- });
2322
-
2323
- // --- Standalone MA Calculator ---
2324
-
2325
- registerTool({
2326
- name: "calculate_ma",
2327
- description:
2328
- "独立均线计算器 — 支持任意周期MA(5/10/20/30/60/120/250或自定义)+ 偏离度 + 均线排列 + 金叉死叉检测。只要均线数值或需要30/120/250等非默认周期时用本工具;综合技术面分析用 get_technical_analysis",
2329
- parameters: {
2330
- type: "object",
2331
- properties: {
2332
- symbol: {
2333
- type: "string",
2334
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2335
- },
2336
- periods: {
2337
- type: "string",
2338
- description: "逗号分隔的MA周期列表,如 5,10,20,60,120,250",
2339
- },
2340
- kline_period: {
2341
- type: "string",
2342
- enum: ["daily", "weekly", "monthly"],
2343
- description: "K线周期,默认 daily",
2344
- },
2345
- },
2346
- required: ["symbol"],
2347
- },
2348
- async execute(_id, { symbol, periods = "5,10,20,30,60,120,250", kline_period = "daily" }) {
2349
- const result = await py("technical.py", [
2350
- "calculate_ma",
2351
- symbol,
2352
- "--periods",
2353
- periods,
2354
- "--period",
2355
- kline_period,
2356
- "--count",
2357
- "300",
2358
- ]);
2359
- return asText(result.stdout);
2360
- },
2361
- });
2362
-
2363
- // --- Volume-Price Analysis ---
2364
-
2365
- registerTool({
2366
- name: "get_volume_analysis",
2367
- description:
2368
- "独立量价分析 — 量价相关性、上涨/下跌日成交量对比、量能趋势、量价模式解读(放量上涨/缩量回调等)。综合技术面判断用 get_technical_analysis,扫当日异动用 detect_anomaly",
2369
- parameters: {
2370
- type: "object",
2371
- properties: {
2372
- symbol: {
2373
- type: "string",
2374
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2375
- },
2376
- period: {
2377
- type: "string",
2378
- enum: ["daily", "weekly", "monthly"],
2379
- description: "K线周期,默认 daily",
2380
- },
2381
- count: {
2382
- type: "number",
2383
- description: "分析K线条数,默认 60",
2384
- },
2385
- },
2386
- required: ["symbol"],
2387
- },
2388
- async execute(_id, { symbol, period = "daily", count = 60 }) {
2389
- const result = await py("volume_analysis.py", [
2390
- "analyze",
2391
- symbol,
2392
- "--period",
2393
- period,
2394
- "--count",
2395
- String(count),
2396
- ]);
2397
- return asText(result.stdout);
2398
- },
2399
- });
2400
-
2401
- // --- Search Intelligence ---
2402
-
2403
- registerTool({
2404
- name: "search_stock_news",
2405
- description:
2406
- "多引擎股票新闻搜索(Tavily/Brave/SerpAPI/Bocha/SearXNG)。需配置至少一个搜索源的 Key 或 SearXNG URL。get_news 快讯不够或要按主题搜索时用;深度6维情报用 search_comprehensive_intel",
2407
- parameters: {
2408
- type: "object",
2409
- properties: {
2410
- query: {
2411
- type: "string",
2412
- description: "搜索关键词",
2413
- },
2414
- count: {
2415
- type: "number",
2416
- description: "返回结果数量,默认 10",
2417
- },
2418
- },
2419
- required: ["query"],
2420
- },
2421
- async execute(_id, { query, count = 10 }) {
2422
- const result = await py("search_intel.py", [
2423
- "search",
2424
- query,
2425
- "--count",
2426
- String(count),
2427
- ]);
2428
- return asText(result.stdout);
2429
- },
2430
- });
2431
-
2432
- registerTool({
2433
- name: "search_comprehensive_intel",
2434
- description:
2435
- "股票综合情报搜索 — 从6个维度(新闻/公告/行情分析/风险/业绩/行业)搜索综合信息。用于个股的深入研究/全面调研;快速看新闻用 get_news",
2436
- parameters: {
2437
- type: "object",
2438
- properties: {
2439
- symbol: {
2440
- type: "string",
2441
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2442
- },
2443
- name: {
2444
- type: "string",
2445
- description: "股票名称(可选,提升搜索准确度)",
2446
- },
2447
- },
2448
- required: ["symbol"],
2449
- },
2450
- async execute(_id, { symbol, name }) {
2451
- const result = await py("search_intel.py", [
2452
- "comprehensive",
2453
- symbol,
2454
- ...(name ? ["--name", name] : []),
2455
- ]);
2456
- return asText(result.stdout);
2457
- },
2458
- });
2459
-
2460
- registerTool({
2461
- name: "get_social_sentiment",
2462
- description:
2463
- "获取股票社交媒体情绪数据。A股:东方财富股吧热度+雪球讨论热度(无需配置);美股/港股:Reddit/X/Polymarket情绪(需 SENTIMENT_API_KEY)。自动按市场选数据源。面向个股维度;全市场热门讨论用 get_trending_sentiment",
2464
- parameters: {
2465
- type: "object",
2466
- properties: {
2467
- symbol: {
2468
- type: "string",
2469
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2470
- },
2471
- },
2472
- required: ["symbol"],
2473
- },
2474
- async execute(_id, { symbol }) {
2475
- const result = await py("search_intel.py", ["sentiment", symbol]);
2476
- return asText(result.stdout);
2477
- },
2478
- });
2479
-
2480
- registerTool({
2481
- name: "get_trending_sentiment",
2482
- description:
2483
- "获取社交媒体热门趋势(Reddit/X/Polymarket热门股票讨论)。适用于发现市场热点;查个股情绪用 get_social_sentiment",
2484
- parameters: {
2485
- type: "object",
2486
- properties: {},
2487
- },
2488
- async execute() {
2489
- const result = await py("search_intel.py", ["trending"]);
2490
- return asText(result.stdout);
2491
- },
2492
- });
2493
-
2494
- registerTool({
2495
- name: "extract_article",
2496
- description:
2497
- "网页文章全文提取 — 输入URL,提取文章标题、正文(最多3000字)、作者、发布日期等。配合 get_news/search_stock_news 的搜索结果做深度阅读",
2498
- parameters: {
2499
- type: "object",
2500
- properties: {
2501
- url: {
2502
- type: "string",
2503
- description: "文章URL",
2504
- },
2505
- },
2506
- required: ["url"],
2507
- },
2508
- async execute(_id, { url }) {
2509
- const result = await py("search_intel.py", ["extract", url]);
2510
- return asText(result.stdout);
2511
- },
2512
- });
2513
-
2514
- registerTool({
2515
- name: "screen_risk",
2516
- description:
2517
- "A股风险专项筛查 — 检查估值、技术预警、解禁、减持、业绩预警、监管和行业政策,返回风险评级和 veto_buy。新闻搜索命中是待核实线索,不是已证实风险。data_complete和warnings标明覆盖;数据不足时risk_level=unknown,risk_score或veto_buy可为null,不能视为低风险",
2518
- parameters: {
2519
- type: "object",
2520
- properties: {
2521
- symbol: {
2522
- type: "string",
2523
- description: "A股股票代码,如 600519",
2524
- },
2525
- name: {
2526
- type: "string",
2527
- description: "股票名称(可选,提升新闻搜索准确度)",
2528
- },
2529
- },
2530
- required: ["symbol"],
2531
- },
2532
- async execute(_id, { symbol, name }) {
2533
- const result = await py("risk_screening.py", [
2534
- "screen",
2535
- symbol,
2536
- ...(name ? ["--name", name] : []),
2537
- ]);
2538
- return asText(result.stdout);
2539
- },
2540
- });
2541
-
2542
- registerTool({
2543
- name: "detect_market_regime",
2544
- description:
2545
- "市场状态检测 — 分析大盘指数判断当前市场阶段(上涨趋势/下跌趋势/横盘震荡/高波动/板块热点),并推荐适合的分析策略",
2546
- parameters: {
2547
- type: "object",
2548
- properties: {
2549
- market: {
2550
- type: "string",
2551
- enum: ["A", "HK", "US"],
2552
- description: "市场代码,默认 A",
2553
- },
2554
- },
2555
- },
2556
- async execute(_id, { market }) {
2557
- const m = market || "A";
2558
- const result = await py("market_regime.py", ["detect", m]);
2559
- return asText(result.stdout);
2560
- },
2561
- });
2562
-
2563
- registerTool({
2564
- name: "get_market_review",
2565
- description:
2566
- "大盘复盘 — 获取市场日度复盘数据,包含指数、涨跌统计、板块排名、新闻、市场温度与策略建议。复盘类需求的首选,无需再分别调指数/统计/板块工具。数据不足时温度score及strategy_stance为null,信号unknown;warnings/data_quality说明限制",
2567
- parameters: {
2568
- type: "object",
2569
- properties: {
2570
- market: {
2571
- type: "string",
2572
- enum: ["A", "HK", "US", "all"],
2573
- description: "市场代码,默认 A。all 表示所有市场",
2574
- },
2575
- },
2576
- },
2577
- async execute(_id, { market }) {
2578
- const m = market || "A";
2579
- const result = await py("market_review.py", ["review", "--market", m]);
2580
- return asText(result.stdout);
2581
- },
2582
- });
2583
-
2584
- registerTool({
2585
- name: "run_watchlist_analysis",
2586
- description:
2587
- "批量自选股分析 — 对多只股票并行采集行情/技术/资金/风险等数据,返回汇总结果。适用于每日定时分析自选股列表",
2588
- parameters: {
2589
- type: "object",
2590
- properties: {
2591
- symbols: {
2592
- type: "string",
2593
- description: "逗号分隔的股票代码列表,如 600519,000001,300750",
2594
- },
2595
- workers: {
2596
- type: "number",
2597
- description: "并发数,默认 3(建议不超过5,避免API限流)",
2598
- },
2599
- },
2600
- required: ["symbols"],
2601
- },
2602
- async execute(_id, { symbols, workers = 3 }) {
2603
- const result = await py("watchlist.py", [
2604
- "analyze",
2605
- symbols,
2606
- "--workers",
2607
- String(workers),
2608
- ]);
2609
- return asText(result.stdout);
2610
- },
2611
- });
2612
-
2613
- registerTool({
2614
- name: "detect_anomaly",
2615
- description:
2616
- "异常/事件检测 — 一键扫描股票当前所有异动信号(MACD金叉死叉、RSI超买超卖、20日突破、放量异动、涨跌停、布林突破、KDJ极值、资金异动等),返回结构化异常列表。当日异动归因的首选;综合技术面判断用 get_technical_analysis",
2617
- parameters: {
2618
- type: "object",
2619
- properties: {
2620
- symbol: {
2621
- type: "string",
2622
- description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
2623
- },
2624
- },
2625
- required: ["symbol"],
2626
- },
2627
- async execute(_id, { symbol }) {
2628
- const result = await py("anomaly_detect.py", ["detect", symbol]);
2629
- return asText(result.stdout);
2630
- },
2631
- });
2632
-
2633
- // --- Diagnostics & Capabilities ---
2634
-
2635
- registerTool({
2636
- name: "diagnose_data_sources",
2637
- description:
2638
- "数据源诊断 — 检查当前环境各数据 provider 的包与凭据就绪情况(不探测网络可达性),输出每个市场的可用链路、缺失 env、warnings。工具拿不到数据或报错时调用排查",
2639
- parameters: {
2640
- type: "object",
2641
- properties: {
2642
- market: {
2643
- type: "string",
2644
- enum: ["A", "HK", "US", "JP", "KR", "TW", "all"],
2645
- description: "市场,默认 all",
2646
- },
2647
- },
2648
- },
2649
- async execute(_id, { market = "all" }) {
2650
- const result = await py("diagnostics.py", ["check", "--market", market]);
2651
- return asText(result.stdout);
2652
- },
2653
- });
2654
-
2655
- registerTool({
2656
- name: "get_market_capabilities",
2657
- description:
2658
- "市场能力边界 — 返回指定市场支持/不支持的工具列表。不确定某市场能否用某工具(如港股的筹码分布、美股的资金流)时先调本工具,避免调用不支持的工具后编造数据",
2659
- parameters: {
2660
- type: "object",
2661
- properties: {
2662
- market: { type: "string", enum: ["A", "HK", "US", "JP", "KR", "TW"], description: "市场代码" },
2663
- symbol: { type: "string", description: "股票代码(自动识别市场,与 market 二选一)" },
2664
- },
2665
- },
2666
- async execute(_id, { market, symbol }) {
2667
- const args = symbol
2668
- ? ["get", "--symbol", symbol]
2669
- : ["get", "--market", market || "A"];
2670
- const result = await py("capabilities.py", args);
2671
- return asText(result.stdout);
2672
- },
2673
- });
2674
-
2675
- // --- Report Rendering ---
2676
-
2677
- registerTool({
2678
- name: "render_stock_report",
2679
- description:
2680
- "股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full。全部分析完成后的最后一步调用。默认仅渲染;final=true表示最终回复,支持直出的宿主可原样交付并结束本轮。report可包含evidence(path/label/value/source/as_of)与data_quality(flags/limitations),brief/full均展示证据和限制。",
2681
- parameters: {
2682
- type: "object",
2683
- properties: {
2684
- final: { type: "boolean", description: "最终回复标记,默认false;保存附件或继续分析时保持false" },
2685
- report: {
2686
- type: "object",
2687
- description: "结构化股票报告 JSON",
2688
- },
2689
- template: {
2690
- type: "string",
2691
- enum: ["brief", "full"],
2692
- description: "模板类型,默认 full",
2693
- },
2694
- },
2695
- required: ["report"],
2696
- },
2697
- async execute(_id, { report, template = "full", final = false }) {
2698
- const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
2699
- const result = await py("report_renderer.py", [
2700
- "stock",
2701
- "--template",
2702
- template,
2703
- "--input-b64",
2704
- b64,
2705
- ...(final ? ["--final"] : []),
2706
- ]);
2707
- return asText(result.stdout);
2708
- },
2709
- });
2710
-
2711
- registerTool({
2712
- name: "render_market_report",
2713
- description:
2714
- "大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json 为准。save=true 时把报告对象追加归档到本地 JSONL(默认不保存不推送),纵向对比用 get_review_history;final=true仅用于最终回复,保存附件或继续分析时保持false",
2715
- parameters: {
2716
- type: "object",
2717
- properties: {
2718
- final: { type: "boolean", description: "最终回复标记,默认false;保存附件或继续分析时保持false" },
2719
- report: { type: "object", description: "结构化市场复盘" },
2720
- save: { type: "boolean", description: "是否归档到本地复盘 JSONL 存储,默认 false" },
2721
- },
2722
- required: ["report"],
2723
- },
2724
- async execute(_id, { report, save, final = false }) {
2725
- const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
2726
- const result = await py("report_renderer.py", [
2727
- "market",
2728
- "--input-b64",
2729
- b64,
2730
- ...(final ? ["--final"] : []),
2731
- ...(save ? ["--save"] : []),
2732
- ]);
2733
- return asText(result.stdout);
2734
- },
2735
- });
2736
-
2737
- registerTool({
2738
- name: "get_review_history",
2739
- description:
2740
- "复盘归档历史 — 读取本地 JSONL 归档的最近 N 条市场复盘(最新在前),用于纵向对比(温度/姿态/主线变化)。归档由 render_market_report 的 save=true 写入,空存档返回空列表",
2741
- parameters: {
2742
- type: "object",
2743
- properties: {
2744
- limit: { type: "number", description: "返回条数,默认 10" },
2745
- },
2746
- },
2747
- async execute(_id, { limit = 10 }) {
2748
- const result = await py("market_review.py", ["history", "--limit", String(limit)]);
2749
- return asText(result.stdout);
2750
- },
2751
- });
2752
-
2753
- // --- Watchlist / Position / Alert Context ---
2754
-
2755
- registerTool({
2756
- name: "build_watchlist_context",
2757
- description:
2758
- "自选股上下文包 — 对多只股票输出评分/趋势/异常/风险/建议 next_tools 的 agent 友好摘要。宿主 agent 决定如何写日报或深入分析。异动检查失败时anomaly_status=unavailable、anomaly_count=null,保留anomaly_error/warnings;汇总计入partial",
2759
- parameters: {
2760
- type: "object",
2761
- properties: {
2762
- symbols: { type: "string", description: "逗号分隔的股票代码列表" },
2763
- include_market_review: {
2764
- type: "boolean",
2765
- description: "是否附带各市场复盘,默认 false",
2766
- },
2767
- workers: { type: "number", description: "并发数,默认 3" },
2768
- },
2769
- required: ["symbols"],
2770
- },
2771
- async execute(_id, { symbols, include_market_review = false, workers = 3 }) {
2772
- const result = await py("watchlist_context.py", [
2773
- "build",
2774
- symbols,
2775
- "--workers",
2776
- String(workers),
2777
- ...(include_market_review ? ["--include-market-review"] : []),
2778
- ]);
2779
- return asText(result.stdout);
2780
- },
2781
- });
2782
-
2783
- registerTool({
2784
- name: "analyze_position_context",
2785
- description:
2786
- "持仓上下文分析 — 输入成本/仓位/止损止盈,结合现价和技术位输出浮盈亏、离止损距离、风险级别、操作建议。无状态、不存账户",
2787
- parameters: {
2788
- type: "object",
2789
- properties: {
2790
- symbol: { type: "string", description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" },
2791
- cost: { type: "number", description: "成本价" },
2792
- quantity: { type: "number", description: "持仓数量" },
2793
- stop_loss: { type: "number", description: "止损价" },
2794
- take_profit: { type: "number", description: "止盈价" },
2795
- },
2796
- required: ["symbol", "cost", "quantity"],
2797
- },
2798
- async execute(_id, { symbol, cost, quantity, stop_loss, take_profit }) {
2799
- const result = await py("position_context.py", [
2800
- "analyze",
2801
- symbol,
2802
- "--cost",
2803
- String(cost),
2804
- "--quantity",
2805
- String(quantity),
2806
- ...(stop_loss !== undefined ? ["--stop-loss", String(stop_loss)] : []),
2807
- ...(take_profit !== undefined ? ["--take-profit", String(take_profit)] : []),
2808
- ]);
2809
- return asText(result.stdout);
2810
- },
2811
- });
2812
-
2813
- registerTool({
2814
- name: "check_alert_rules",
2815
- description:
2816
- "无状态告警规则检查 — 传入规则数组,返回当前是否触发。规则类型: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不代表检查成功",
2817
- parameters: {
2818
- type: "object",
2819
- properties: {
2820
- symbol: { type: "string", description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" },
2821
- rules: {
2822
- type: "array",
2823
- description: "规则列表,每项 { type, value }",
2824
- items: {
2825
- type: "object",
2826
- properties: {
2827
- type: { type: "string" },
2828
- value: {},
2829
- },
2830
- },
2831
- },
2832
- },
2833
- required: ["symbol", "rules"],
2834
- },
2835
- async execute(_id, { symbol, rules }) {
2836
- const b64 = Buffer.from(JSON.stringify(rules), "utf-8").toString("base64");
2837
- const result = await py("alert_rules.py", ["check", symbol, "--rules-b64", b64]);
2838
- return asText(result.stdout);
2839
- },
2840
- });
2841
-
2842
- registerTool({
2843
- name: "record_signal",
2844
- description:
2845
- "记录一条 AI 分析建议信号(方向/入场价/目标价/止损价/持有期限),供后续胜率评估。信号持久化在本地 JSONL($STOCK_SIGNAL_STORE 或 ~/.stock-analysis/signals.jsonl),宿主 Agent 自行决定何时 record/evaluate",
2846
- parameters: {
2847
- type: "object",
2848
- properties: {
2849
- symbol: { type: "string", description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" },
2850
- direction: {
2851
- type: "string",
2852
- enum: ["buy", "sell"],
2853
- description: "建议方向",
2854
- },
2855
- entry_price: { type: "number", description: "入场价(可选)" },
2856
- target_price: { type: "number", description: "目标价(可选)" },
2857
- stop_price: { type: "number", description: "止损价(可选)" },
2858
- horizon_days: { type: "number", description: "持有期限(交易日),默认 10" },
2859
- source: { type: "string", description: "信号来源(如触发该建议的 skill 名)" },
2860
- note: { type: "string", description: "备注(可选)" },
2861
- },
2862
- required: ["symbol", "direction"],
2863
- },
2864
- async execute(_id, { symbol, direction, entry_price, target_price, stop_price, horizon_days = 10, source, note }) {
2865
- const result = await py("signal_tracker.py", [
2866
- "record",
2867
- symbol,
2868
- "--direction",
2869
- direction,
2870
- ...(entry_price !== undefined ? ["--entry-price", String(entry_price)] : []),
2871
- ...(target_price !== undefined ? ["--target-price", String(target_price)] : []),
2872
- ...(stop_price !== undefined ? ["--stop-price", String(stop_price)] : []),
2873
- "--horizon-days",
2874
- String(horizon_days),
2875
- ...(source ? ["--source", source] : []),
2876
- ...(note ? ["--note", note] : []),
2877
- ]);
2878
- return asText(result.stdout);
2879
- },
2880
- });
2881
-
2882
- registerTool({
2883
- name: "evaluate_signals",
2884
- description:
2885
- "评估到期信号:拉取记录日之后的日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说明未处理记录,下次可重试",
2886
- parameters: {
2887
- type: "object",
2888
- properties: {
2889
- symbol: { type: "string", description: "股票代码(可选,只评估该股的信号)" },
2890
- },
2891
- },
2892
- async execute(_id, { symbol }) {
2893
- const result = await py("signal_tracker.py", [
2894
- "evaluate",
2895
- ...(symbol ? ["--symbol", symbol] : []),
2896
- ]);
2897
- return asText(result.stdout);
2898
- },
2899
- });
2900
-
2901
- registerTool({
2902
- name: "get_signal_summary",
2903
- description:
2904
- "信号胜率汇总(可按 source/symbol/status 过滤):胜率、平均收益、结果分布与明细。by_source附avg_return_pct、return_samples和sample_warning;仅观察性复盘,样本少不能认定策略有效。",
2905
- parameters: {
2906
- type: "object",
2907
- properties: {
2908
- source: { type: "string", description: "按信号来源过滤(可选)" },
2909
- symbol: { type: "string", description: "按股票代码过滤(可选)" },
2910
- status: {
2911
- type: "string",
2912
- enum: ["open", "closed", "all"],
2913
- description: "open=未结算,closed=已结算,all=全部(默认)",
2914
- },
2915
- },
2916
- },
2917
- async execute(_id, { source, symbol, status = "all" }) {
2918
- const result = await py("signal_tracker.py", [
2919
- "summary",
2920
- ...(source ? ["--source", source] : []),
2921
- ...(symbol ? ["--symbol", symbol] : []),
2922
- "--status",
2923
- status,
2924
- ]);
2925
- return asText(result.stdout);
2926
- },
2927
- });
2928
-
2929
- registerTool({
2930
- name: "parse_stock_list",
2931
- description:
2932
- "自选股/文本导入解析 — 从自然语言、CSV、Markdown 表格提取股票,自动识别 A 股 6 位代码、港股 xxxxx.HK、美股 ticker、日股 xxxx.T、韩股 xxxxxx.KS/KQ、台股 xxxx.TW,并调用 name_resolver 处理中文股票名",
2933
- parameters: {
2934
- type: "object",
2935
- properties: {
2936
- text: { type: "string", description: "待解析的文本" },
2937
- },
2938
- required: ["text"],
2939
- },
2940
- async execute(_id, { text }) {
2941
- const b64 = Buffer.from(String(text), "utf-8").toString("base64");
2942
- const result = await py("import_parser.py", ["parse", "--text-b64", b64]);
2943
- return asText(result.stdout);
2944
- },
2945
- });
109
+ });
110
+ }
2946
111
 
2947
112
  // --- Skill Discovery ---
2948
113
 
114
+ // Same dynamic scan as dsh/hermes: every skills/<name>/SKILL.md is discovered without a list edit.
2949
115
  pi.on("resources_discover", () => ({
2950
- skillPaths: [
2951
- `${baseDir}/skills/stock-analysis/SKILL.md`,
2952
- `${baseDir}/skills/stock-screener/SKILL.md`,
2953
- `${baseDir}/skills/strategy-backtest/SKILL.md`,
2954
- `${baseDir}/skills/sector-rotation/SKILL.md`,
2955
- `${baseDir}/skills/bull-trend/SKILL.md`,
2956
- `${baseDir}/skills/shrink-pullback/SKILL.md`,
2957
- `${baseDir}/skills/ma-crossover/SKILL.md`,
2958
- `${baseDir}/skills/volume-breakout/SKILL.md`,
2959
- `${baseDir}/skills/bottom-volume/SKILL.md`,
2960
- `${baseDir}/skills/dragon-head/SKILL.md`,
2961
- `${baseDir}/skills/chan-theory/SKILL.md`,
2962
- `${baseDir}/skills/wave-theory/SKILL.md`,
2963
- `${baseDir}/skills/box-oscillation/SKILL.md`,
2964
- `${baseDir}/skills/emotion-cycle/SKILL.md`,
2965
- `${baseDir}/skills/one-yang-three-yin/SKILL.md`,
2966
- `${baseDir}/skills/wisburg-research/SKILL.md`,
2967
- `${baseDir}/skills/market-review/SKILL.md`,
2968
- `${baseDir}/skills/event-driven/SKILL.md`,
2969
- `${baseDir}/skills/expectation-repricing/SKILL.md`,
2970
- `${baseDir}/skills/growth-quality/SKILL.md`,
2971
- `${baseDir}/skills/hot-theme/SKILL.md`,
2972
- ],
116
+ skillPaths: readdirSync(`${baseDir}/skills`, { withFileTypes: true })
117
+ .filter(entry => entry.isDirectory() && existsSync(`${baseDir}/skills/${entry.name}/SKILL.md`))
118
+ .map(entry => `${baseDir}/skills/${entry.name}/SKILL.md`),
2973
119
  }));
2974
120
  };