@v587d/capital-generation 2.21.4 → 2.23.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +15 -5
  3. package/automation/board.js +89 -22
  4. package/automation/client.js +3 -3
  5. package/automation/client.src.cjs +5 -1
  6. package/automation/index.js +45 -1
  7. package/automation/package.json +2 -1
  8. package/automation/route.js +8 -0
  9. package/automation/runner.js +3 -2
  10. package/automation/schema.js +4 -0
  11. package/automation/service.js +64 -1
  12. package/automation/storage.js +329 -0
  13. package/chart-ui/package.json +1 -1
  14. package/config/client.js +36 -5
  15. package/config/client.src.cjs +389 -2
  16. package/config/package.json +1 -1
  17. package/lib/agents/messaging-policy.d.ts +21 -0
  18. package/lib/agents/messaging-policy.js +100 -0
  19. package/lib/agents/role-tool-policy.d.ts +23 -7
  20. package/lib/agents/role-tool-policy.js +118 -33
  21. package/lib/agents/root-tool-policy.d.ts +13 -2
  22. package/lib/agents/root-tool-policy.js +87 -28
  23. package/lib/agents/wait-for-agents.d.ts +7 -3
  24. package/lib/agents/wait-for-agents.js +4 -3
  25. package/lib/collector-runtime.js +2 -2
  26. package/lib/data-collector/tools.d.ts +1 -1
  27. package/lib/data-collector/tools.js +31 -3
  28. package/lib/data-collector/upstream-retry.d.ts +48 -0
  29. package/lib/data-collector/upstream-retry.js +192 -0
  30. package/lib/policy-entry.d.ts +3 -3
  31. package/lib/policy-entry.js +3 -1
  32. package/lib/web-retriever/local-fetch.d.ts +1 -1
  33. package/lib/web-retriever/local-fetch.js +1 -1
  34. package/lib/web-retriever/wind-client.d.ts +1 -1
  35. package/lib/web-retriever/wind-client.js +1 -1
  36. package/package.json +6 -6
  37. package/preset/capital-generation/README.md +2 -1
  38. package/preset/capital-generation/agent.patch.yml +58 -44
  39. package/preset/capital-generation/skills/capital-data-profile/SKILL.md +2 -2
  40. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +20 -8
  41. package/preset/capital-generation/skills/capital-data-query/SKILL.md +2 -2
  42. package/preset/capital-generation/skills/capital-equity-research/SKILL.md +1 -1
  43. package/preset/capital-generation/skills/capital-event-impact/SKILL.md +1 -1
  44. package/preset/capital-generation/skills/capital-orchestration/SKILL.md +70 -72
  45. package/preset/capital-generation/skills/capital-portfolio-review/SKILL.md +1 -1
  46. package/preset/capital-generation/skills/capital-visualization-protocol/SKILL.md +1 -0
  47. package/watchlist/package.json +1 -1
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Retry budget for `request_data` upstream failures: three attempts per session+capability.
3
+ * Only rate limits, transport failures, timeouts and 5xx count; parameter/credential errors never do.
4
+ */
5
+ export declare const MAX_UPSTREAM_ATTEMPTS = 3;
6
+ export declare const UPSTREAM_RETRY_WINDOW_MS: number;
7
+ export type UpstreamFailureKind = 'rate_limited' | 'transport' | 'timeout' | 'server';
8
+ export interface UpstreamFailure {
9
+ kind: UpstreamFailureKind;
10
+ message: string;
11
+ }
12
+ export interface RetryBudgetSnapshot {
13
+ attempts: number;
14
+ exhausted: boolean;
15
+ failure: UpstreamFailure;
16
+ }
17
+ /**
18
+ * Classify only failures worth another upstream call. A `fetch failed` is a transport failure, not a
19
+ * rate limit; the two stay separate so the model can report what actually happened.
20
+ */
21
+ export declare function classifyUpstreamFailure(error: unknown): UpstreamFailure | null;
22
+ /** Per-session+capability consecutive-failure counter; success or a five-minute gap resets it. */
23
+ export declare class UpstreamRetryBudget {
24
+ readonly maxAttempts: number;
25
+ private readonly windowMs;
26
+ private readonly now;
27
+ private readonly entries;
28
+ constructor(options?: {
29
+ maxAttempts?: number;
30
+ windowMs?: number;
31
+ now?: () => number;
32
+ });
33
+ inspect(key: string): RetryBudgetSnapshot | undefined;
34
+ record(key: string, failure: UpstreamFailure): RetryBudgetSnapshot;
35
+ reset(key: string): void;
36
+ private liveEntry;
37
+ private prune;
38
+ }
39
+ export declare function retryBudgetKey(sessionId: string, capability: string): string;
40
+ export declare function alternativesFor(capability: string): readonly string[];
41
+ /** Model-visible error; `terminal` is the third failure and carries the stop/report instruction. */
42
+ export declare function upstreamFailureError(input: {
43
+ capability: string;
44
+ failure: UpstreamFailure;
45
+ attempts: number;
46
+ maxAttempts?: number;
47
+ terminal: boolean;
48
+ }): Error;
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Retry budget for `request_data` upstream failures: three attempts per session+capability.
3
+ * Only rate limits, transport failures, timeouts and 5xx count; parameter/credential errors never do.
4
+ */
5
+ export const MAX_UPSTREAM_ATTEMPTS = 3;
6
+ export const UPSTREAM_RETRY_WINDOW_MS = 5 * 60_000;
7
+ const RATE_LIMIT_CODES = new Set(['rate_limited', 'eastmoney_rate_limit', 'tencent_rate_limit']);
8
+ const PERMANENT_CODES = new Set([
9
+ 'credential_missing', 'capability_closed', 'plan_closed', 'invalid_parameter',
10
+ 'request_params_invalid', 'workspace_not_writable', 'upstream_retry_exhausted',
11
+ 'tencent_invalid_param', 'tencent_empty_response', 'tencent_invalid_response',
12
+ 'eastmoney_invalid_response', 'eastmoney_upstream_error',
13
+ ]);
14
+ const TRANSIENT_CODES = new Set(['tencent_kline_unavailable']);
15
+ const PERMANENT_CODE_PREFIXES = [
16
+ 'credential_', 'capability_', 'plan_', 'invalid_', 'request_params_',
17
+ 'workspace_', 'dataset_', 'upstream_retry_',
18
+ ];
19
+ const PERMANENT_PATTERN = /workspace_not_writable|credential_missing|capability_closed|plan_closed|request_params_invalid|invalid_parameter|unsupported parameter|\bparameter\b[^.]*\bmust\b|API error (?:1002|1003|2004)|HTTP (?:400|401|402|403|404|405|409|410|422)\b/i;
20
+ const RATE_LIMIT_PATTERN = /\b429\b|\b4001\b|rate.?limit|too many requests/i;
21
+ const TIMEOUT_PATTERN = /request timed out|timed out|timeout|ETIMEDOUT|ESOCKETTIMEDOUT/i;
22
+ const TRANSPORT_PATTERN = /fetch failed|ECONNRESET|ECONNREFUSED|ENOTFOUND|EAI_AGAIN|EPIPE|socket hang up|network error|connection reset|connection refused|TLS|certificate/i;
23
+ const SERVER_PATTERN = /HTTP (?:error )?5\d\d|bad gateway|service unavailable|gateway timeout|server error/i;
24
+ /** Capability-level substitutes that are actually equivalent enough to hint at; schema still needs a check. */
25
+ const UPSTREAM_ALTERNATIVES = Object.freeze({
26
+ index_quote: ['tencent_quote'],
27
+ quote: ['ftshare_ashare_quote', 'tencent_quote'],
28
+ ftshare_ashare_quote: ['quote', 'tencent_quote'],
29
+ history: ['tencent_kline'],
30
+ index_history: ['tencent_kline'],
31
+ tencent_quote: ['quote', 'ftshare_ashare_quote'],
32
+ tencent_kline: ['history', 'index_history'],
33
+ });
34
+ function codeOf(error) {
35
+ if (!error || typeof error !== 'object')
36
+ return undefined;
37
+ const code = error.code;
38
+ return typeof code === 'string' ? code : undefined;
39
+ }
40
+ function statusOf(error) {
41
+ if (!error || typeof error !== 'object')
42
+ return undefined;
43
+ const status = error.status;
44
+ return typeof status === 'number' ? status : undefined;
45
+ }
46
+ function kindOf(error) {
47
+ if (!error || typeof error !== 'object')
48
+ return undefined;
49
+ const kind = error.kind;
50
+ return typeof kind === 'string' ? kind : undefined;
51
+ }
52
+ function nameOf(error) {
53
+ if (!error || typeof error !== 'object')
54
+ return undefined;
55
+ const name = error.name;
56
+ return typeof name === 'string' ? name : undefined;
57
+ }
58
+ function permanentCode(code) {
59
+ if (!code)
60
+ return false;
61
+ if (PERMANENT_CODES.has(code))
62
+ return true;
63
+ return PERMANENT_CODE_PREFIXES.some((prefix) => code.startsWith(prefix));
64
+ }
65
+ /**
66
+ * Classify only failures worth another upstream call. A `fetch failed` is a transport failure, not a
67
+ * rate limit; the two stay separate so the model can report what actually happened.
68
+ */
69
+ export function classifyUpstreamFailure(error) {
70
+ if (error === undefined || error === null)
71
+ return null;
72
+ const message = error instanceof Error ? error.message : String(error);
73
+ const code = codeOf(error);
74
+ const status = statusOf(error);
75
+ const kind = kindOf(error);
76
+ if (nameOf(error) === 'AbortError' || code === 'ABORTED' || /\brequest aborted\b/i.test(message))
77
+ return null;
78
+ if (permanentCode(code))
79
+ return null;
80
+ if (kind === 'credential_missing' || kind === 'capability_closed' || kind === 'plan_closed' || kind === 'invalid_parameter')
81
+ return null;
82
+ if (kind === 'rate_limited')
83
+ return { kind: 'rate_limited', message };
84
+ if (code && RATE_LIMIT_CODES.has(code))
85
+ return { kind: 'rate_limited', message };
86
+ if (status === 429)
87
+ return { kind: 'rate_limited', message };
88
+ // Eastmoney IP bans surface as 403; other 403s are plan/permission errors and must not be retried.
89
+ if (status === 403)
90
+ return /eastmoney/i.test(message) ? { kind: 'rate_limited', message } : null;
91
+ if (status === 408)
92
+ return { kind: 'timeout', message };
93
+ if (status !== undefined && status >= 500 && status <= 599)
94
+ return { kind: 'server', message };
95
+ if (code && TRANSIENT_CODES.has(code))
96
+ return { kind: 'transport', message };
97
+ if (/eastmoney HTTP 403/i.test(message))
98
+ return { kind: 'rate_limited', message };
99
+ if (PERMANENT_PATTERN.test(message))
100
+ return null;
101
+ if (RATE_LIMIT_PATTERN.test(message))
102
+ return { kind: 'rate_limited', message };
103
+ if (TIMEOUT_PATTERN.test(message))
104
+ return { kind: 'timeout', message };
105
+ if (TRANSPORT_PATTERN.test(message))
106
+ return { kind: 'transport', message };
107
+ if (SERVER_PATTERN.test(message))
108
+ return { kind: 'server', message };
109
+ return null;
110
+ }
111
+ /** Per-session+capability consecutive-failure counter; success or a five-minute gap resets it. */
112
+ export class UpstreamRetryBudget {
113
+ maxAttempts;
114
+ windowMs;
115
+ now;
116
+ entries = new Map();
117
+ constructor(options = {}) {
118
+ this.maxAttempts = options.maxAttempts ?? MAX_UPSTREAM_ATTEMPTS;
119
+ this.windowMs = options.windowMs ?? UPSTREAM_RETRY_WINDOW_MS;
120
+ this.now = options.now ?? (() => Date.now());
121
+ if (!Number.isSafeInteger(this.maxAttempts) || this.maxAttempts < 1)
122
+ throw new Error('maxAttempts must be a positive safe integer');
123
+ if (!Number.isFinite(this.windowMs) || this.windowMs <= 0)
124
+ throw new Error('windowMs must be positive');
125
+ }
126
+ inspect(key) {
127
+ const entry = this.liveEntry(key);
128
+ if (!entry)
129
+ return undefined;
130
+ return { attempts: entry.attempts, exhausted: entry.attempts >= this.maxAttempts, failure: entry.failure };
131
+ }
132
+ record(key, failure) {
133
+ const existing = this.liveEntry(key);
134
+ const attempts = existing ? existing.attempts + 1 : 1;
135
+ this.entries.set(key, { attempts, at: this.now(), failure });
136
+ this.prune();
137
+ return { attempts, exhausted: attempts >= this.maxAttempts, failure };
138
+ }
139
+ reset(key) {
140
+ this.entries.delete(key);
141
+ }
142
+ liveEntry(key) {
143
+ const entry = this.entries.get(key);
144
+ if (!entry)
145
+ return undefined;
146
+ if (this.now() - entry.at > this.windowMs) {
147
+ this.entries.delete(key);
148
+ return undefined;
149
+ }
150
+ return entry;
151
+ }
152
+ prune() {
153
+ const now = this.now();
154
+ for (const [key, entry] of this.entries) {
155
+ if (now - entry.at > this.windowMs)
156
+ this.entries.delete(key);
157
+ }
158
+ if (this.entries.size <= 1000)
159
+ return;
160
+ const oldest = [...this.entries.entries()].sort((a, b) => a[1].at - b[1].at).slice(0, this.entries.size - 1000);
161
+ for (const [key] of oldest)
162
+ this.entries.delete(key);
163
+ }
164
+ }
165
+ export function retryBudgetKey(sessionId, capability) {
166
+ return `${sessionId}\u0000${capability}`;
167
+ }
168
+ export function alternativesFor(capability) {
169
+ return UPSTREAM_ALTERNATIVES[capability] ?? [];
170
+ }
171
+ /** Model-visible error; `terminal` is the third failure and carries the stop/report instruction. */
172
+ export function upstreamFailureError(input) {
173
+ const maxAttempts = input.maxAttempts ?? MAX_UPSTREAM_ATTEMPTS;
174
+ const alternatives = alternativesFor(input.capability);
175
+ const alternativeText = alternatives.length > 0
176
+ ? `可改用 ${alternatives.join(' / ')}(先用 describe_capability 核对字段、单位与代码范围;切换后在 source_label 注明)。`
177
+ : '没有已核对的等价上游。';
178
+ const state = input.terminal
179
+ ? `已连续 ${input.attempts} 次可重试失败`
180
+ : `第 ${input.attempts}/${maxAttempts} 次可重试失败`;
181
+ const next = input.terminal
182
+ ? `已停止重试:不要再次调用 ${input.capability},也不要用 wait_agent 等上游恢复。${alternativeText}立即发 data_failed + data_collection_completed,如实回告 lead。`
183
+ : `不要用 wait_agent 等;${alternativeText}若无法切换再重试,最多 ${maxAttempts} 次。`;
184
+ const prefix = input.terminal ? 'upstream_retry_exhausted' : 'upstream_retryable_failure';
185
+ const error = new Error(`${prefix}: ${input.capability} ${state}(${input.failure.kind}: ${input.failure.message})。${next}`);
186
+ const tagged = error;
187
+ tagged.code = input.terminal ? 'upstream_retry_exhausted' : 'upstream_retryable_failure';
188
+ tagged.attempts = input.attempts;
189
+ tagged.capability = input.capability;
190
+ tagged.alternatives = alternatives;
191
+ return error;
192
+ }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Host-plane Capital policy row: call-level gates that preset composition cannot express.
3
- * Root convergence (visibility already closed by family rows), per-name sibling deny,
4
- * call-level guards for the `ocr` url form and role `interrupt_agent`, plus shell and fs
5
- * guards. Identity must be read per call: the host creates the Agent before selecting a
3
+ * Root host-global deny, role host-global allow-list (family rows own scoped tools), per-name
4
+ * sibling deny, call-level guards for the `ocr` url form and role `interrupt_agent`, plus shell
5
+ * and fs guards. Identity must be read per call: the host creates the Agent before selecting a
6
6
  * preset. Also hides delegation-only roles from the remote roster. Listens on `ctx.root`;
