@v587d/capital-generation 2.22.0 → 2.24.0

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.
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Catalog shard key for every model-visible capability. One table, not one field per
3
+ * source: the nine shards must be audited together, and a missing production entry is a
4
+ * test failure rather than a capability that silently falls into `meta`.
5
+ */
6
+ export const CATALOG_TOPICS = [
7
+ 'quote',
8
+ 'flow',
9
+ 'financials',
10
+ 'fund',
11
+ 'events',
12
+ 'macro',
13
+ 'futures',
14
+ 'cross',
15
+ 'meta',
16
+ ];
17
+ export const CATALOG_TOPIC_LABELS = {
18
+ quote: '行情与指数',
19
+ flow: '资金与筹码',
20
+ financials: '财务与估值',
21
+ fund: '基金',
22
+ events: '公告与公司行为',
23
+ macro: '宏观与利率',
24
+ futures: '期货与商品',
25
+ cross: '跨境与全球',
26
+ meta: '日历与元数据',
27
+ };
28
+ /**
29
+ * Keep this table explicit. Deriving a topic from a name prefix looks convenient until
30
+ * `dragon_tiger` lands in `quote` or `eastmoney_mutual_flow` lands in `flow` instead of
31
+ * `cross`; both are discovery-time failures, not cosmetic mislabels.
32
+ */
33
+ export const CATALOG_TAXONOMY = {
34
+ // quote
35
+ 'auction': 'quote',
36
+ 'eastmoney_sector_rotation': 'quote',
37
+ 'ftshare_ashare_quote': 'quote',
38
+ 'ftshare_convertible_bond_kline': 'quote',
39
+ 'ftshare_daily_kline_snapshot': 'quote',
40
+ 'ftshare_limit_price': 'quote',
41
+ 'ftshare_market_breadth': 'quote',
42
+ 'ftshare_prev_close': 'quote',
43
+ 'history': 'quote',
44
+ 'index_history': 'quote',
45
+ 'index_quote': 'quote',
46
+ 'quote': 'quote',
47
+ 'tencent_hk_index_quote': 'quote',
48
+ 'tencent_hk_kline': 'quote',
49
+ 'tencent_hk_quote': 'quote',
50
+ 'tencent_kline': 'quote',
51
+ 'tencent_quote': 'quote',
52
+ 'tencent_ticks': 'quote',
53
+ 'tencent_us_index_quote': 'quote',
54
+ 'tencent_us_kline': 'quote',
55
+ 'tencent_us_quote': 'quote',
56
+ // flow
57
+ 'anomaly_list': 'flow',
58
+ 'anomaly_stock': 'flow',
59
+ 'auction_benchmark': 'flow',
60
+ 'dragon_tiger': 'flow',
61
+ 'eastmoney_cashflow_rotation': 'flow',
62
+ 'eastmoney_holder_number_snapshot': 'flow',
63
+ 'eastmoney_main_capital_snapshot': 'flow',
64
+ 'eastmoney_margin_trading': 'flow',
65
+ 'eastmoney_top_buy_sell_market': 'flow',
66
+ 'eastmoney_top_buy_sell_ticker': 'flow',
67
+ 'ftshare_block_trades': 'flow',
68
+ 'ftshare_concept_daily_flow': 'flow',
69
+ 'ftshare_dragon_tiger_seats': 'flow',
70
+ 'ftshare_holder_number': 'flow',
71
+ 'ftshare_industry_daily_flow': 'flow',
72
+ 'ftshare_main_capital_flow': 'flow',
73
+ 'ftshare_stock_daily_flow': 'flow',
74
+ 'hot_stock_history': 'flow',
75
+ 'hot_stock_list': 'flow',
76
+ 'hot_stock_rank_trend': 'flow',
77
+ 'limit_break_pool': 'flow',
78
+ 'limit_down_pool': 'flow',
79
+ 'limit_up_ladder': 'flow',
80
+ 'limit_up_pool': 'flow',
81
+ 'skyrocket_list': 'flow',
82
+ // financials
83
+ 'balance_sheet': 'financials',
84
+ 'cash_flow': 'financials',
85
+ 'eastmoney_convertible_bond_list': 'financials',
86
+ 'financial_indicators': 'financials',
87
+ 'ftshare_performance_express': 'financials',
88
+ 'ftshare_performance_forecast': 'financials',
89
+ 'ftshare_sw_industry_metrics': 'financials',
90
+ 'ftshare_sw_industry_overview': 'financials',
91
+ 'income_statement': 'financials',
92
+ 'valuation': 'financials',
93
+ // fund
94
+ 'fund_asset_allocation': 'fund',
95
+ 'fund_backtest': 'fund',
96
+ 'fund_backtest_indicators': 'fund',
97
+ 'fund_balance': 'fund',
98
+ 'fund_bond_history': 'fund',
99
+ 'fund_bond_report_dates': 'fund',
100
+ 'fund_company': 'fund',
101
+ 'fund_diagnostics': 'fund',
102
+ 'fund_dividends': 'fund',
103
+ 'fund_drawdowns': 'fund',
104
+ 'fund_financial_indicators': 'fund',
105
+ 'fund_history': 'fund',
106
+ 'fund_holders': 'fund',
107
+ 'fund_holdings': 'fund',
108
+ 'fund_income': 'fund',
109
+ 'fund_indicator_line': 'fund',
110
+ 'fund_indicator_table': 'fund',
111
+ 'fund_industry_allocation': 'fund',
112
+ 'fund_manager': 'fund',
113
+ 'fund_manager_experience': 'fund',
114
+ 'fund_manager_performance': 'fund',
115
+ 'fund_manager_style': 'fund',
116
+ 'fund_nav': 'fund',
117
+ 'fund_offerings': 'fund',
118
+ 'fund_performance_history': 'fund',
119
+ 'fund_profile': 'fund',
120
+ 'fund_quota_list': 'fund',
121
+ 'fund_quota_summary': 'fund',
122
+ 'fund_quote': 'fund',
123
+ 'fund_returns': 'fund',
124
+ 'fund_stock_history': 'fund',
125
+ 'fund_stock_report_dates': 'fund',
126
+ 'fund_top_holders': 'fund',
127
+ // events
128
+ 'corporate_actions': 'events',
129
+ 'eastmoney_dividend_plan': 'events',
130
+ 'eastmoney_lockup_expiry': 'events',
131
+ // macro
132
+ 'eastmoney_cpi': 'macro',
133
+ 'eastmoney_customs_trade': 'macro',
134
+ 'eastmoney_deposit_reserve': 'macro',
135
+ 'eastmoney_gdp': 'macro',
136
+ 'eastmoney_money_supply': 'macro',
137
+ 'eastmoney_pmi': 'macro',
138
+ 'eastmoney_ppi': 'macro',
139
+ 'eastmoney_retail_sales': 'macro',
140
+ 'eastmoney_rmb_loan': 'macro',
141
+ 'ftshare_chinabond_yield': 'macro',
142
+ 'ftshare_hibor': 'macro',
143
+ 'ftshare_lpr': 'macro',
144
+ 'ftshare_shibor': 'macro',
145
+ 'wind_edb_query': 'macro',
146
+ 'wind_edb_search': 'macro',
147
+ // futures
148
+ 'ftshare_bullion_price': 'futures',
149
+ 'ftshare_futures_contract_detail': 'futures',
150
+ 'ftshare_futures_contracts': 'futures',
151
+ 'ftshare_futures_index_kline': 'futures',
152
+ 'ftshare_futures_kline': 'futures',
153
+ 'ftshare_futures_limit_price': 'futures',
154
+ 'ftshare_futures_member_rank': 'futures',
155
+ 'ftshare_futures_settle': 'futures',
156
+ 'ftshare_futures_warrant': 'futures',
157
+ 'ftshare_futures_weekly': 'futures',
158
+ // cross
159
+ 'eastmoney_mutual_flow': 'cross',
160
+ 'eastmoney_mutual_quota': 'cross',
161
+ 'ftshare_financial_calendar': 'cross',
162
+ 'ftshare_trading_calendar': 'cross',
163
+ 'wind_stock_kline': 'cross',
164
+ // meta
165
+ 'ftshare_index_weight': 'meta',
166
+ 'index_catalog': 'meta',
167
+ 'index_constituents': 'meta',
168
+ 'ticker_list': 'meta',
169
+ 'ticker_search': 'meta',
170
+ 'trading_calendar': 'meta',
171
+ };
172
+ /** Fallback exists only for test fixtures; assembly rejects any production capability not in the table. */
173
+ export function topicOf(capability) {
174
+ return CATALOG_TAXONOMY[capability] ?? 'meta';
175
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { DataTimeContract } from '../time/tools.js';
3
3
  import type { DatasetRef, SaveDatasetInput, SessionLike } from './store.js';
4
+ import { type CatalogTopic } from './catalog-taxonomy.js';
4
5
  /** Normalize an internal data_key token; data_key is host-only and never model-visible. */
5
6
  export declare function normalizeKeyToken(value: string): string;
6
7
  export declare function buildDataKey(provider: string, kind: string, resource: string): string;
@@ -40,6 +41,14 @@ export interface CapabilitySummary {
40
41
  summary: string;
41
42
  paginated: boolean;
42
43
  }
44
+ /** One shard header for the discovery index; chars is the exact size of that shard's catalog text. */
45
+ export interface CatalogTopicSummary {
46
+ topic: CatalogTopic;
47
+ label: string;
48
+ count: number;
49
+ chars: number;
50
+ examples: string[];
51
+ }
43
52
  /** Full contract for one capability; must be read before calling. */
44
53
  export interface CapabilityDetail extends CapabilitySummary {
45
54
  description: string;
@@ -113,10 +122,14 @@ export declare class DataCollectorHub {
113
122
  private awaitSettlement;
114
123
  private settleWaiter;
115
124
  /** Catalog: capability, one-line summary, paginated only. Full schemas would be pruned; details come from describeCapability. */
116
- listCapabilities(): CapabilitySummary[];
125
+ listCapabilities(topic?: CatalogTopic): CapabilitySummary[];
117
126
  capabilityNames(): string[];
118
- /** Model-visible catalog: one `capability|summary|paginated` line each; JSON costs about twice the tokens. */
119
- capabilityDirectory(): string;
127
+ /** One row per non-empty topic; chars is the exact size of the shard text the model will receive. */
128
+ catalogTopicEntries(): CatalogTopicSummary[];
129
+ /** Discovery index: `topic|label|count|chars|examples`, one row per non-empty shard. */
130
+ catalogIndex(): string;
131
+ /** Full catalog is internal aggregation only; the model receives catalogIndex() or one topic shard. */
132
+ capabilityDirectory(topic?: CatalogTopic): string;
120
133
  /** Single capability contract; undefined for unknown names (the tool layer classifies it). */
121
134
  describeCapability(capability: string): CapabilityDetail | undefined;
122
135
  private processNext;
@@ -1,4 +1,5 @@
1
1
  import { summarizeTimeCoverage } from './time-axis.js';
2
+ import { CATALOG_TOPICS, CATALOG_TOPIC_LABELS, topicOf } from './catalog-taxonomy.js';
2
3
  /** Normalize an internal data_key token; data_key is host-only and never model-visible. */
3
4
  export function normalizeKeyToken(value) {
4
5
  return value.replace(/[\\/:]+/g, '.')
@@ -27,6 +28,14 @@ function encodeDirectoryField(value) {
27
28
  .replace(/\n/g, '\\n')
28
29
  .replace(/\t/g, '\\t');
29
30
  }
31
+ /** One model-visible catalog line; keep this the only encoder so index and shard lines cannot drift. */
32
+ function formatCapabilityLine(entry) {
33
+ return `${encodeDirectoryField(entry.capability)}|${encodeDirectoryField(entry.summary)}|${entry.paginated ? 1 : 0}`;
34
+ }
35
+ /** Host pruner measures Unicode code points, not UTF-16 units; shard sizes use the same denominator. */
36
+ function codePointLength(value) {
37
+ return Array.from(value).length;
38
+ }
30
39
  function isPlainRecord(value) {
31
40
  return typeof value === 'object' && value !== null && !Array.isArray(value);
32
41
  }
@@ -258,22 +267,47 @@ export class DataCollectorHub {
258
267
  waiter.reject(outcome.error);
259
268
  }
260
269
  /** Catalog: capability, one-line summary, paginated only. Full schemas would be pruned; details come from describeCapability. */
261
- listCapabilities() {
262
- return [...this.sources.values()].map((source) => ({
270
+ listCapabilities(topic) {
271
+ const entries = [...this.sources.values()].map((source) => ({
263
272
  capability: source.schema.capability,
264
273
  summary: summarize(source.schema),
265
274
  paginated: source.schema.paginated === true,
266
275
  }));
276
+ return topic === undefined ? entries : entries.filter((entry) => topicOf(entry.capability) === topic);
267
277
  }
268
278
  capabilityNames() {
269
279
  return [...this.sources.keys()];
270
280
  }
271
- /** Model-visible catalog: one `capability|summary|paginated` line each; JSON costs about twice the tokens. */
272
- capabilityDirectory() {
273
- return this.listCapabilities()
274
- .map((entry) => `${encodeDirectoryField(entry.capability)}|${encodeDirectoryField(entry.summary)}|${entry.paginated ? 1 : 0}`)
281
+ /** One row per non-empty topic; chars is the exact size of the shard text the model will receive. */
282
+ catalogTopicEntries() {
283
+ const result = [];
284
+ for (const topic of CATALOG_TOPICS) {
285
+ const entries = this.listCapabilities(topic);
286
+ if (entries.length === 0)
287
+ continue;
288
+ const chars = codePointLength(entries.map(formatCapabilityLine).join('\n'));
289
+ result.push({
290
+ topic,
291
+ label: CATALOG_TOPIC_LABELS[topic],
292
+ count: entries.length,
293
+ chars,
294
+ examples: entries.slice(0, 2).map((entry) => entry.capability),
295
+ });
296
+ }
297
+ return result;
298
+ }
299
+ /** Discovery index: `topic|label|count|chars|examples`, one row per non-empty shard. */
300
+ catalogIndex() {
301
+ return this.catalogTopicEntries()
302
+ .map((entry) => [entry.topic, entry.label, String(entry.count), String(entry.chars), entry.examples.join(',')]
303
+ .map(encodeDirectoryField)
304
+ .join('|'))
275
305
  .join('\n');
276
306
  }
307
+ /** Full catalog is internal aggregation only; the model receives catalogIndex() or one topic shard. */
308
+ capabilityDirectory(topic) {
309
+ return this.listCapabilities(topic).map(formatCapabilityLine).join('\n');
310
+ }
277
311
  /** Single capability contract; undefined for unknown names (the tool layer classifies it). */
278
312
  describeCapability(capability) {
279
313
  const source = this.sources.get(capability);
@@ -2,6 +2,7 @@ import { UpstreamRetryBudget, classifyUpstreamFailure, retryBudgetKey, upstreamF
2
2
  // Session reading and authorization have one implementation (src/tool-exec.ts); do not re-implement here.
3
3
  import { authorizedSession, sessionIdentityDecisions } from '../tool-exec.js';
4
4
  import { DATA_COLLECTION_PRESET_IDS } from '../preset-ids.js';
5
+ import { CATALOG_TOPICS } from './catalog-taxonomy.js';
5
6
  const jsonObject = (properties = {}, required = []) => ({ type: 'object', properties, required, additionalProperties: false });
6
7
  const freeObject = { type: 'object', additionalProperties: true };
7
8
  const MAX_ID_LENGTH = 256;
@@ -114,12 +115,30 @@ function resolveCapability(hub, value) {
114
115
  if (!hub.describeCapability(name)) {
115
116
  const available = hub.capabilityNames();
116
117
  if (available.length === 0) {
117
- throw capabilityError('capability_catalog_empty', '当前没有任何已注册的数据能力(数据源注册没有生效)。注意:缺凭据**不会**让目录变空——同花顺能力始终在目录里,只在取数那一刻点名 FUYAO_API_KEY 失败。本工具此刻对任何名字都会失败——不要反复重试,也不要编造能力名;请把该状态回告主 Agent,必要时用 dc_status 核对 registered_capabilities 与 api_key。');
118
+ throw capabilityError('capability_catalog_empty', '当前没有任何已注册的数据能力(数据源注册没有生效)。注意:缺凭据**不会**让目录变空——同花顺能力始终在目录里,只在取数那一刻点名 FUYAO_API_KEY 失败。本工具此刻对任何名字都会失败——不要反复重试,也不要编造能力名;请把该状态回告主 Agent,必要时用 dc_status 核对 registered_capability_count / registered_topics 与 api_key。');
118
119
  }
119
- throw capabilityError('capability_unknown', `未注册的能力 "${name}"。当前可用能力:${available.join(', ')}。请从 list_capabilities() 返回的目录里原样复制一个名字,再调用 describe_capability;不要自行编造、缩写或改写。`);
120
+ throw capabilityError('capability_unknown', `未注册的能力 "${name}"。目录按九个主题分片,下面是索引;先按 topic 取分片,再原样复制名字:\n${hub.catalogIndex()}\n不要自行编造、缩写或改写。`);
120
121
  }
121
122
  return name;
122
123
  }
124
+ /** `topic` is optional; blank means "index", an unknown value gets the full topic list instead of an empty shard. */
125
+ function resolveCatalogTopic(hub, value) {
126
+ if (value === undefined || value === null)
127
+ return undefined;
128
+ if (typeof value !== 'string') {
129
+ throw capabilityError('capability_scope_invalid', `topic 必须是字符串(收到 ${Array.isArray(value) ? 'array' : typeof value})。省略 topic 取九行索引,或从索引里选一个 topic 原样传入。`);
130
+ }
131
+ const topic = value.trim();
132
+ if (topic.length === 0)
133
+ return undefined;
134
+ const entries = hub.catalogTopicEntries();
135
+ const match = entries.find((entry) => entry.topic === topic);
136
+ if (!match) {
137
+ const available = entries.map((entry) => `${entry.topic}(${entry.label},${entry.count}条)`).join('、');
138
+ throw capabilityError('capability_scope_invalid', `未知 topic "${topic}"。可用 topic:${available || '(当前目录为空)'}。请从 list_capabilities() 的索引里原样选一个 topic,再调用 list_capabilities({ "topic": "<topic>" });不要编造。需要全量就九片分别取,不要用 all。`);
139
+ }
140
+ return match.topic;
141
+ }
123
142
  export function registerDataCollectorTools(ctx, hub, diagnostics) {
124
143
  const tools = ctx.get('tools');
125
144
  if (!tools)
@@ -177,8 +196,21 @@ export function registerDataCollectorTools(ctx, hub, diagnostics) {
177
196
  throw requestParamsError(error, requestedCapability) ?? error;
178
197
  }
179
198
  }),
180
- tool('list_capabilities', '列出当前已注册的数据能力目录:**纯文本,一行一条** `capability|summary|paginated`,paginated 为 1(分页)/ 0(不分页)。名字或摘要里的 `|`、换行会转义成 `\\|`、`\\n`,所以一行就是一条能力,不要按冒号或空格拆分。目录是发现入口,**一个任务只需调用一次**:同一 session 的历史里已经保有这份目录,重复调用只会白占上下文。目录刻意不含参数与输出结构(完整 schema 约 23KB,会被剪枝截断);确定要用的能力后,用 describe_capability 单独取那一个能力的 input_schema 后即可 request_data。request_data 的 capability 必须以本目录为准,不要自行编造。', jsonObject(), { type: 'string' }, async (_args, exec) => { authorizedSession(ctx, exec, 'list_capabilities', DATA_COLLECTION_PRESET_IDS); return hub.capabilityDirectory(); }, { concurrencySafe: true }),
181
- tool('describe_capability', '读取**一个**能力的完整契约:description(单位、null 语义、时间与分页口径)、input_schema(params 的取值与约束)、output_fields(返回字段的逐行字典 `路径:类型[:说明]`,类型后缀 `?` 为可为 null、`[].` 为数组元素的字段)与 paginated。request_data 的 params 必须按这里返回的 input_schema 填写;request_data 若返回 request_params_invalid,应回到这里重新读取后再重试。一个能力描述一次即可:结果已在本 session 历史里,重复描述同一个能力只会白占上下文;需要几个能力就**在同一条消息里一次发出多个调用**(本工具是纯读、可并发执行,框架会把它们放进并发池、在同一个下一步一起返回),但一次仍只传**一个**名字,不要用逗号把多个名字塞进一条调用。错误按 code 引导:capability_required(没给名字,先 list_capabilities())、capability_invalid(不是字符串/超长/含逗号,改为目录中的单个名字)、capability_catalog_empty(数据源未注册,别重试,回告主 Agent)、capability_unknown(名字不存在,错误里会列出全部可用能力名并要求原样复制)。', jsonObject({ capability: { type: 'string' } }, ['capability']), jsonObject({
199
+ tool('list_capabilities', '发现数据能力目录。不传 topic:返回九行主题索引 `topic|中文|条数|码点|例子`,先看哪个主题包含所需能力;传 topic:返回该主题的 `capability|summary|paginated` 行。按问题需要取片,不设片数上限:复杂/跨资产问题建议第一步九片全取,单一资产按需取;同一 session 已有结果不要重复调用,多个 topic 在同一条消息里并发调用(本工具纯读、可并发)。片数是结果,不是配额;单片 <2048 是体积预算。目录刻意不含 schema;选定能力后用 describe_capability 取完整契约。request_data 的 capability 必须以目录为准,不要编造。未知 topic 返回 capability_scope_invalid 并列出可用主题。', jsonObject({
200
+ topic: {
201
+ type: 'string',
202
+ enum: [...CATALOG_TOPICS],
203
+ description: '可选。省略返回九行主题索引;给出 topic 返回该主题的能力目录。一次只取需要的主题,不要拉全部。',
204
+ },
205
+ }), { type: 'string' }, async (args, exec) => {
206
+ authorizedSession(ctx, exec, 'list_capabilities', DATA_COLLECTION_PRESET_IDS);
207
+ if (hub.capabilityNames().length === 0) {
208
+ throw capabilityError('capability_catalog_empty', '当前没有任何已注册的数据能力(数据源注册没有生效)。注意:缺凭据**不会**让目录变空;不要反复重试,也不要编造能力名;请用 dc_status 核对 registered_capability_count / registered_topics 与 api_key,并回告主 Agent。');
209
+ }
210
+ const topic = resolveCatalogTopic(hub, args.topic);
211
+ return topic === undefined ? hub.catalogIndex() : hub.capabilityDirectory(topic);
212
+ }, { concurrencySafe: true }),
213
+ tool('describe_capability', '读取**一个**能力的完整契约:description(单位、null 语义、时间与分页口径)、input_schema(params 的取值与约束)、output_fields(返回字段的逐行字典 `路径:类型[:说明]`,类型后缀 `?` 为可为 null、`[].` 为数组元素的字段)与 paginated。request_data 的 params 必须按这里返回的 input_schema 填写;request_data 若返回 request_params_invalid,应回到这里重新读取后再重试。一个能力描述一次即可:结果已在本 session 历史里,重复描述同一个能力只会白占上下文;需要几个能力就**在同一条消息里一次发出多个调用**(本工具是纯读、可并发执行,框架会把它们放进并发池、在同一个下一步一起返回),但一次仍只传**一个**名字,不要用逗号把多个名字塞进一条调用。错误按 code 引导:capability_required(没给名字,先 list_capabilities())、capability_invalid(不是字符串/超长/含逗号,改为目录中的单个名字)、capability_catalog_empty(数据源未注册,别重试,回告主 Agent)、capability_unknown(名字不存在,错误里回九行索引,按 topic 取分片后原样复制)。', jsonObject({ capability: { type: 'string' } }, ['capability']), jsonObject({
182
214
  capability: { type: 'string' },
183
215
  summary: { type: 'string' },
184
216
  paginated: { type: 'boolean' },
@@ -194,11 +226,16 @@ export function registerDataCollectorTools(ctx, hub, diagnostics) {
194
226
  return detail;
195
227
  }, { concurrencySafe: true }),
196
228
  ...(diagnostics ? [
197
- tool('dc_status', '诊断工具:返回数据管道运行状态 —— at/call 为本次真实执行的时间戳与计数(防伪)、api_key 为**本次调用现取**的凭据解析结果(present/source,不含密钥值)、registered_capabilities 为当前已注册 capability 列表、agent_tool_policy 为工具面收敛的现场记录(preset_id / root / outcome / allowed / denied / failed:`outcome=restricted` 是组合期那次减名字的账,`guard-denied` 是一次调用真的被调用级闸门拦下(`ocr` 的 url 形态、`write` / `edit`、角色的 `interrupt_agent`),`not-capital` / `skipped` / `unavailable` / `pending` 是四种没生效的原因;`root=true` 是用户手开出来的会话。工具面本身由该 preset 挂的工具行决定,allowed 恒为空。排查"某个 Agent 为什么看得见、或为什么用不了某颗工具"用)、session_identity 为最近的工具授权判据现场(tool / via=preset|topology / preset_id / allowed;`via:"topology"` 表示 registry 读不到身份、回落到"必须是被委派的子会话"这一旧判据)。数据源注册不依赖 key:api_key.present=false 时同花顺能力仍在目录里,但每次取数会点名 FUYAO_API_KEY 失败。排障时优先调用。', jsonObject(), jsonObject({
229
+ tool('dc_status', '诊断工具:返回数据管道运行状态 —— at/call 为本次真实执行的时间戳与计数(防伪)、api_key 为**本次调用现取**的凭据解析结果(present/source,不含密钥值)、registered_capability_count 与 registered_topics 为当前注册规模(九片 topic/label/count 汇总;**不返回全部能力名**,名字从 `list_capabilities` 分片取)、agent_tool_policy 为工具面收敛的现场记录(preset_id / root / outcome / allowed / denied / failed:`outcome=restricted` 是组合期那次减名字的账,`guard-denied` 是一次调用真的被调用级闸门拦下(`ocr` 的 url 形态、`write` / `edit`、角色的 `interrupt_agent`),`not-capital` / `skipped` / `unavailable` / `pending` 是四种没生效的原因;`root=true` 是用户手开出来的会话。工具面本身由该 preset 挂的工具行决定,allowed 恒为空。排查"某个 Agent 为什么看得见、或为什么用不了某颗工具"用)、session_identity 为最近的工具授权判据现场(tool / via=preset|topology / preset_id / allowed;`via:"topology"` 表示 registry 读不到身份、回落到"必须是被委派的子会话"这一旧判据)。数据源注册不依赖 key:api_key.present=false 时同花顺能力仍在目录里,但每次取数会点名 FUYAO_API_KEY 失败。排障时优先调用。', jsonObject(), jsonObject({
198
230
  at: { type: 'integer' },
199
231
  call: { type: 'integer' },
200
232
  api_key: jsonObject({ present: { type: 'boolean' }, source: { oneOf: [{ type: 'string' }, { type: 'null' }] }, error: { oneOf: [{ type: 'string' }, { type: 'null' }] } }, ['present']),
201
- registered_capabilities: { type: 'array', items: { type: 'string' } },
233
+ registered_capability_count: { type: 'integer' },
234
+ registered_topics: { type: 'array', items: jsonObject({
235
+ topic: { type: 'string' },
236
+ label: { type: 'string' },
237
+ count: { type: 'integer' },
238
+ }, ['topic', 'label', 'count']) },
202
239
  agent_tool_policy: { type: 'array', items: jsonObject({
203
240
  agent_id: { oneOf: [{ type: 'string' }, { type: 'null' }] },
204
241
  root: { type: 'boolean' },
@@ -214,7 +251,7 @@ export function registerDataCollectorTools(ctx, hub, diagnostics) {
214
251
  preset_id: { oneOf: [{ type: 'string' }, { type: 'null' }] },
215
252
  allowed: { type: 'boolean' },
216
253
  }, ['tool', 'via', 'preset_id', 'allowed']) },
217
- }, ['at', 'call', 'api_key', 'registered_capabilities']), async (_args, exec) => {
254
+ }, ['at', 'call', 'api_key', 'registered_capability_count', 'registered_topics']), async (_args, exec) => {
218
255
  authorizedSession(ctx, exec, 'dc_status', DATA_COLLECTION_PRESET_IDS);
219
256
  const apiKey = await diagnostics.probeApiKey();
220
257
  const capabilities = hub.capabilityNames();
@@ -233,7 +270,8 @@ export function registerDataCollectorTools(ctx, hub, diagnostics) {
233
270
  at: snapshot.at,
234
271
  call: snapshot.call,
235
272
  api_key: apiKey,
236
- registered_capabilities: capabilities,
273
+ registered_capability_count: capabilities.length,
274
+ registered_topics: hub.catalogTopicEntries().map(({ topic, label, count }) => ({ topic, label, count })),
237
275
  ...(agentToolPolicy === undefined ? {} : { agent_tool_policy: agentToolPolicy }),
238
276
  // Authorization decision trail: preset identity vs fallback to session topology; without
239
277
  // it, "identity unavailable" and "identity confirmed" look identical to the model.
@@ -3,7 +3,7 @@
3
3
  * Known limit: DNS resolves per request but the IP is not pinned to the connection,
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
- export declare const LOCAL_FETCH_CLIENT_VERSION = "2.22.0";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.24.0";
7
7
  export declare const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
8
8
  export type LocalFetchErrorCode = 'ABORTED' | 'TIMEOUT' | 'INVALID_URL' | 'BLOCKED_URL' | 'DNS' | 'REDIRECT' | 'HTTP' | 'TOO_LARGE' | 'UNSUPPORTED_CONTENT_TYPE';
9
9
  export declare class LocalFetchError extends Error {
@@ -4,7 +4,7 @@
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
6
  import { htmlToMarkdown, stripInvisibleText } from './html-markdown.js';
7
- export const LOCAL_FETCH_CLIENT_VERSION = '2.22.0';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.24.0';
8
8
  export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
9
9
  export class LocalFetchError extends Error {
10
10
  code;
@@ -35,7 +35,7 @@ export interface WindCallResult {
35
35
  code?: WindErrorCode;
36
36
  }
37
37
  /** Must match `package.json` version; a test pins the two together. */
38
- export declare const WIND_CLIENT_VERSION = "2.22.0";
38
+ export declare const WIND_CLIENT_VERSION = "2.24.0";
39
39
  export interface WindClient {
40
40
  callTool(toolName: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<WindCallResult>;
41
41
  }
@@ -19,7 +19,7 @@ export const WIND_SERVER_ENDPOINTS = {
19
19
  analytics_data: 'https://mcp.wind.com.cn/vserver_analytics_data/mcp/',
20
20
  };
21
21
  /** Must match `package.json` version; a test pins the two together. */
22
- export const WIND_CLIENT_VERSION = '2.22.0';
22
+ export const WIND_CLIENT_VERSION = '2.24.0';
23
23
  function errorText(error) {
24
24
  return error instanceof Error ? error.message : String(error);
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-generation",
3
- "version": "2.22.0",
3
+ "version": "2.24.0",
4
4
  "description": "Capital Generation:面向中国散户的 AI 投资助手插件(自动模式 Agent Preset)",
5
5
  "icon": "assets/cg-icon.png",
6
6
  "author": "v587d",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: capital-data-protocol
3
- description: Use when composing or reading a Capital data message — data_request, per-Dataset dataset_ready / data_failed / data_collection_completed, the two-step capability discovery, retry discipline and disclosure fields. Volume 1 of the Capital data protocol; reading a Dataset back lives in capital-data-profile, QuerySpec and derived arithmetic in capital-data-query.
3
+ description: Use when composing or reading a Capital data message — data_request, per-Dataset dataset_ready / data_failed / data_collection_completed, the three-step capability discovery, retry discipline and disclosure fields. Volume 1 of the Capital data protocol; reading a Dataset back lives in capital-data-profile, QuerySpec and derived arithmetic in capital-data-query.
4
4
  ---
5
5
 
6
6
  # Capital 数据协议 · 第一册:委派与逐份回传
@@ -19,7 +19,7 @@ description: Use when composing or reading a Capital data message — data_reque
19
19
  | 角色 | 需要 | 说明 |
20
20
  |---|---|---|
21
21
  | 主 Agent | §1、§3、§4、§5 | 发请求、收回传、输出披露字段(§3 / §3.1 / §3.2 在 `capital-data-profile`,§3.3 / §4 在 `capital-data-query`) |
22
- | `data_collector` | §1、§1.1、§2、§5 | 收请求、能力发现两步、回传载荷、重试纪律(本册即够) |
22
+ | `data_collector` | §1、§1.1、§2、§5 | 收请求、能力发现三步、回传载荷、重试纪律(本册即够) |
23
23
  | `data_junior` | §3、§3.1、§4、§5 | 质检回传、数据缺口、受控查询、重试纪律(§3 系在 `capital-data-profile`,§3.3 / §4 在 `capital-data-query`,§5 在本册) |
24
24
 
25
25
  ## 1. 数据请求(主 Agent → data_collector)
@@ -40,7 +40,7 @@ description: Use when composing or reading a Capital data message — data_reque
40
40
  | `type` | 固定 `data_request` |
41
41
  | `task_id` | 同一任务复用同一个值,便于回传对账 |
42
42
  | `description` | 用自然语言写清要什么数据;也可含标的、区间、频率 |
43
- | `capability` | 可选。明确知道能力名时才指定;省略时由 `data_collector` 走下面 §1.1 的两步发现 |
43
+ | `capability` | 可选。明确知道能力名时才指定;省略时由 `data_collector` 走下面 §1.1 的三步发现 |
44
44
  | `params` | 按该 capability 的 `input_schema` 填写;标的使用完整代码(如 `600519.SH`),不自行拼接交易所后缀。腾讯 fallback 使用 `tencent_quote` / `tencent_kline`,不要改写成已有 `quote` / `history` |
45
45
  | `force_refresh` | `false`/省略:宿主可复用当前 session 内未过期且满足该能力缓存新鲜度的 Dataset;`true`:强制重新取数并生成新的不可变 Dataset,**绝不覆盖旧文件**。用户要求“现在/最新”的快照时传 `true`;保留 7 天不代表行情仍是最新 |
46
46
 
@@ -54,34 +54,33 @@ description: Use when composing or reading a Capital data message — data_reque
54
54
  - 含义相近的能力不自动互换:例如 Fuyao `history` 仅日线,腾讯 `tencent_kline` 支持近期分钟线;按 `describe_capability` 核对粒度、字段与单位,来源切换须写进回传。
55
55
  - `task_id` 由主 Agent 在本轮首次委派前确定;同一用户任务的 data_collector、data_junior 与 visualization 必须原样复用。data_collector 不得自行生成或改写 task_id,缺失时应拒绝请求并回告主 Agent。
56
56
 
57
- ## 1.1 能力发现(data_collector 侧:两步,且各只做一次)
57
+ ## 1.1 能力发现(data_collector 侧:索引 → 分片 → 详情)
58
58
 
59
59
  | 步 | 工具 | 得到什么 | 调用纪律 |
60
60
  |----|------|----------|----------|
61
- | ① | `list_capabilities()` | 纯文本能力目录:**一行一条** `capability\|summary\|paginated`(1=分页、0=不分页) | **一个任务只调一次**;目录已在本 session 历史里,重复调用只会白占上下文 |
62
- | ② | `describe_capability({ capability })` | 该能力的完整 `description` / `input_schema` / `output_fields`(逐行字段字典) | 一次只传**一个**名字、**不传逗号**;同一个能力描述一次即可;要几个能力就在**同一条消息里一次发出多个调用**(纯读、可并发),不要一份一份等 |
63
-
64
- - 读目录时**按行切**:一行就是一条能力,取第一个 `|` 前面的部分当 `capability` 原样复制;摘要里出现的
65
- `\|`、`\n` 是转义字符,不是分隔符。
66
- - `output_fields` 每行是 `字段路径:类型[:说明]`:后缀 `?` 表示上游可能给 `null`,`[].` 表示该字段在数组
67
- 元素上(`item[].thscode`),说明段写 `取值 a/b` 时该字段只允许这几个值。按它写 `query_dataset` 的
68
- `select` / `filters` 列名,大小写与下划线原样照抄。
69
- - 目录刻意不含参数与输出结构:全量 schema 约 23KB,会被工具结果剪枝器(阈值 8192)截断中间
70
- 部分,导致排在中间的能力在发现阶段不可见。目录只负责"选哪个",详情负责"怎么填"。
71
- - **一个任务只调一次 `list_capabilities`**;**同一个能力只描述一次**,重复调用只会白占上下文。
72
- - `list_capabilities` 与 `describe_capability` 都是**纯读**:本轮要看几个能力,就在**同一条消息里一次发出
73
- 这几个 `describe_capability` 调用**,它们在框架并发池里并行执行、在同一个下一步一起返回;一份一份等
74
- 等于把一次往返付成 N 次。这不改变上一条"每个能力只描述一次",也不改变"一次只传一个名字"。
75
- - 不查 `input_schema` 就填 `params` 属于违规;`params` 的取值与约束一律以 `describe_capability` 为准。
61
+ | ① | `list_capabilities()` | 九行主题索引:`topic\|中文\|条数\|码点\|例子` | **一个任务只调一次索引**;重复调用白占上下文 |
62
+ | ② | `list_capabilities({ topic })` | 该主题的 `capability\|summary\|paginated` 行 | **每个 topic 只调一次**;按问题需要取片,不设片数上限:需要几片取几片,复杂/跨资产问题可以九片全取;多个 topic 同一条消息并发发出 |
63
+ | ③ | `describe_capability({ capability })` | 完整 `description` / `input_schema` / `output_fields`(逐行字段字典) | 一次只传**一个**名字、**不传逗号**;同一个能力只描述一次;多个描述同一条消息并发发出 |
64
+
65
+ - **先看索引再选片**:复杂/跨资产问题第一步九片全取;单一资产按需取。
66
+ - **片数是结果不是配额**:按需取片,不要为省片数漏能力。单片 <2048 是体积预算;九片合起来仍是全目录,不会触发单条剪枝。
67
+ - **九片全取用九个独立调用**:不要 `topic=all`,那会合成一条 10k 结果,剪枝按单条算;分开取。
68
+ - 读分片**按行切**:第一个 `|` 前是 capability;`\|`、`\n` 是转义。索引行五个字段,分片行三个。
69
+ - `output_fields` 每行 `字段路径:类型[:说明]`:`?` = 上游可能给 `null`,`[].` = 数组元素字段;按它写 `query_dataset` 的 `select` / `filters` 列名,原样照抄。
70
+ - 目录刻意不带 schema(全量约 23KB 会被剪枝);分片只解决目录总量,详情仍逐个取。
71
+ - **一个任务只调一次索引;每个 topic 只调一次;同一个能力只描述一次**。
72
+ - 两者都是**纯读**:多个调用放同一条消息并发发出,不要一份一份等;这不改变上面的去重规则。
73
+ - 不查 `input_schema` 就填 `params` 属于违规;参数一律以 `describe_capability` 为准。
76
74
 
77
75
  `describe_capability` 的错误按 code 处置,不要盲目重试:
78
76
 
79
77
  | code | 含义 | 正确动作 |
80
78
  |------|------|----------|
81
- | `capability_required` | 没给名字(缺失或空白) | 先调一次 `list_capabilities`,把目录里的名字原样传入 |
79
+ | `capability_required` | 没给名字(缺失或空白) | 先取一次索引,再取对应 topic 的分片,把名字原样传入 |
82
80
  | `capability_invalid` | 不是字符串 / 超长 / 含逗号 | 改成单个字符串名字后重试一次;多个能力分多次调用 |
83
- | `capability_unknown` | 名字不在目录里(错误信息会列出全部可用名字) | 从列出的名字里原文复制重来;不编造、不缩写、不改写 |
84
- | `capability_catalog_empty` | 当前没有任何已注册能力(数据源注册没生效;**缺凭据不会让目录变空**,只会在取数那一刻点名凭据失败) | **不要重试**(此刻任何名字都会失败);用 `dc_status` 核对 `registered_capabilities` 与 `api_key`,如实回告主 Agent |
81
+ | `capability_unknown` | 名字不在目录里(错误信息会回九行索引,不再列全量名字) | 从错误里的索引选 topic,取分片后原文复制名字;不编造、不缩写、不改写 |
82
+ | `capability_scope_invalid` | `list_capabilities` 的 topic 不在当前索引里 | 按错误列出的主题重选一个;不要重试同一个 topic。需要全量就九片分别取,不要用 `all` |
83
+ | `capability_catalog_empty` | 当前没有任何已注册能力(数据源注册没生效;**缺凭据不会让目录变空**,只会在取数那一刻点名凭据失败) | **不要重试**(此刻任何名字都会失败);用 `dc_status` 核对 `registered_capability_count` / `registered_topics` 与 `api_key`,如实回告主 Agent |
85
84
  | `request_params_invalid` | `request_data` 的 `params` 不符合该能力契约(错误会保留具体字段原因) | 先按错误中的 capability 调 `describe_capability({"capability":"..."})`,重新读取 `input_schema`,修正后只重试一次;不要凭记忆猜参数。网络、超时、落盘错误不要走这条路径 |
86
85
 
87
86
  ## 2. 逐份回传(data_collector → 主 Agent)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/watchlist",
3
- "version": "2.22.0",
3
+ "version": "2.24.0",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",