@v587d/capital-generation 0.0.0-stage → 2.6.1

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 (117) hide show
  1. package/CHANGELOG.md +814 -0
  2. package/LICENSE +21 -0
  3. package/README.md +118 -2
  4. package/assets/cg-icon.png +0 -0
  5. package/capital-config/client.js +28 -0
  6. package/capital-config/client.src.cjs +388 -0
  7. package/capital-config/index.js +113 -0
  8. package/capital-config/package.json +36 -0
  9. package/capital-watchlist/client.js +182 -0
  10. package/capital-watchlist/client.src.cjs +1229 -0
  11. package/capital-watchlist/index.js +772 -0
  12. package/capital-watchlist/package.json +37 -0
  13. package/chart-ui/README.md +112 -0
  14. package/chart-ui/client.js +16 -0
  15. package/chart-ui/client.src.cjs +126 -0
  16. package/chart-ui/index.js +205 -0
  17. package/chart-ui/package.json +30 -0
  18. package/cordis.patch.yml +72 -0
  19. package/lib/agents/bash-guard.d.ts +55 -0
  20. package/lib/agents/bash-guard.js +162 -0
  21. package/lib/agents/root-tool-policy.d.ts +164 -0
  22. package/lib/agents/root-tool-policy.js +309 -0
  23. package/lib/chart/artifact-ref.d.ts +65 -0
  24. package/lib/chart/artifact-ref.js +107 -0
  25. package/lib/chart/downsample.d.ts +8 -0
  26. package/lib/chart/downsample.js +53 -0
  27. package/lib/chart/errors.d.ts +16 -0
  28. package/lib/chart/errors.js +15 -0
  29. package/lib/chart/events.d.ts +120 -0
  30. package/lib/chart/events.js +471 -0
  31. package/lib/chart/html.d.ts +21 -0
  32. package/lib/chart/html.js +154 -0
  33. package/lib/chart/runtime.d.ts +20 -0
  34. package/lib/chart/runtime.js +270 -0
  35. package/lib/chart/series.d.ts +102 -0
  36. package/lib/chart/series.js +424 -0
  37. package/lib/chart/source-token.d.ts +64 -0
  38. package/lib/chart/source-token.js +217 -0
  39. package/lib/chart/spec.d.ts +58 -0
  40. package/lib/chart/spec.js +265 -0
  41. package/lib/chart/tool.d.ts +86 -0
  42. package/lib/chart/tool.js +288 -0
  43. package/lib/chart/vendor/LICENSE +201 -0
  44. package/lib/chart/vendor/VERSION.json +8 -0
  45. package/lib/chart/vendor/lightweight-charts.standalone.production.js +7 -0
  46. package/lib/data-collector/args.d.ts +38 -0
  47. package/lib/data-collector/args.js +114 -0
  48. package/lib/data-collector/dataset-tools.d.ts +3 -0
  49. package/lib/data-collector/dataset-tools.js +421 -0
  50. package/lib/data-collector/describe.d.ts +99 -0
  51. package/lib/data-collector/describe.js +256 -0
  52. package/lib/data-collector/hub.d.ts +187 -0
  53. package/lib/data-collector/hub.js +469 -0
  54. package/lib/data-collector/query-time.d.ts +58 -0
  55. package/lib/data-collector/query-time.js +101 -0
  56. package/lib/data-collector/query.d.ts +57 -0
  57. package/lib/data-collector/query.js +473 -0
  58. package/lib/data-collector/store.d.ts +499 -0
  59. package/lib/data-collector/store.js +1486 -0
  60. package/lib/data-collector/time-axis.d.ts +169 -0
  61. package/lib/data-collector/time-axis.js +419 -0
  62. package/lib/data-collector/tools.d.ts +32 -0
  63. package/lib/data-collector/tools.js +216 -0
  64. package/lib/index.d.ts +275 -0
  65. package/lib/index.js +458 -0
  66. package/lib/net/eastmoney-client.d.ts +104 -0
  67. package/lib/net/eastmoney-client.js +118 -0
  68. package/lib/net/throttle.d.ts +16 -0
  69. package/lib/net/throttle.js +34 -0
  70. package/lib/ocr/client.d.ts +82 -0
  71. package/lib/ocr/client.js +281 -0
  72. package/lib/ocr/markdown.d.ts +75 -0
  73. package/lib/ocr/markdown.js +209 -0
  74. package/lib/ocr/store.d.ts +119 -0
  75. package/lib/ocr/store.js +226 -0
  76. package/lib/sources/eastmoney-http.d.ts +2 -0
  77. package/lib/sources/eastmoney-http.js +1253 -0
  78. package/lib/sources/fuyao-core.d.ts +52 -0
  79. package/lib/sources/fuyao-core.js +96 -0
  80. package/lib/sources/fuyao-rest.d.ts +14 -0
  81. package/lib/sources/fuyao-rest.js +2057 -0
  82. package/lib/sources/security-code.d.ts +27 -0
  83. package/lib/sources/security-code.js +104 -0
  84. package/lib/sources/security-identity.d.ts +24 -0
  85. package/lib/sources/security-identity.js +89 -0
  86. package/lib/sources/tencent-http.d.ts +2 -0
  87. package/lib/sources/tencent-http.js +1053 -0
  88. package/lib/sources/wind-mcp.d.ts +8 -0
  89. package/lib/sources/wind-mcp.js +593 -0
  90. package/lib/time/tools.d.ts +74 -0
  91. package/lib/time/tools.js +464 -0
  92. package/lib/tool-exec.d.ts +29 -0
  93. package/lib/tool-exec.js +17 -0
  94. package/lib/web-retriever/engines.d.ts +61 -0
  95. package/lib/web-retriever/engines.js +202 -0
  96. package/lib/web-retriever/html-markdown.d.ts +50 -0
  97. package/lib/web-retriever/html-markdown.js +321 -0
  98. package/lib/web-retriever/local-fetch.d.ts +121 -0
  99. package/lib/web-retriever/local-fetch.js +562 -0
  100. package/lib/web-retriever/retriever.d.ts +58 -0
  101. package/lib/web-retriever/retriever.js +94 -0
  102. package/lib/web-retriever/sources.d.ts +235 -0
  103. package/lib/web-retriever/sources.js +961 -0
  104. package/lib/web-retriever/tools.d.ts +50 -0
  105. package/lib/web-retriever/tools.js +1029 -0
  106. package/lib/web-retriever/wind-client.d.ts +69 -0
  107. package/lib/web-retriever/wind-client.js +311 -0
  108. package/locale/en.json +6 -0
  109. package/locale/zh.json +6 -0
  110. package/package.json +84 -4
  111. package/preset/capital-generation/README.md +161 -0
  112. package/preset/capital-generation/agent.patch.yml +509 -0
  113. package/preset/capital-generation/skills/capital-chart-protocol/SKILL.md +137 -0
  114. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +416 -0
  115. package/preset/capital-generation/skills/capital-orchestration/SKILL.md +174 -0
  116. package/preset/capital-generation/skills/capital-visualization-protocol/SKILL.md +296 -0
  117. package/preset/capital-generation/skills/capital-web-protocol/SKILL.md +240 -0