7
7
  * one registration per process.
8
8
  */
@@ -1,4 +1,5 @@
1
1
  import { registerBashGuard } from './agents/bash-guard.js';
2
+ import { registerSendMessageGuard } from './agents/messaging-policy.js';
2
3
  import { registerPresetRosterFilter } from './agents/preset-roster.js';
3
4
  import { registerFsWriteGuard, registerRootOcrGuard, registerRootToolPolicy } from './agents/root-tool-policy.js';
4
5
  import { registerRoleSiblingGuard, registerRoleToolPolicy } from './agents/role-tool-policy.js';
@@ -12,10 +13,11 @@ export const inject = ['tools'];
12
13
  export function apply(ctx) {
13
14
  const policy = ctx;
14
15
  // Preset rows now own visibility; the host keeps only call-level gates.
15
- registerRootToolPolicy(policy, { deny: false });
16
+ registerRootToolPolicy(policy);
16
17
  registerRootOcrGuard(policy);
17
18
  registerRoleToolPolicy(policy);
18
19
  registerRoleSiblingGuard(policy);
20
+ registerSendMessageGuard(policy);
19
21
  registerBashGuard(policy);
20
22
  registerFsWriteGuard(policy);
21
23
  registerPresetRosterFilter(ctx);
@@ -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.21.4";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.23.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.21.4';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.23.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.21.4";
38
+ export declare const WIND_CLIENT_VERSION = "2.23.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.21.4';
22
+ export const WIND_CLIENT_VERSION = '2.23.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.21.4",
3
+ "version": "2.23.0",
4
4
  "description": "Capital Generation:面向中国散户的 AI 投资助手插件(自动模式 Agent Preset)",
5
5
  "icon": "assets/cg-icon.png",
6
6
  "author": "v587d",
@@ -163,14 +163,14 @@
163
163
  },
164
164
  "peerDependencies": {
165
165
  "@deepseek-ai/cordis": "~4.1.0",
166
- "@deepseek-ai/dsh-skill": "0.2.2-rc.1",
167
- "@deepseek-ai/dsh-skill-filesystem": "0.2.2-rc.1"
166
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.2",
167
+ "@deepseek-ai/dsh-skill-filesystem": "0.2.2-rc.2"
168
168
  },
169
169
  "devDependencies": {
170
170
  "@deepseek-ai/cordis": "~4.1.0",
171
- "@deepseek-ai/dsh-skill": "^0.2.2-rc.1",
172
- "@deepseek-ai/dsh-skill-filesystem": "^0.2.2-rc.1",
173
- "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.1",
171
+ "@deepseek-ai/dsh-skill": "^0.2.2-rc.2",
172
+ "@deepseek-ai/dsh-skill-filesystem": "^0.2.2-rc.2",
173
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.2",
174
174
  "@deepseek-ai/schemastery": "^3.19.0",
175
175
  "esbuild": "^0.28.2",
176
176
  "js-yaml": "^5.4.1",
@@ -103,7 +103,8 @@
103
103
  替代是「persona 与工具插件改住 Agent Preset,委派行只用 `agentPreset` 选它」——这一条我们做到底:
104
104
  本仓当前由 preset 族行暴露的 29 颗模型工具,按族拆成
105
105
  `@v587d/capital-generation/tools/<family>` 的 subpath 入口行
106
- (`package.json` 的 `exports`),每颗 preset 只挂自己那几族,**不再有运行期名字级 allow 名单**。
106
+ (`package.json` 的 `exports`),每颗 preset 只挂自己那几族;宿主全局工具另由
107
+ `role-tool-policy` 的显式白名单收口(**scoped 工具面仍只由族行决定**)。
107
108
  行契约(那一行注册哪些名字)只有一份,住 `test/family-rows.mjs`:`test/family-entries.test.mjs`
108
109
  拿它实测每个入口注册了什么,`test/persona.test.mjs` 拿它核对 YAML 的组合结果。
109
110
  - collector:`tools/collect` + `tools/time`;junior:`tools/dataset-read` + `tools/chart-source` +
@@ -35,20 +35,20 @@
35
35
  data_request / dataset_ready / data_failed / data_collection_completed 载荷、能力发现与重试纪律、
36
36
  7 天保留与 workspace_not_writable 等失败处置;本 persona 只留硬规则。
37
37
  1. 启动自检与登记:若作用域里没有 request_data / list_capabilities(只有 send_message
38
- 等通用工具),立即用 send_message 回告主 Agent「数据工具未挂载(缺少
38
+ 等通用工具),立即用 send_message({ agent: "lead" }) 回告主 Agent「数据工具未挂载(缺少
39
39
  request_data/list_capabilities),请检查 capital-generation 装配」,不要假装调用
40
40
  不存在的工具;工具正常时先发一次
41
41
  {"type":"data_collector_ready","tools":[可见的数据工具名]},不要为登记创建虚假请求。
42
- 2. 取数:按问题选足相关能力,不按固定数量提前停止;request_data 阻塞等待,一次只请求一个能力、串行推进。
42
+ 2. 取数:按问题选足相关能力,不限;request_data 阻塞等待(超时约 30 秒),一次只请求一个能力、串行推进。
43
43
  params 按 input_schema 填,capability 以 list_capabilities 目录为准,不编造。
44
- 宿主只复用满足来源新鲜度要求的 Dataset;明确要求最新快照时 force_refresh=true,绝不覆盖旧文件。
44
+ 宿主只复用满足来源新鲜度要求的 Dataset;要最新 force_refresh=true,绝不覆盖旧文件。
45
45
  遇 request_params_invalid,按错误中的 capability 调 describe_capability 重读 input_schema,修正 params 后只重试一次;不要猜参数。
46
46
  3. 每次 request_data 成功(包括缓存命中)立刻 send_message 一份 dataset_ready;
47
47
  每次请求最终失败立刻发 data_failed;全部请求结束再发 data_collection_completed(不重发 DatasetRef)。
48
48
  dataset_id / artifact_ref / source_label / captured_at / retention_until 按 request_data 返回原样填入;
49
49
  字段、数值、日期不改写;禁止只回传 markdown 汇总或原始行。
50
50
  4. 失败:绝不幻觉填充数据、绝不用编造的来源补位、绝不声称数据已保存;重试纪律按 skill
51
- 处置(参数类修正后重试,瞬时与执行超时各最多重试 1 次;同一请求累计最多重试 2 次,仍失败即回传 failed 并注明)。
51
+ 处置(可重试上游最多 3 次尝试;先换等价能力;upstream_retry_exhausted 即回传 failed,不再调用/wait_agent)。
52
52
  5. 叶子边界:你不创建、不委派、不指挥任何下游子 Agent(data_junior 由主 Agent 直接创建,
53
53
  不归你创建、不归你指挥),互通一律经主 Agent 中继。
54
54
 
@@ -98,6 +98,8 @@
98
98
 
99
99
  - id: tool-subagent-control
100
100
  name: '@deepseek-ai/dsh-tool-subagent-control'
101
+ config:
102
+ interrupt: false
101
103
 
102
104
  - id: capital-generation-scope
103
105
  name: cordis:group
@@ -127,12 +129,11 @@
127
129
  prefix: |-
128
130
  # ROLE & IDENTITY
129
131
  你是数据分析师(data_junior):接收主 Agent 的 profile_request / query_request
130
- (DatasetRef + 问题;describe_dataset 一次完成描述,单点复核才用 inspect/profile/query_dataset),
131
- 以及无 Dataset 的假设建模请求(假设与口径由主 Agent 给)。有 Dataset 时按 DUTIES 6 出图;
132
+ (DatasetRef + 问题;describe_dataset 一次描述,单点复核才用 inspect/profile/query_dataset),
133
+ 以及无 Dataset 假设建模(主 Agent 给)。有 Dataset 时按 DUTIES 6 出图;
132
134
  创建 specialist 后等终态再回传。载荷中不得出现原始数据行。你不是投资分析师
133
- (不做投资判断、不输出买卖建议),也不改写原始 Dataset。你是主 Agent 的直接子 Agent,
134
- 与 data_collector 是兄弟:你不会被 data_collector 创建或指挥,互通一律经主 Agent 中继;
135
- visualization_specialist 是你的异步子 Agent,不向主 Agent 直接发消息。
135
+ (不做投资判断、不输出买卖建议),也不改写原始 Dataset。你是主 Agent 的直接子 Agent,与 data_collector 是兄弟,不会被 data_collector 创建,互通经主 Agent 中继;
136
+ visualization_specialist 是你的异步子 Agent,不直接发消息。
136
137
  工具面没有外部行情 API、网页检索与凭据入口;run_code 里的 Node 也不得用于取数、联网或读凭据;宿主若暴露 web_search / web_fetch 也不得用于取数或查资料。不索取或保存账户密码。
137
138
 
138
139
  # DUTIES
@@ -149,10 +150,10 @@
149
150
  3. 默认用 describe_dataset 读 Dataset(多份在同一 run_code 程序里 Promise.all,见 PROGRAM DISCIPLINE);inspect_dataset/profile_dataset/query_dataset 只用于单点复核。优先用 profile 的 time_facts 与 structure;query_dataset 只做受控聚合,你取不到原始行。
150
151
 
151
152
  4. 数据缺口:先分清「数据里确实没有」与「那份数据还没取」。后者不要写成「无法确认」,
152
- 立即用 send_message 向父 Agent 发一次 data_gap(task_id / dataset_id / need / reason /
153
+ 立即用 send_message({ agent: "lead" }) 发一次 data_gap(task_id / dataset_id / need / reason /
153
154
  blocking),同一条缺口只发一次,这是请求不是结论。你不得自行取数、也不得直接找
154
- data_collector(取数由主 Agent 转交);不要为了填空编造能力名。
155
- 5. 回传:用 tools.send_message 逐份回传结构化载荷(type / task_id / dataset_id / profile_ref
155
+ data_collector(取数经主 Agent);不要为了填空编造能力名。
156
+ 5. 回传:用 tools.send_message({ agent: "lead" }) 逐份回传结构化载荷(type / task_id / dataset_id / profile_ref
156
157
  或 query_result),字段按工具返回原样填入——字段名、数值、日期一律不改写;可附表或
157
158
  摘要,禁止只回传 markdown 汇总。失败回传 profile_failed / query_failed 与 error/code,
158
159
  绝不编造统计或查询结果;失败不影响原始 Dataset,可按主 Agent 指示重试。同一 task_id + dataset_id 已完成 profile 不重复做。
@@ -220,6 +221,8 @@
220
221
 
221
222
  - id: tool-subagent-control
222
223
  name: '@deepseek-ai/dsh-tool-subagent-control'
224
+ config:
225
+ interrupt: false
223
226
 
224
227
  - id: tool-subagent-visualization-specialist
225
228
  name: '@deepseek-ai/dsh-tool-subagent'
@@ -380,6 +383,8 @@
380
383
 
381
384
  - id: tool-subagent-control
382
385
  name: '@deepseek-ai/dsh-tool-subagent-control'
386
+ config:
387
+ interrupt: false
383
388
 
384
389
  # Family rows: search / sources / ocr / time (built in retriever-runtime.ts); receipts stay per row.
385
390
  - id: capital-retrieve-search-tools
@@ -483,6 +488,8 @@
483
488
 
484
489
  - id: tool-subagent-control
485
490
  name: '@deepseek-ai/dsh-tool-subagent-control'
491
+ config:
492
+ interrupt: false
486
493
 
487
494
  # Family rows only: a hand-opened preset session bypasses `disabled`, so the row combo is the only gate.
488
495
  - id: capital-dataset-read-tools
@@ -535,59 +542,63 @@
535
542
  数据截止时间以 DatasetRef 的 captured_at 为准并披露。
536
543
 
537
544
  # SUBAGENT ORCHESTRATION(子 Agent 编排)
538
- 1. 每轮预检(硬):本轮第一次调用任何创建类工具前,必须先 list_agents(scope="children")。
539
- 上一轮空列表不能代替本轮;一次覆盖全部角色,不逐角色重查、不等待时轮询。
545
+ 1. 每轮预检(硬):本轮第一次调用任何创建类工具前,必须先 list_agents()。
546
+ 上一轮空列表不能代替本轮;一次覆盖全部角色,不轮询。
547
+ 行格式 `<name> [<status>] — <description>`,首行 `lead`;只看 name 不含 `/` 且不是 `lead` 的直系子 Agent,
548
+ `data-junior/...` 这类孙 Agent 一律忽略。
540
549
 
541
- 2. 复用优先(硬):只选 kind=child,按角色映射匹配 data_collector / data_junior / web_retriever:
542
- label 优先;历史 child 的 label 即使是旧任务标题,只要已映射到该角色 durable id,必须沿用,不得因 label 非标准而新建。
543
- 同角色存在 running 或 inactive → 立即 send_message(inactive 会开一个新回合),禁止因空闲、完成、标题变化或并行而再建一个。
544
- ID 纪律:agent_id 只从最近一次 list_agents 返回复制,禁止凭记忆或历史复述;
545
- 发送前核对 id、label、任务三者对应。
550
+ 2. 复用优先(硬):按 name 匹配 data-collector / data-junior / web-retriever,name 缺失时用 description 兜底;
551
+ 历史 child 没有 name 时用 session id,必须沿用;不得因为 description 是旧任务标题而新建。
552
+ 同角色存在 running 或 inactive → 立即 send_message,禁止因空闲、完成、标题变化或并行再建一个。
553
+ 名字纪律:name 只从最近一次 list_agents 复制,禁止凭记忆复述;
554
+ 发送前核对 name、description、任务三者对应;同名创建报 DUPLICATE_AGENT_NAME、非法名报 INVALID_AGENT_NAME。
546
555
 
547
556
  3. 创建:仅当本轮 list_agents 明确无该角色时,才调用 direct-child 专用工具
548
- subagent_data_collector / subagent_data_junior / subagent_web_retriever;subagent_visualization_specialist 不是你的 direct-child 创建工具,只能由 data_junior 在可视化 gate 后调用;description 必须等于角色标签;参数写 prompt,不需要复制任何模板。返回 durable id 后立即记入委派清单;每会话只需一个同角色 Agent,不要反复创建。
557
+ subagent_data_collector / subagent_data_junior / subagent_web_retriever;name 固定为 data-collector / data-junior / web-retriever,
558
+ description 必须等于角色标签;prompt 只写本次任务,不需要复制任何模板。subagent_visualization_specialist 只能由 data_junior 在可视化 gate 后调用;
559
+ 创建回执是 `started subagent <name>`;每会话各角色只需一个,不反复创建。
549
560
 
550
561
  4. 路由(硬)
551
- a. 行情/财务/历史→data_collector;质检/建模(DCF、估值、三表、情景、敏感性等,含纯算术)/统计/可视化编排→data_junior;
562
+ a. 行情/财务/历史→data_collector;质检/建模(DCF、估值、三表、情景、敏感性)/统计/可视化编排→data_junior;
552
563
  网页事实 → web_retriever。即使不取数、只有用户假设也交 data_junior:你只给假设与口径,不自己算。
553
- prompt 带已消歧标的与完整代码;多角色可并行,但先复用/创建并记清单。
564
+ prompt 带已消歧标的与完整代码;多角色可并行,先复用/创建并记清单。
554
565
 
555
566
  b. 主 Agent 禁止自行检索;宿主若仍暴露 web_search / web_fetch,也不得调用。
556
- 外部检索只经 web_retriever 回传。
557
- 工作目录里的本地 PDF / 图片可直接用 ocr 解析(外部链接仍走委派)。
567
+ 外部检索一律委派。
568
+ 本地 PDF / 图片可直接用 ocr 解析(外部链接仍走委派)。
558
569
 
559
570
  c. data_collector、data_junior、web_retriever 是兄弟子 Agent,互通经主 Agent 中继;
571
+ 根只发无 `/` 且不是 `lead` 的直系名,子 Agent 只回 `lead`;
560
572
  data_junior 是你的直接子 Agent,一律由你直接创建;data_collector 不得创建或指挥它。
561
573
 
562
- d. visualization_specialist 是 data_junior 在可视化 gate 后创建的孙 Agent;
563
- 主 Agent 不直接调用、不复用、不轮询。
574
+ d. visualization_specialist 是 data_junior 的可视化孙 Agent;
564
575
 
565
- e. 没有通用委派出口:只有上面那三颗专用工具(以及 data_junior 手里的出图工具);
576
+ e. 没有通用委派出口:只有上面三颗专用工具(及 data_junior 的出图工具);
566
577
  不属于任何专用角色的活你自己做,或如实说明缺口,不派子 Agent。
567
578
  data_analyst 未启用:不创建。
568
579
 
569
- f. 委派出去的子 Agent 一律异步 continuable:创建工具立即返回 id,本轮结束不等于它结束。
580
+ f. 委派一律异步 continuable:创建立即返回 name,本轮结束不等于它结束。
570
581
 
571
582
  5. 回合:子 Agent 完成靠结算通知唤醒;结束前不向用户断言完成。
572
- 写最终结论前对账:逐行核对每个子 Agent 在你最后一次创建 / send_message 之后
573
- 是否已收到结算通知(回传正文再像完成也不算 ✓,细则见 skill capital-orchestration);
574
- 缺一条本轮只写等待行,结论留到收齐那一步;结论后又唤醒谁就重新对账。
583
+ 写最终结论前对账:逐行核对每个子 Agent 在最后一次交互后
584
+ 是否收到结算通知(回传正文不算✓);
585
+ 缺一条本轮只写等待行;结论后再被唤醒就重新对账。
575
586
  结算通知只证明该子 Agent 本轮结束,仍不等于任务完成;所有委派行都结算后才可收口。
576
587
  收口:对账通过 → 有图先 present_charts → 再写最终答复。
577
- 等待:委派后调 wait_for_agents;message/user_input 先处理再等,
578
- all_settled 才对账;timeout 仍有 running 就继续等,无法继续才写等待。
588
+ 等待:委派后调 wait_for_agents;message/user_input 先处理,
589
+ all_settled 才对账;timeout 有 running 就继续等。
590
+ wait_agent 只返回 timedOut,不是收尾屏障,不替代 wait_for_agents。
591
+ 不使用 Team 任务板工具。
579
592
  等待期不做外部检索。
580
- 已答复且无新增信息:不输出可见正文(绝不写“已完成/见上”),或重发自足最终答复;之后有工具调用 → 重新答复。
581
593
 
582
- 5.1 子 Agent 中途请求(硬):收到子 Agent 的中途消息(就绪登记,或
583
- type=data_gap 的补数据请求)时,它是工单不是完成:就绪登记继续等其正式回传;
584
- data_gap 立即按清单复用对应角色补齐(结构化数据交 data_collector,网页材料交
585
- web_retriever),再 send_message 发回**同一个**子 Agent(禁止新建同角色),
586
- 不必重跑本轮预检;标为「等数据」的子 Agent 收到结算通知也不算完成。
587
- 取数失败、或现有能力**根本给不了**这份数据时,也必须回一条消息告诉它
588
- (写明是「数据源没有该字段」而不是取数失败),不能让它一直等。
594
+ 5.1 子 Agent 中途请求(硬):收到中途消息(就绪登记或 data_gap 补数)是工单不是完成:就绪登记继续等;
595
+ data_gap 按清单复用角色补齐,再发回**同一个**子 Agent,
596
+ 不必重跑本轮预检;「等数据」行收到结算不算完成。
597
+ 错投补救:interrupt_agent({ agent: "<name>" }) 停当前轮。
598
+ 取数失败或能力给不了这份数据时,也必须回一条消息告诉它
599
+ (「数据源没有该字段」≠取数失败)。
589
600
 
590
- 6. 预检异常、委派清单格式与完整载荷示例 → skill capital-orchestration。
601
+ 6. 预检异常、委派清单格式与完整载荷示例见 skill capital-orchestration。
591
602
 
592
603
  # DATA COORDINATION(数据调度纪律)
593
604
  1. 主 Agent 禁止直接调用 request_data / list_capabilities / dc_status / Dataset 系列工具;
@@ -666,10 +677,13 @@
666
677
  toolName: subagent_data_analyst
667
678
  agentPreset: capital-data-analyst
668
679
  # If this row is ever enabled, `query_dataset` stays aggregate-only: it must not reopen raw rows.
669
- # 0.2.2 registers send_message / interrupt_agent / list_agents from the main entry; the
670
- # old `list-agents` subpath is gone and a row naming it keeps the whole preset broken.
680
+ # 0.2.2 registers send_message / interrupt_agent / list_agents / wait_agent from the main
681
+ # entry; the old `list-agents` subpath is gone and a row naming it keeps the preset broken.
682
+ # dsh-base sets interrupt:false; the root must restate true (rc.2 honors the nearest row).
671
683
  - id: tool-subagent-control
672
684
  name: '@deepseek-ai/dsh-tool-subagent-control'
685
+ config:
686
+ interrupt: true
673
687
 
674
688
  - id: tool-ask-user
675
689
  name: '@deepseek-ai/dsh-tool-ask-user'
@@ -155,8 +155,8 @@ data_junior 发现「问题需要的那份数据还没取」时(不是「数
155
155
  }
156
156
  ```
157
157
 
158
- PTC 下发送是 `await tools.send_message({ agent_id: PARENT, message: JSON.stringify(payload) })`;
159
- payload 的 JSON 形状不变,父 Agent id 仍来自系统提示。
158
+ PTC 下发送是 `await tools.send_message({ agent: "lead", message: JSON.stringify(payload) })`;
159
+ payload 的 JSON 形状不变。
160
160
 
161
161
  | 字段 | 规则 |
162
162
  |------|------|
@@ -86,7 +86,7 @@ description: Use when composing or reading a Capital data message — data_reque
86
86
 
87
87
  ## 2. 逐份回传(data_collector → 主 Agent)
88
88
 
89
- 每次 `request_data` 返回后立即 `send_message`,成功时每条只含**一份** DatasetRef(缓存命中也一样):
89
+ 每次 `request_data` 返回后立即 `send_message({ agent: "lead", ... })`,成功时每条只含**一份** DatasetRef(缓存命中也一样):
90
90
 
91
91
  ```json
92
92
  {
@@ -149,17 +149,29 @@ description: Use when composing or reading a Capital data message — data_reque
149
149
 
150
150
  ## 5. 重试纪律
151
151
 
152
-
153
152
  | 错误类型 | 例子 | 处理 |
154
153
  |----------|------|------|
155
- | 参数类 | 缺参、格式错、枚举越界 | 对照 `input_schema` 的 enum/description 修正后重试 |
156
- | 瞬时类 | 限流、上游超时、网络 | 重试 1 次 |
157
- | 执行超时 | 约 30 秒超时 | 重试 1 次 |
158
- | 数据源/环境 | 无可用数据源、workspace 只读、落盘失败(`workspace_not_writable`) | 不回退、不假装成功,如实回传 `error`/`code` |
154
+ | 参数类 | 缺参、格式错、枚举越界 | 对照 `input_schema` 修正后重试一次,不占上游预算 |
155
+ | 可重试上游 | 429/4001、`fetch failed`、超时、5xx | 先换等价能力;无替代才重试;同一能力最多 3 次尝试(首发 + 2 次重试) |
156
+ | 终止类 | 2004、套餐 403、凭据缺失、`workspace_not_writable` | 不重试,如实回传 `error`/`code` |
159
157
  | 网页获取 | 网络或服务错误 | 最多重试 1 次,仍失败如实回传 |
160
158
 
161
- 底线:绝不幻觉填充数据,绝不用编造的来源补位,绝不声称数据已保存;
162
- 同一请求累计最多重试 2 次,仍失败就回传 `failed` 并注明已重试,不再继续。
159
+ **替代表**(先 `describe_capability` 核对字段、单位、代码范围;切换后 `source_label` 写新来源):
160
+
161
+ | 需求 | 主能力 | 可替代 |
162
+ |------|--------|--------|
163
+ | 指数快照 | `index_quote` | `tencent_quote`(支持指数,字段名不同) |
164
+ | A 股个股快照 | `quote` / `ftshare_ashare_quote` | `tencent_quote`(仅 SH/SZ);反向同理 |
165
+ | 日 K / 指数日 K | `history` / `index_history` | `tencent_kline`(无成交额,成交量单位手) |
166
+ | 板块排名 / 市场广度 / 涨跌停池 / 港股美股快照 | 各自能力 | 无等价替代;同源(如东财板块与东财资金流)也不算替代 |
167
+
168
+ **硬规则**:
169
+
170
+ - `request_data` 对同一 session + capability 计数(5 分钟窗口):第 3 次可重试失败返回 `upstream_retry_exhausted`,第 4 次调用直接拒绝;成功一次即清零。
171
+ - 收到 `upstream_retryable_failure` / `upstream_retry_exhausted` 后不要用 `wait_agent` 等上游恢复;它只等消息,长等会触发运行 idle 计时。
172
+ - 没有替代能力时重试到 3 次上限;收到 `upstream_retry_exhausted` 立即发 `data_failed` + `data_collection_completed`,`error` 保留最后一次错误原文与 `attempts`;不要为等一个上游耗尽整轮预算。
173
+
174
+ 底线:绝不幻觉填充数据,绝不用编造的来源补位,绝不声称数据已保存;同一能力达到上限后不再重试。
163
175
 
164
176
  ## 5. 输出必须披露的字段
165
177
 
@@ -37,8 +37,8 @@ return { pct: ((b - a) / a) * 100, from: a, to: b }
37
37
  `query_dataset` 串行,不要混进同一批。某份可能失败时用 `Promise.allSettled`。
38
38
  - 一次程序只做一段事:先 `console.log(s.content)` 读协议,再 describe/算数,最后回传;
39
39
  不要把整份 profile 或多个工具结果 `return` 回去(外层结果会过 8192 剪枝)。
40
- - 回传与 `data_gap` 用 `await tools.send_message({ agent_id, message })`;它返回 `{messageId}`,
41
- 不结束本轮。`agent_id` 取系统提示里的 parent agent id。
40
+ - 回传与 `data_gap` 用 `await tools.send_message({ agent: "lead", message })`;它返回 `{messageId}`,
41
+ 不结束本轮。根 Agent 的树内名字固定是 `lead`。
42
42
 
43
43
  **不许做的**(这是纪律,不是沙箱限制——沙箱只拦写,不拦读与网络):
44
44