@@ -0,0 +1,27 @@
1
+ export type SecurityMarket = 'SH' | 'SZ' | 'BJ';
2
+ export interface SecurityCode {
3
+ digits: string;
4
+ market: SecurityMarket;
5
+ canonical: string;
6
+ tencentSymbol: string;
7
+ isIndex: boolean;
8
+ }
9
+ /**
10
+ * Parse an A-share/ETF/index code without dropping exchange information.
11
+ * Bare 000xxx codes are rejected because they are ambiguous (e.g. 000001).
12
+ */
13
+ export declare function parseSecurityCode(value: unknown, name?: string): SecurityCode;
14
+ /**
15
+ * 检索面的代码口径:只回答"把这串写法归一成 6 位数字"。
16
+ *
17
+ * 与 `parseSecurityCode` 的分工是刻意的:数据面必须消歧(裸 `000001` 在指数与个股之间
18
+ * 有歧义),而**具名来源自己会回答"这台机器上有没有这只票"**——cninfo 只覆盖深市、
19
+ * sseinfo 只覆盖沪市,越界返回 0 条并带 note 是真事实,不能在这一层把它拒掉。
20
+ * 所以裸 `000001`(平安银行)在这里合法,`SH600519` / `600519.SH` 也合法(东财研报库
21
+ * 实测只认纯数字,带前缀返回 0 条,因此归一化属于工具职责而不是模型的记性)。
22
+ */
23
+ export declare function bareAshareDigits(value: unknown, name?: string): string;
24
+ /** Normalize a list while preserving first-seen order and rejecting duplicates after normalization. */
25
+ export declare function normalizeSecurityCodes(value: unknown, name?: string, maximum?: number): SecurityCode[];
26
+ export declare function requireTencentSecurity(code: SecurityCode, name?: string): SecurityCode;
27
+ export declare function isLikelyIndex(code: SecurityCode): boolean;
@@ -0,0 +1,104 @@
1
+ const CODE_PATTERN = /^(?:(sh|sz|bj)(\d{6})|(\d{6})(?:\.(sh|sz|bj|xshg|xshe))?)$/i;
2
+ const JOINQUANT_MARKETS = { xshg: 'SH', xshe: 'SZ' };
3
+ const SH_INDEX_CODES = new Set(['000001', '000010', '000016', '000300', '000688', '000852', '000905']);
4
+ function naturalMarket(digits) {
5
+ if (digits.startsWith('92') || digits.startsWith('4') || digits.startsWith('8'))
6
+ return 'BJ';
7
+ if (digits[0] === '5' || digits[0] === '6' || digits[0] === '9')
8
+ return 'SH';
9
+ return 'SZ';
10
+ }
11
+ function explicitMarket(prefix, suffix) {
12
+ const raw = (prefix ?? suffix ?? '').toLowerCase();
13
+ if (!raw)
14
+ return undefined;
15
+ return (JOINQUANT_MARKETS[raw] ?? raw.toUpperCase());
16
+ }
17
+ function isMarket(value) {
18
+ return value === 'SH' || value === 'SZ' || value === 'BJ';
19
+ }
20
+ /**
21
+ * Parse an A-share/ETF/index code without dropping exchange information.
22
+ * Bare 000xxx codes are rejected because they are ambiguous (e.g. 000001).
23
+ */
24
+ export function parseSecurityCode(value, name = 'code') {
25
+ if (typeof value !== 'string' || value.trim().length === 0)
26
+ throw new Error(`parameter ${name} must be a security code`);
27
+ const raw = value.trim();
28
+ const match = CODE_PATTERN.exec(raw);
29
+ if (!match) {
30
+ throw new Error(`parameter ${name} must be a six-digit code with an exchange (for example 600519.SH, SH600519, or 600519.XSHG)`);
31
+ }
32
+ const digits = match[2] ?? match[3];
33
+ const market = explicitMarket(match[1], match[4]);
34
+ if (market !== undefined && !isMarket(market))
35
+ throw new Error(`parameter ${name} has an unsupported exchange in ${JSON.stringify(raw)}`);
36
+ if (market === undefined && digits.startsWith('000')) {
37
+ throw new Error(`parameter ${name} requires an explicit exchange for ambiguous 000xxx code ${digits} (use ${digits}.SH for an index or ${digits}.SZ for a stock)`);
38
+ }
39
+ const resolved = market ?? naturalMarket(digits);
40
+ if (digits.startsWith('000')) {
41
+ if (resolved === 'BJ')
42
+ throw new Error(`parameter ${name} has an invalid BJ exchange for 000xxx code ${digits}`);
43
+ }
44
+ else if (resolved !== naturalMarket(digits)) {
45
+ throw new Error(`parameter ${name} exchange conflicts with code ${digits}: expected ${naturalMarket(digits)}`);
46
+ }
47
+ const isIndex = (resolved === 'SH' && SH_INDEX_CODES.has(digits)) || (resolved === 'SZ' && digits.startsWith('399'));
48
+ return {
49
+ digits,
50
+ market: resolved,
51
+ canonical: `${digits}.${resolved}`,
52
+ tencentSymbol: `${resolved.toLowerCase()}${digits}`,
53
+ isIndex,
54
+ };
55
+ }
56
+ /**
57
+ * 检索面的代码口径:只回答"把这串写法归一成 6 位数字"。
58
+ *
59
+ * 与 `parseSecurityCode` 的分工是刻意的:数据面必须消歧(裸 `000001` 在指数与个股之间
60
+ * 有歧义),而**具名来源自己会回答"这台机器上有没有这只票"**——cninfo 只覆盖深市、
61
+ * sseinfo 只覆盖沪市,越界返回 0 条并带 note 是真事实,不能在这一层把它拒掉。
62
+ * 所以裸 `000001`(平安银行)在这里合法,`SH600519` / `600519.SH` 也合法(东财研报库
63
+ * 实测只认纯数字,带前缀返回 0 条,因此归一化属于工具职责而不是模型的记性)。
64
+ */
65
+ export function bareAshareDigits(value, name = 'code') {
66
+ if (typeof value !== 'string' || value.trim().length === 0) {
67
+ throw new Error(`parameter ${name} must be a six-digit A-share code (600519 / SH600519 / 600519.SH)`);
68
+ }
69
+ const match = CODE_PATTERN.exec(value.trim());
70
+ if (match === null) {
71
+ throw new Error(`parameter ${name} must be a six-digit A-share code (接受 600519 / SH600519 / 600519.SH,收到 ${JSON.stringify(value)})`);
72
+ }
73
+ return match[2] ?? match[3];
74
+ }
75
+ /** Normalize a list while preserving first-seen order and rejecting duplicates after normalization. */
76
+ export function normalizeSecurityCodes(value, name = 'codes', maximum = 50) {
77
+ const rawValues = Array.isArray(value)
78
+ ? value
79
+ : typeof value === 'string'
80
+ ? value.split(',').map((item) => item.trim()).filter(Boolean)
81
+ : undefined;
82
+ if (!rawValues || rawValues.length === 0)
83
+ throw new Error(`parameter ${name} must contain at least one security code`);
84
+ if (rawValues.length > maximum)
85
+ throw new Error(`parameter ${name} accepts at most ${maximum} codes`);
86
+ const seen = new Set();
87
+ const result = [];
88
+ for (const item of rawValues) {
89
+ const code = parseSecurityCode(item, name);
90
+ if (!seen.has(code.canonical)) {
91
+ seen.add(code.canonical);
92
+ result.push(code);
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ export function requireTencentSecurity(code, name = 'code') {
98
+ if (code.market === 'BJ')
99
+ throw new Error(`parameter ${name} is a BJ code; Tencent public market endpoints currently support SH/SZ only`);
100
+ return code;
101
+ }
102
+ export function isLikelyIndex(code) {
103
+ return code.isIndex;
104
+ }
@@ -0,0 +1,24 @@
1
+ export type EastmoneyMarket = 'SH' | 'SZ' | 'BJ';
2
+ export interface EastmoneySecurityIdentity {
3
+ thscode: string;
4
+ ticker: string;
5
+ eastmoney_code: string;
6
+ eastmoney_market: EastmoneyMarket;
7
+ }
8
+ /**
9
+ * Resolve Eastmoney's provider identifiers without guessing a market from digits.
10
+ * `market` is mandatory for a bare SECURITY_CODE; `secid` carries its own market.
11
+ */
12
+ export declare function normalizeEastmoneySecurityIdentity(input: {
13
+ secucode?: unknown;
14
+ security_code?: unknown;
15
+ market?: unknown;
16
+ secid?: unknown;
17
+ }): EastmoneySecurityIdentity;
18
+ export declare function normalizeEastmoneyAshareIdentity(value: unknown): EastmoneySecurityIdentity;
19
+ export interface EastmoneyBoardIdentity {
20
+ board_code: string;
21
+ board_name: string;
22
+ board_type: 'industry' | 'concept' | 'region';
23
+ }
24
+ export declare function normalizeEastmoneyBoardIdentity(codeValue: unknown, nameValue: unknown, boardType: EastmoneyBoardIdentity['board_type']): EastmoneyBoardIdentity;
@@ -0,0 +1,89 @@
1
+ import { parseSecurityCode } from './security-code.js';
2
+ /**
3
+ * secid 市场码(实测于 2026-09-24,`push2.eastmoney.com/api/qt/stock/get`):
4
+ * `1.` = 沪;`0.` = **深市与北交所共用**(`0.920982`、`0.430047` 返回 rc=0,`2.*` 一律 rc=100)。
5
+ * 因此 `0.` 的 BJ/SZ 由数字前缀区分(4/8/92 为北交所),与 `normalizeEastmoneyAshareIdentity`
6
+ * 共用 `marketFromAshareDigits` 的同一份规则(§9.7:一条知识一个实现)。
7
+ */
8
+ const SECID_MARKET_BY_PREFIX = { '1': 'SH', '0': 'SZ_OR_BJ' };
9
+ function marketFromAshareDigits(digits) {
10
+ if (/^(?:4|8|92)/u.test(digits))
11
+ return 'BJ';
12
+ if (/^(?:6|9)/u.test(digits))
13
+ return 'SH';
14
+ return 'SZ';
15
+ }
16
+ function text(value, name) {
17
+ if (typeof value !== 'string' || value.trim().length === 0)
18
+ throw new Error(`${name} must be a non-empty string`);
19
+ return value.trim();
20
+ }
21
+ function market(value, name = 'market') {
22
+ const raw = text(value, name).toUpperCase();
23
+ if (raw === 'SH' || raw === 'SSE' || raw === '1')
24
+ return 'SH';
25
+ if (raw === 'SZ' || raw === 'SZSE' || raw === '0')
26
+ return 'SZ';
27
+ if (raw === 'BJ' || raw === 'BSE' || raw === '2')
28
+ return 'BJ';
29
+ throw new Error(`${name} must be SH, SZ, or BJ`);
30
+ }
31
+ function code(value, name) {
32
+ const raw = text(value, name).toUpperCase();
33
+ if (/^\d{6}\.(?:SH|SZ|BJ)$/.test(raw))
34
+ return raw;
35
+ if (/^(?:SH|SZ|BJ)\d{6}$/.test(raw))
36
+ return `${raw.slice(2)}.${raw.slice(0, 2)}`;
37
+ if (/^\d{6}$/.test(raw))
38
+ return raw;
39
+ throw new Error(`${name} must be a six-digit code, SECUCODE, or market-prefixed code`);
40
+ }
41
+ /**
42
+ * Resolve Eastmoney's provider identifiers without guessing a market from digits.
43
+ * `market` is mandatory for a bare SECURITY_CODE; `secid` carries its own market.
44
+ */
45
+ export function normalizeEastmoneySecurityIdentity(input) {
46
+ const explicit = input.secucode ?? input.security_code;
47
+ if (explicit !== undefined) {
48
+ const normalized = code(explicit, 'security_code');
49
+ const parsed = normalized.includes('.') ? parseSecurityCode(normalized, 'security_code') : undefined;
50
+ if (!parsed && input.market === undefined)
51
+ throw new Error('security_code requires an explicit market');
52
+ const resolvedMarket = parsed?.market ?? market(input.market);
53
+ const digits = parsed?.digits ?? normalized;
54
+ if (parsed && input.market !== undefined && resolvedMarket !== market(input.market))
55
+ throw new Error('security_code conflicts with market');
56
+ return {
57
+ thscode: `${digits}.${resolvedMarket}`,
58
+ ticker: digits,
59
+ eastmoney_code: digits,
60
+ eastmoney_market: resolvedMarket,
61
+ };
62
+ }
63
+ const rawSecid = text(input.secid, 'secid');
64
+ const match = /^(0|1)\.(\d{6})$/.exec(rawSecid);
65
+ if (!match)
66
+ throw new Error('secid must have the form 0.000001 or 1.600519 (北交所同为 0.)');
67
+ const digits = match[2];
68
+ const resolvedMarket = SECID_MARKET_BY_PREFIX[match[1]] === 'SH' ? 'SH' : marketFromAshareDigits(digits);
69
+ return {
70
+ thscode: `${digits}.${resolvedMarket}`,
71
+ ticker: digits,
72
+ eastmoney_code: digits,
73
+ eastmoney_market: resolvedMarket,
74
+ };
75
+ }
76
+ export function normalizeEastmoneyAshareIdentity(value) {
77
+ const raw = text(value, 'security_code').toUpperCase();
78
+ const digits = raw.includes('.') ? raw.slice(0, 6) : raw;
79
+ if (!/^\d{6}$/.test(digits))
80
+ throw new Error('security_code must be a six-digit A-share code');
81
+ const resolvedMarket = marketFromAshareDigits(digits);
82
+ return { thscode: `${digits}.${resolvedMarket}`, ticker: digits, eastmoney_code: digits, eastmoney_market: resolvedMarket };
83
+ }
84
+ export function normalizeEastmoneyBoardIdentity(codeValue, nameValue, boardType) {
85
+ const board_code = text(codeValue, 'board_code').toUpperCase();
86
+ if (!/^BK\d{4}$/.test(board_code))
87
+ throw new Error(`board_code must be BK followed by four digits (received ${JSON.stringify(board_code)})`);
88
+ return { board_code, board_name: text(nameValue, 'board_name'), board_type: boardType };
89
+ }
@@ -0,0 +1,2 @@
1
+ import type { DataSource } from '../data-collector/hub.js';
2
+ export declare function createTencentSources(): DataSource[];