@v587d/capital-generation 2.30.1 → 2.31.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 (69) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +4 -4
  3. package/THIRD_PARTY_NOTICES.md +1 -0
  4. package/automation/package.json +1 -1
  5. package/automation/storage.js +4 -0
  6. package/chart-ui/package.json +1 -1
  7. package/config/client.js +1 -1
  8. package/config/package.json +1 -1
  9. package/lib/agents/messaging-policy.d.ts +23 -6
  10. package/lib/agents/messaging-policy.js +64 -9
  11. package/lib/agents/role-tool-policy.d.ts +3 -0
  12. package/lib/agents/role-tool-policy.js +15 -5
  13. package/lib/agents/selected-skills-provider.d.ts +1 -1
  14. package/lib/agents/selected-skills-provider.js +3 -1
  15. package/lib/analysis/registry.d.ts +12 -0
  16. package/lib/analysis/registry.js +76 -0
  17. package/lib/analysis/runtime.d.ts +87 -0
  18. package/lib/analysis/runtime.js +225 -0
  19. package/lib/analysis/schemas.d.ts +58 -0
  20. package/lib/analysis/schemas.js +276 -0
  21. package/lib/analysis/snapshot.d.ts +102 -0
  22. package/lib/analysis/snapshot.js +266 -0
  23. package/lib/analysis/storage.d.ts +64 -0
  24. package/lib/analysis/storage.js +96 -0
  25. package/lib/analysis/tools.d.ts +17 -0
  26. package/lib/analysis/tools.js +357 -0
  27. package/lib/analysis/types.d.ts +201 -0
  28. package/lib/analysis/types.js +44 -0
  29. package/lib/analysis/validation.d.ts +44 -0
  30. package/lib/analysis/validation.js +381 -0
  31. package/lib/analysis-entry.d.ts +10 -0
  32. package/lib/analysis-entry.js +7 -0
  33. package/lib/data-collector/store.d.ts +14 -1
  34. package/lib/data-collector/store.js +47 -1
  35. package/lib/data-contract.d.ts +3 -2
  36. package/lib/data-contract.js +18 -2
  37. package/lib/preset-ids.d.ts +5 -0
  38. package/lib/preset-ids.js +7 -1
  39. package/lib/python-runtime/errors.d.ts +7 -1
  40. package/lib/python-runtime/errors.js +9 -1
  41. package/lib/python-runtime/manager.d.ts +30 -0
  42. package/lib/python-runtime/manager.js +88 -0
  43. package/lib/python-runtime/probe.js +5 -1
  44. package/lib/selected-skills-entry.js +1 -1
  45. package/lib/web-retriever/local-fetch.d.ts +1 -1
  46. package/lib/web-retriever/local-fetch.js +1 -1
  47. package/lib/web-retriever/wind-client.d.ts +1 -1
  48. package/lib/web-retriever/wind-client.js +1 -1
  49. package/package.json +6 -1
  50. package/preset/capital-generation/README.md +5 -6
  51. package/preset/capital-generation/agent.patch.yml +54 -65
  52. package/preset/capital-generation/skills/capital-analysis-evidence/SKILL.md +99 -0
  53. package/preset/capital-generation/skills/capital-analysis-synthesis/SKILL.md +110 -0
  54. package/preset/capital-generation/skills/capital-analysis-validation/SKILL.md +96 -0
  55. package/preset/capital-generation/skills/capital-data-query/SKILL.md +1 -1
  56. package/preset/capital-generation/skills/capital-equity-research/SKILL.md +1 -1
  57. package/preset/capital-generation/skills/capital-event-impact/SKILL.md +1 -1
  58. package/preset/capital-generation/skills/capital-orchestration/SKILL.md +32 -27
  59. package/preset/capital-generation/skills/capital-portfolio-review/SKILL.md +1 -1
  60. package/preset/capital-generation/skills/capital-senior-analysis/SKILL.md +105 -0
  61. package/python/analysis/modules/financial_quality/LICENSE +27 -0
  62. package/python/analysis/modules/financial_quality/module.json +65 -0
  63. package/python/analysis/modules/financial_quality/module.py +535 -0
  64. package/python/analysis/modules/hello/LICENSE +21 -0
  65. package/python/analysis/modules/hello/module.json +46 -0
  66. package/python/analysis/modules/hello/module.py +56 -0
  67. package/python/worker.py +152 -5
  68. package/selected-skills/routing.js +5 -2
  69. package/watchlist/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { chmod, mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
2
3
  import { randomUUID } from 'node:crypto';
3
4
  import { dirname, join, resolve } from 'node:path';
4
5
  import { fileURLToPath, pathToFileURL } from 'node:url';
@@ -18,6 +19,7 @@ const PYTHON_VENDOR_DIR = fileURLToPath(new URL('../../python/vendor', import.me
18
19
  const DATA_SCRIPT_ID = /^[a-z0-9_]+$/u;
19
20
  const DATA_RUN_DIR = 'data-runs';
20
21
  const DIAGNOSTIC_TAIL_CHARS = 2_000;
22
+ const ANALYSIS_ENTRYPOINT = /^[A-Za-z0-9_.-]{1,64}$/u;
21
23
  function recordOf(value) {
22
24
  return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
23
25
  }
@@ -592,6 +594,92 @@ export class PythonRuntimeManager {
592
594
  await rm(runDir, { recursive: true, force: true }).catch(() => undefined);
593
595
  }
594
596
  }
597
+ /**
598
+ * Run one reviewed analysis module and return the object it wrote.
599
+ *
600
+ * The child gets a run directory inside the workspace: `request.json` is already there (the store
601
+ * wrote it), and the module's `outputs/` and `logs/` land beside it. The run directory is not
602
+ * deleted here — it is the audit trail; retention is the analysis layer's decision.
603
+ */
604
+ async runAnalysisModule(options) {
605
+ const entrypoint = typeof options?.entrypoint === 'string' ? options.entrypoint : '';
606
+ if (!ANALYSIS_ENTRYPOINT.test(entrypoint) || entrypoint.includes('..')) {
607
+ throw new PythonRuntimeError('invalid-request', `分析模块入口名不合法:${JSON.stringify(entrypoint)}`);
608
+ }
609
+ if (typeof options?.runDir !== 'string' || typeof options?.inputsDir !== 'string'
610
+ || typeof options?.moduleDir !== 'string') {
611
+ throw new PythonRuntimeError('invalid-request', '分析模块运行需要绝对 runDir / inputsDir / moduleDir');
612
+ }
613
+ const timeoutMs = options.timeoutMs;
614
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {
615
+ throw new PythonRuntimeError('invalid-request', 'timeoutMs 必须是正整数。');
616
+ }
617
+ const signal = options.signal;
618
+ const handle = await this.resolveDataRuntime();
619
+ const sitePackages = [...handle.sitePackages];
620
+ if (await exists(PYTHON_VENDOR_DIR))
621
+ sitePackages.push(PYTHON_VENDOR_DIR);
622
+ // The cache root can be mounted read-only for the running process; the child only needs a
623
+ // writable HOME/TMPDIR, and the run directory itself already lives in the workspace.
624
+ const homeDir = join(tmpdir(), 'cg-analysis-home');
625
+ const tempDir = join(tmpdir(), 'cg-analysis-tmp');
626
+ await mkdir(homeDir, { recursive: true, mode: 0o700 });
627
+ await mkdir(tempDir, { recursive: true, mode: 0o700 });
628
+ const env = pythonChildEnv({ pythonDir: dirname(handle.python), homeDir, tempDir, baseEnv: process.env });
629
+ const args = [
630
+ ...pythonFlags,
631
+ this.workerPath,
632
+ 'analysis',
633
+ ...sitePackages.flatMap((item) => ['--site-packages', item]),
634
+ '--run-dir',
635
+ options.runDir,
636
+ '--module-dir',
637
+ options.moduleDir,
638
+ '--inputs-dir',
639
+ options.inputsDir,
640
+ '--entrypoint',
641
+ entrypoint,
642
+ '--capabilities',
643
+ options.capabilities.join(','),
644
+ '--limits',
645
+ JSON.stringify({
646
+ max_input_rows: options.limits.max_input_rows,
647
+ max_output_bytes: options.limits.max_output_bytes,
648
+ max_log_bytes: options.limits.max_log_bytes,
649
+ }),
650
+ ];
651
+ const worker = await this.runWorker({
652
+ python: handle.python,
653
+ args,
654
+ cwd: options.runDir,
655
+ env,
656
+ timeoutMs,
657
+ ...(signal === undefined ? {} : { signal }),
658
+ });
659
+ if (worker.spawnError !== undefined) {
660
+ throw new PythonRuntimeError('script-failed', `启动 Python 失败:${worker.spawnError}`, diagnosticTail(worker.stderr));
661
+ }
662
+ if (worker.timedOut)
663
+ throw new PythonRuntimeError('timeout', `分析模块超时(${timeoutMs}ms)。`, diagnosticTail(worker.stderr));
664
+ if (worker.aborted)
665
+ throw new PythonRuntimeError('cancelled', undefined, diagnosticTail(worker.stderr));
666
+ const executed = recordOf(await readJson(join(options.runDir, 'result.json')));
667
+ if (executed === undefined) {
668
+ throw new PythonRuntimeError('script-failed', `分析模块没有写出 result.json(退出码 ${String(worker.code)})。`, diagnosticTail(worker.stderr || worker.stdout));
669
+ }
670
+ const failure = recordOf(executed.error);
671
+ if (executed.ok !== true) {
672
+ const workerMessage = typeof failure?.message === 'string' && failure.message.trim() !== '' ? failure.message.trim() : undefined;
673
+ const message = lastStderrLine(worker.stderr) ?? workerMessage ?? `分析模块退出码 ${String(worker.code)}。`;
674
+ const analysisCode = typeof failure?.code === 'string' && failure.code.startsWith('analysis_') ? failure.code : undefined;
675
+ throw new PythonRuntimeError('script-failed', message, failureDiagnostics(worker, failure), analysisCode);
676
+ }
677
+ return {
678
+ result: executed.result,
679
+ pythonVersion: typeof executed.python === 'string' ? executed.python : handle.pythonVersion,
680
+ durationMs: typeof executed.durationMs === 'number' && Number.isFinite(executed.durationMs) ? executed.durationMs : 0,
681
+ };
682
+ }
595
683
  async resolve(packs = ['base']) {
596
684
  const names = normalizePackNames(packs);
597
685
  const target = this.targetId();
@@ -28,7 +28,11 @@ export async function runWorkerProcess(options) {
28
28
  setTimeout(() => { void killTree(child.pid, child, 'SIGKILL'); }, 2_000).unref?.();
29
29
  }, options.timeoutMs);
30
30
  timer.unref?.();
31
- const abort = () => { void killTree(child.pid, child, 'SIGTERM'); };
31
+ // Abort escalates once: a child that ignores SIGTERM would keep the workspace run directory open.
32
+ const abort = () => {
33
+ void killTree(child.pid, child, 'SIGTERM');
34
+ setTimeout(() => { void killTree(child.pid, child, 'SIGKILL'); }, 5_000).unref?.();
35
+ };
32
36
  options.signal?.addEventListener('abort', abort, { once: true });
33
37
  const finish = (code) => {
34
38
  if (settled)
@@ -19,7 +19,7 @@ export function apply(ctx, config = {}) {
19
19
  let lastRenderError;
20
20
  ctx.effect(() => {
21
21
  // Every role that can load a skill also needs the boundary that says where its data comes from.
22
- const disposeContract = ctx.systemPrompt.section(dataContractSection());
22
+ const disposeContract = ctx.systemPrompt.section(dataContractSection(role));
23
23
  const dispose = ctx.systemPrompt.section({
24
24
  name: SECTION_NAME,
25
25
  order: SECTION_ORDER,
@@ -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.30.1";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.31.1";
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.30.1';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.31.1';
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.30.1";
38
+ export declare const WIND_CLIENT_VERSION = "2.31.1";
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.30.1';
22
+ export const WIND_CLIENT_VERSION = '2.31.1';
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.30.1",
3
+ "version": "2.31.1",
4
4
  "description": "Capital Generation:面向中国散户的 AI 投资助手插件",
5
5
  "icon": "assets/cg-icon.png",
6
6
  "author": "v587d",
@@ -37,6 +37,11 @@
37
37
  "import": "./lib/policy-entry.js",
38
38
  "default": "./lib/policy-entry.js"
39
39
  },
40
+ "./tools/analysis": {
41
+ "types": "./lib/analysis-entry.d.ts",
42
+ "import": "./lib/analysis-entry.js",
43
+ "default": "./lib/analysis-entry.js"
44
+ },
40
45
  "./tools/chart-render": {
41
46
  "types": "./lib/chart-render-entry.d.ts",
42
47
  "import": "./lib/chart-render-entry.js",
@@ -56,8 +56,8 @@
56
56
  而 skill 只在模型决定加载时才生效。
57
57
  - **按需进 `skills/`**:载荷 JSON 样例、字段级规则、`error/code → 处置`表、四态事实怎么读、
58
58
  QuerySpec 细则、检索收敛法则、官方域名核验清单、回传格式范例。
59
- - **子 Agent 也能按需加载**:每颗角色 preset 自己挂 `@deepseek-ai/dsh-tool-skill` 行(四颗在用角色都有;预留的
60
- `capital-data-analyst` declaration 已 disabled,恢复时要去掉 `disabled`),子 Agent 就同时拿到
59
+ - **子 Agent 也能按需加载**:每颗角色 preset 自己挂 `@deepseek-ai/dsh-tool-skill` 行(五颗角色都有),
60
+ 子 Agent 就同时拿到
61
61
  目录与加载器。判据在 `dsh-tools` 的 `view()`:restriction 过滤**继承层(全局 + 全部祖先
62
62
  scope,含 preset 层)**,只豁免"本 scope 自己注册的"工具;而 `dsh-tool-skill` 发布目录的
63
63
  条件正是 `ctx.tools.get('skill', agent) === 该注册对象`。源码注释里记着这段历史坑
@@ -144,10 +144,9 @@
144
144
  - 不用 `dsh-time-context` 行:它每个 step 自动注入时钟读数,与自研 `get_local_datetime`
145
145
  重复;时间读数只来自后者(会话组作用域内注册,主 Agent 与全部子 Agent 共享,支持
146
146
  `timezone` 换算)。
147
- - `data_analyst` 的 preset 与委派行都保持 `disabled`(2026-10-18 用户要求先停用,等价于注释)。
148
- 恢复前置条件(缺一不可):宿主先实现 Python runner 与 coding 工具;插件注册 `read_profile`
149
- (新工具必须先有族行带它、行契约同步);更新 `AGENTS.md`、`docs/dev/data-roles.md` 与
150
- `test/persona.test.mjs` 的预留期断言。
147
+ - `senior_analyst`(preset id 仍 `capital-data-analyst`,卡片名「高级分析师」)在 Phase 3 启用:preset 与
148
+ 委派行去掉 `disabled`,工具面只有分析族行 + time + skill + send_message(叶子,无 shell / PTC / 取数)。
149
+ 再停用 = 把这两处 `disabled` 加回去;它的边界、四册 skill 与直连语义见 `docs/dev/senior-analysis.md`。
151
150
 
152
151
  ## 5.1 shell 与文件口:主 Agent 保留 shell,data_junior 用 PTC(2026-10-15 / 2026-10-23)
153
152
 
@@ -42,15 +42,15 @@
42
42
  2. 取数:按问题选足相关能力,不限;request_data 阻塞等待(超时约 30 秒),一次只请求一个能力、串行推进。
43
43
  params 按 input_schema 填,capability 以 list_capabilities 目录为准,不编造。
44
44
  宿主只复用满足来源新鲜度要求的 Dataset;要最新 force_refresh=true,绝不覆盖旧文件。
45
- 遇 request_params_invalid,按错误中的 capability 调 describe_capability 重读 input_schema,修正 params 后只重试一次;不要猜参数。
45
+ 遇 request_params_invalid,按错误中的 capability 调 describe_capability 重读 input_schema,修正后只重试一次;不要猜参数。
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
51
  处置(可重试上游最多 3 次尝试;先换等价能力;upstream_retry_exhausted 即回传 failed,不再调用/wait_agent)。
52
- 5. 叶子边界:你不创建、不委派、不指挥任何下游子 Agent(data_junior 由主 Agent 直接创建,
53
- 不归你创建、不归你指挥),互通一律经主 Agent 中继。
52
+ 5. 叶子边界:你不创建、不委派、不指挥任何下游子 Agent(data_junior 由主 Agent 直接创建);
53
+ 数据可直达 data-junior / senior-analyst。
54
54
 
55
55
 
56
56
  # TIME DISCIPLINE
@@ -133,7 +133,7 @@
133
133
  (DatasetRef + 问题;describe_dataset 一次描述,单点复核才用 inspect/profile/query_dataset),
134
134
  以及无 Dataset 假设建模(主 Agent 给)。有 Dataset 时按 DUTIES 6 出图;
135
135
  创建 specialist 后等终态再回传。载荷中不得出现原始数据行。你不是投资分析师
136
- (不做投资判断、不输出买卖建议),也不改写原始 Dataset。你是主 Agent 的直接子 Agent,与 data_collector 是兄弟,不会被 data_collector 创建,互通经主 Agent 中继;
136
+ (不做投资判断、不输出买卖建议),也不改写原始 Dataset。你是主 Agent 的直接子 Agent,与 data_collector 是兄弟,不会被 data_collector 创建,补计算回执直达 senior-analyst,其余经 lead;
137
137
  visualization_specialist 是你的异步子 Agent,不直接发消息。
138
138
  工具面没有外部行情 API、网页检索与凭据入口;run_code 里的 Node 也不得用于取数、联网或读凭据;宿主若暴露 web_search / web_fetch 也不得用于取数或查资料。不索取或保存账户密码。
139
139
 
@@ -146,9 +146,9 @@
146
146
  1. 启动自检:先看 SDK 有无 tools.describe_dataset,没有就 send_message 回告;正常时登记 data_junior_ready。
147
147
 
148
148
  2. 只用受控工具:dataset_ids 按主 Agent 转发的原样使用;一切路径都是 opaque
149
- artifact_ref(workspace://...),由受控工具解析;Dataset 工具只收 dataset_id 与 QuerySpec,
149
+ artifact_ref,由受控工具解析;Dataset 工具只收 dataset_id 与 QuerySpec,
150
150
  run_code 只调度工具与算术,不得读文件。
151
- 3. 默认用 describe_dataset 读 Dataset(多份在同一 run_code 程序里 Promise.all,见 PROGRAM DISCIPLINE);inspect_dataset/profile_dataset/query_dataset 只用于单点复核。优先用 profile 的 time_facts 与 structure;query_dataset 只做受控聚合,你取不到原始行。
151
+ 3. 默认用 describe_dataset 读 Dataset(多份用 Promise.all,见 PROGRAM DISCIPLINE);inspect_dataset/profile_dataset/query_dataset 只用于单点复核。优先用 profile 的 time_facts 与 structure;query_dataset 只做受控聚合,你取不到原始行。
152
152
 
153
153
  4. 数据缺口:先分清「数据里确实没有」与「那份数据还没取」。后者不要写成「无法确认」,
154
154
  立即用 send_message({ agent: "lead" }) 发一次 data_gap(task_id / dataset_id / need / reason /
@@ -400,53 +400,43 @@
400
400
  - id: capital-time-tools
401
401
  name: '@v587d/capital-generation/tools/time'
402
402
 
403
- # `disabled` is the restore point, not deleted; enabling needs a Python runner + role allow (./README.md §5).
403
+ # Phase 3 enabled it: the analysis family row + reviewed module are the prerequisites (./README.md §5).
404
404
  - id: preset-capital-data-analyst
405
405
  name: '@deepseek-ai/dsh-agent-preset'
406
- disabled: true
407
406
  config:
408
407
  id: capital-data-analyst
409
- name: 专业分析(未启用)
410
- description: 用 Python 做逐行分析与统计检验(开发中,暂未启用)。
408
+ name: 高级分析师
409
+ description: 高级分析师(内部角色):用受控分析模块复核财务质量、收益风险与情景敏感性,结论必须可溯源。
410
+ order: 7
411
411
  plugins:
412
412
  - id: persona
413
413
  name: '@deepseek-ai/dsh-persona'
414
414
  config:
415
415
  prefix: |-
416
- # ROLE & IDENTITY(预留角色,启用后生效)
417
- 你是金融工程研究员(data_analyst)。
418
- 你的职责:接收 DatasetRef + data_junior profile 引用 + 用户问题;启用后使用宿主提供的
419
- Python runner 与 coding tools(当前均未实现)按需读取数据完成专业分析(技术分析、
420
- 财务计算、回测、统计检验),回传分析结论、证据 DatasetRef、派生结果 artifact_ref
421
- 与局限性。
422
- 你是主 Agent 的直接子 Agent,与 data_collector / data_junior 是兄弟,互通
423
- 一律经主 Agent 中继。
424
- 你只接收 DatasetRef 与 profile 引用,绝不接收主 Agent 转发的完整表格、
425
- data_collector 的原始 API 返回值或未经 DatasetRef 授权的任意文件路径。
426
-
427
- # PROTOCOL(预留;启用后与主 Agent 约定)
428
- 请求(主 Agent → 你):
429
- {
430
- "type": "analysis_request",
431
- "task_id": "task_01J...",
432
- "dataset_ids": ["ds_01J..."],
433
- "profile_ids": ["profile_01J..."],
434
- "question": "分析近一年趋势、波动和最大回撤",
435
- "constraints": { "must_show_method": true, "must_report_limitations": true }
436
- }
437
- 完成回传(你 → 主 Agent):
438
- 分析结论 + 证据 DatasetRef + 派生结果 artifact_ref + 局限性;
439
- 必要时保存 analysis.py / result.json / report.md,回传其 artifact_ref。
440
- 失败回传:
441
- { "type": "analysis_failed", "task_id": "task_01J...", "error": "...", "code": "..." }
442
- 硬规则:
443
- - 任何消息不携带完整原始 rows;一切路径都是 opaque artifact_ref,
444
- 由受控工具解析,不传文件绝对路径。
445
- - 分析脚本与运行环境分开;依赖来自项目配置声明,不由数据内容或网页临时注入。
416
+ # ROLE & IDENTITY
417
+ 你是高级分析师(senior_analyst):投研任务的结论层,把已取回的材料变成可核查的判断;
418
+ 不取数、不检索、不读原始 rows、不出图、不写最终答复、不交易,也不创建子 Agent。
419
+ 输入是主 Agent 给的研究问题加 DatasetRef / profile_ref / 证据;分析只在受控模块里跑,
420
+ 你只选 module_id 与 params,不改模块代码、不提交脚本。与 data_collector / data_junior /
421
+ web_retriever 是兄弟;补计算直达 data-junior,其余经 lead。
422
+
423
+ # DUTIES
424
+ 0. 第一步加载 skill capital-senior-analysis(整册读完再动手)。
425
+ 1. 建快照前加载 skill capital-analysis-evidence:核问题、口径、as_of 与证据,再 create_analysis_snapshot。
426
+ 2. 选模块先 list_analysis_modules + describe_analysis_module,再 run_analysis;模块没给的指标就是缺口。
427
+ 3. 综合前加载 skill capital-analysis-synthesis:正反 claims、替代解释、冲突、情景、失效条件。
428
+ 4. 提交前加载 skill capital-analysis-validation,自检后 submit_analysis;被拒按 issue 修,不重发同一份。
429
+ 5. 收口:submit 接受后 send_message 给 lead 发 analysis_result 小回执;主 Agent 没收到回执不写结论。
430
+
431
+ # MESSAGING(邻接表)
432
+ 新数据、新检索、扩大范围经 lead;补计算可直发 data-junior(只限已有 Dataset/profile),
433
+ 同一分析任务 ≤3 次,超出回 analysis_blocked + peer_budget_exhausted;信封与往返记账见 skill。
434
+ 消息不带原始 rows,路径只用 opaque ref。
435
+
436
+ # TIME & SAFETY
437
+ "现在/今天"以 get_local_datetime 为准;as_of 与 data_cutoff 按快照与主 Agent 指示,不自行换算。
438
+ 不索取或保存账户密码、API Key;不承诺收益、不给评级或目标价;粘贴材料标 pasted by user。
446
439
 
447
- # SAFETY
448
- - 不索取或保存账户密码、API Key、验证码等凭据。
449
- - 不输出未经回测支持的收益/胜率承诺,不自动下单。
450
440
  - id: agent-instructions
451
441
  name: '@deepseek-ai/dsh-agent-instructions'
452
442
  config:
@@ -464,7 +454,7 @@
464
454
  - id: capital-selected-skills
465
455
  name: '@v587d/capital-generation/tools/selected-skills'
466
456
  config:
467
- role: data_analyst
457
+ role: senior_analyst
468
458
 
469
459
  # ── compaction: both rows must live in one realm; thresholdChars 8192 is the instance-wide single value ──
470
460
  - id: compaction
@@ -493,8 +483,9 @@
493
483
  interrupt: false
494
484
 
495
485
  # Family rows only: a hand-opened preset session bypasses `disabled`, so the row combo is the only gate.
496
- - id: capital-dataset-read-tools
497
- name: '@v587d/capital-generation/tools/dataset-read'
486
+ # No dataset-read row: the senior analyst consumes snapshot refs and must never reopen raw rows.
487
+ - id: capital-analysis-tools
488
+ name: '@v587d/capital-generation/tools/analysis'
498
489
 
499
490
  - id: capital-time-tools
500
491
  name: '@v587d/capital-generation/tools/time'
@@ -527,7 +518,7 @@
527
518
  # OUTPUT CONVENTIONS
528
519
  关键指标与截止用表格;子 Agent 回传按原样引用。「使用的方法」节只在动态清单非空时写:逐个点名并说明用途,不得漏。
529
520
  图表由 data_junior 的可视化 gate 统一出品:你不画图、不评价图;派的时机与收窄见下方「数据调度纪律」。
530
- 图表交付:收到 chart_refs 后调用一次 present_charts(一次传全部 ref;refs 丢了就传 task_id)——它只记录清单,宿主会在最终答复前写入答复末尾的「交付」行,提前调用不会落进中间轮。正文不要提图表、不在正文里罗列图表文件 / 路径 / HTML。图表是呈现不是分析:不用图推断数字,数值结论一律以 profile / query 回传为准。
521
+ 图表交付:收到 chart_refs 后调用一次 present_charts(一次传全部 ref;refs 丢了就传 task_id)——它只记录清单,宿主会在最终答复前写入答复末尾的「交付」行。正文不要提图表、不在正文里罗列图表文件 / 路径 / HTML。图表是呈现不是分析:不用图推断数字,数值结论一律以 profile / query 回传为准。
531
522
  最终答(硬):必须自足——结论、关键证据与来源标注、局限与风险、观察 / 验证 / 防守选项;归因准确。**禁止“分析已完成 / 结论见上 / 如上”这类指针式收尾**:界面只展示最后一轮答复、前面轮次会被折叠,指针句会让用户什么也看不到。被通知唤醒且无新增信息时:不输出可见正文(让上一条完整结论成为最后一轮),或重发一份自足总结;绝不写「无新增信息」「结论见上」这类占位句。
532
523
 
533
524
  # RULES & DISCIPLINE
@@ -561,22 +552,21 @@
561
552
 
562
553
  4. 路由(硬)
563
554
  a. 行情/财务/历史→data_collector;质检/建模(DCF、估值、三表、情景、敏感性)/统计/可视化编排→data_junior;
564
- 网页事实 → web_retriever。即使不取数、只有用户假设也交 data_junior:你只给假设与口径,不自己算。
555
+ 网页事实 → web_retriever;结论层复核 → senior_analyst(投研/事件/财报质量/组合风险,单点事实不派)。
556
+ 即使不取数、只有用户假设也交 data_junior:你只给假设与口径,不自己算。
565
557
  prompt 带已消歧标的与完整代码;多角色可并行,先复用/创建并记清单。
566
558
 
567
- b. 主 Agent 禁止自行检索;宿主若仍暴露 web_search / web_fetch,也不得调用。
568
- 外部检索一律委派。
569
- 本地 PDF / 图片可直接用 ocr 解析(外部链接仍走委派)。
559
+ b. 主 Agent 禁止自行检索;宿主若仍暴露 web_search / web_fetch,也不得调用;外部检索一律委派。
560
+ 本地 PDF / 图片可直接用 ocr 解析(外部链接仍走委派)。
570
561
 
571
- c. data_collector、data_junior、web_retriever 是兄弟子 Agent,互通经主 Agent 中继;
572
- 根只发无 `/` 且不是 `lead` 的直系名,子 Agent 只回 `lead`;
562
+ c. 兄弟子 Agent 按邻接表直连(见 skill capital-orchestration);
563
+ 根只发无 `/` 且不是 `lead` 的直系名;senior 对 junior 只补计算(≤3 次),新数据/新检索仍经你;
573
564
  data_junior 是你的直接子 Agent,一律由你直接创建;data_collector 不得创建或指挥它。
574
565
 
575
566
  d. visualization_specialist 是 data_junior 的可视化孙 Agent;
576
567
 
577
- e. 没有通用委派出口:只有上面三颗专用工具(及 data_junior 的出图工具);
568
+ e. 没有通用委派出口:只有上面四颗专用工具(及 data_junior 的出图工具);
578
569
  不属于任何专用角色的活你自己做,或如实说明缺口,不派子 Agent。
579
- data_analyst 未启用:不创建。
580
570
 
581
571
  f. 委派一律异步 continuable:创建立即返回 name,本轮结束不等于它结束。
582
572
 
@@ -584,7 +574,8 @@
584
574
  写最终结论前对账:逐行核对每个子 Agent 在最后一次交互后
585
575
  是否收到结算通知(回传正文不算✓);
586
576
  缺一条本轮只写等待行;结论后再被唤醒就重新对账。
587
- 结算通知只证明该子 Agent 本轮结束,仍不等于任务完成;所有委派行都结算后才可收口。
577
+ 结算通知只证明本轮结束,仍不等于任务完成;所有委派行都结算后才可收口。
578
+ senior:未收到 analysis_result 不写结论;缺口原样转述。
588
579
  收口:对账通过 → 有图先 present_charts → 再写最终答复。
589
580
  等待:委派后调 wait_for_agents;message/user_input 先处理,
590
581
  all_settled 才对账;timeout 有 running 就继续等。
@@ -595,11 +586,10 @@
595
586
  5.1 子 Agent 中途请求(硬):收到中途消息(就绪登记或 data_gap 补数)是工单不是完成:就绪登记继续等;
596
587
  data_gap 按清单复用角色补齐,再发回**同一个**子 Agent,
597
588
  不必重跑本轮预检;「等数据」行收到结算不算完成。
598
- 错投补救:interrupt_agent({ agent: "<name>" }) 停当前轮。
599
- 取数失败或能力给不了这份数据时,也必须回一条消息告诉它
600
- (「数据源没有该字段」≠取数失败)。
589
+ 错投补救:interrupt_agent 停当前轮。
590
+ 取数失败或能力给不了时,也必须回一条消息告诉它(「数据源没有该字段」≠取数失败)。
601
591
 
602
- 6. 预检异常、委派清单格式与完整载荷示例见 skill capital-orchestration。
592
+ 6. 预检异常与清单格式见 skill capital-orchestration。
603
593
 
604
594
  # DATA COORDINATION(数据调度纪律)
605
595
  1. 主 Agent 禁止直接调用 request_data / list_capabilities / dc_status / Dataset 系列工具;
@@ -623,7 +613,7 @@
623
613
  原始行永不进入你的上下文;网页比对仅作异常抽样,不写成绝对真实。
624
614
 
625
615
  5. DatasetRef 元数据可直接引用;看内容或基础统计 → 委派 data_junior;
626
- 逐行 / 专业分析 → 告知 data_analyst 未启用,改用 junior 的受控统计与检索材料,并标明局限。
616
+ 逐行 / 专业分析、财务质量复核 → 委派 senior_analyst,把 refs 与口径给它。
627
617
  禁止直调 Dataset 工具;若遇 dataset_session_mismatch,不要重试直读,改委派。
628
618
 
629
619
  6. 行情数值必须来自 data_collector 结构化回传;网页数字只能标「媒体转述旁证」,
@@ -670,14 +660,13 @@
670
660
  provider: spawn
671
661
  toolName: subagent_web_retriever
672
662
  agentPreset: capital-web-retriever
673
- - id: tool-subagent-data-analyst
663
+ - id: tool-subagent-senior-analyst
674
664
  name: '@deepseek-ai/dsh-tool-subagent'
675
- disabled: true
676
665
  config:
677
666
  provider: spawn
678
- toolName: subagent_data_analyst
667
+ toolName: subagent_senior_analyst
679
668
  agentPreset: capital-data-analyst
680
- # If this row is ever enabled, `query_dataset` stays aggregate-only: it must not reopen raw rows.
669
+ # The preset id keeps the session-log identity; the tool name and tree name are the new ones.
681
670
  # 0.2.2 registers send_message / interrupt_agent / list_agents / wait_agent from the main
682
671
  # entry; the old `list-agents` subpath is gone and a row naming it keeps the preset broken.
683
672
  # dsh-base sets interrupt:false; the root must restate true (rc.2 honors the nearest row).
@@ -0,0 +1,99 @@
1
+ ---
2
+ name: capital-analysis-evidence
3
+ description: Use when freezing or reviewing the inputs of a Capital analysis — deciding which Dataset / profile / evidence refs belong in an AnalysisSnapshot, reading bounded profile facts, classifying missing data (not delivered vs not in the source vs unsupported), and writing an analysis_data_request through the lead.
4
+ ---
5
+
6
+ # 证据与快照(完整版)
7
+
8
+ 在建快照之前和读 profile 之后看这一册。它回答三件事:**这一版输入够不够支撑问题**、
9
+ **缺的那些分别属于哪一类**、**要补数据时怎么提**。提交前的数字规则在 `capital-analysis-validation`。
10
+
11
+ ## 1. 建快照前的六问
12
+
13
+ 1. **问题**:一句话说清要判断什么(不是"分析一下这家公司",而是"毛利率是否可持续 / 现金流是否支撑利润")。
14
+ 2. **标的**:公司 / 代码 / 组合,写进 `instrument`;多个标的要分开建快照,除非问题本身就是比较。
15
+ 3. **期间与 as_of**:结论站在哪一天、覆盖到哪个报告期或交易日;`as_of` 与 `data_cutoff` 必须来自主 Agent
16
+ 或用户,不自己推。as_of 晚于数据覆盖时,要在结论里点名"该窗口内没有数据"。
17
+ 4. **输入**:哪些 DatasetRef、哪些 profile、哪些证据条目,各自服务于哪个子问题。
18
+ 5. **证据等级**:官方披露 / 媒体转述 / 用户提供;用户粘贴的材料标 `pasted by user`,不因粘贴提高置信度。
19
+ 6. **完成标准**:到什么程度算够(核心比率能否算全、关键事件是否有官方来源),写进 `constraints`。
20
+
21
+ 六问答不全就先问一次主 Agent,不要用默认值把问题糊过去。
22
+
23
+ ## 2. 快照里放什么
24
+
25
+ ```json
26
+ {
27
+ "task_id": "task_...", "question": "...", "instrument": "600519.SH",
28
+ "purpose": "research", "depth": "standard", "as_of": "2025-06-30",
29
+ "dataset_refs": [{ "dataset_id": "ds_..." }],
30
+ "profile_refs": [{ "profile_id": "profile_..." }],
31
+ "evidence": [{ "source_id": "ev_annual_2024", "kind": "filing",
32
+ "title": "2024 年年度报告", "published_at": "2025-03-28",
33
+ "excerpt": "营收…(只放摘要)", "verification": "verified_official" }],
34
+ "prior_analysis_refs": [], "constraints": { "must_show_method": true }
35
+ }
36
+ ```
37
+
38
+ - `kind` 只能 `filing` / `news` / `research` / `user_material`;
39
+ `verification` 只能 `verified_official` / `unverified` / `not_verified`——**没有官方来源就写后两个**,
40
+ 不要为了"看起来权威"写 verified。
41
+ - `excerpt` 是摘要,不是全文;正文留在检索侧,快照不存大段文本。
42
+ - refs 逐份校验:任意一份读不到、过期或不属于本会话,整次建快照失败并点名是哪一份——先修 ref,不要删掉它硬建。
43
+ - 同一任务重跑要**重建**快照;旧快照不会因为主 Agent 补了新数据而更新。
44
+
45
+ ## 3. 读 profile 的纪律
46
+
47
+ - `read_profile` 只给有界事实:行数、列、缺失、重复、时间覆盖与质量标签,**没有行级数据**。
48
+ - 判断"这份数据能不能支撑结论"看三点:列是否覆盖所需字段、时间覆盖是否包含所需期间、
49
+ 质量标签(`validation` / `warnings`)里有没有致命项。
50
+ - 超预算时工具返回小回执 + hint:用 `columns_of_interest` 收窄,不要反复原样重读。
51
+ - profile 事实是**输入说明**,不是结论本身;不要把它改写成"数据很好/很差"这种判断。
52
+
53
+ ## 4. 缺口的三种来源(处置完全不同)
54
+
55
+ | 缺口 | 表现 | 处置 |
56
+ |---|---|---|
57
+ | **还没取到** | 快照里没有这份 Dataset / 字段 | 发 `analysis_data_request` 给 lead;不加默认值 |
58
+ | **数据里确实没有** | 列在、值缺失或字段未披露 | 写 `data_gaps`,结论降级,点名缺哪个字段哪一期 |
59
+ | **口径不支持** | 有数据但频率/币种/期间对不上,或模块不适用 | 换模块或如实写"本模块口径算不了",不硬套 |
60
+
61
+ 三类都要在回执里说清,主 Agent 才能决定是补数还是降级答复。
62
+
63
+ ## 5. 补数请求(经主 Agent)
64
+
65
+ ```json
66
+ { "protocol": "capital.agent.message/v1", "type": "analysis_data_request",
67
+ "task_id": "task_...", "analysis_id": "analysis_...",
68
+ "payload": { "instrument": "600519.SH", "need": ["利润表 2021-2024 年报"],
69
+ "fields": ["operating_income", "net_profit", "operating_costs"],
70
+ "period": ["2021", "2022", "2023", "2024"], "as_of": "2025-06-30",
71
+ "why": "财务质量模块需要多期趋势,目前只有 2024 一期", "blocking": true } }
72
+ ```
73
+
74
+ - 一次把要什么写全:标的、字段、期间、as_of、用途、是否阻塞;不要挤牙膏式一条一条要。
75
+ - `blocking: false` 表示可以先出降级结论;`true` 表示没有它就只能 blocked。
76
+ - 不要在请求里指定数据源或给服务商键名——那是主 Agent 和取数侧的事。
77
+
78
+ ## 6. 首个模块 `financial_quality` 的输入契约
79
+
80
+ - 吃**三份 Dataset**:利润表(`operating_income` + `net_profit`)、资产负债表(`assets_total` +
81
+ `holder_equity_total`)、现金流量表(`act_cash_flow_net`)。靠列签名识别,不需要预拼宽表。
82
+ - 三份都要有公共报告期键:优先 `period_end_ms`,否则 `period`;同一报表同一报告期只能一行。
83
+ - `params`:`period`(可选,默认最新一期;`2024`、`2024-FY`、`2024-12-30` 都认,报错会列出可选报告期)、
84
+ `compare_previous`(可选,默认 true 算环比)、以及 `income_dataset_id` / `balance_dataset_id` /
85
+ `cashflow_dataset_id`(多份同型时报错时用来指名)。
86
+ - **报告期标签来自报告期键,不来自数据源的 `period` 列**:A 股三表的 `period` 列实测是常量 `annual`,
87
+ 每期都一样;选期用 `period_end_ms` 的日期(如 `2024-12-30`)或 `fiscal_year`(如 `2024`)。
88
+ `financial_indicators` 这类 **document 型 Dataset 不能当分析输入**(没有行数组),不要塞进快照。
89
+ - 返回:`metrics`(比率 6 位小数、金额原币元、`currency` 记币种)、`assumptions`(EBIT 近似、
90
+ 期末余额口径、`total_debt` 是负债合计不是有息负债、累计口径、不换汇)、`data_gaps`(缺表/缺列/
91
+ 分母无经济含义)、`outputs`(每个指标的公式与输入值,可逐项复算)。
92
+ - `status` 语义:三张表齐且零缺口 → `completed`;有缺口 → `partial`;缺利润表 → `blocked`。
93
+ `partial` 不是失败,是"这几项没算"的诚实表达,如实转述。
94
+
95
+ ## 7. 证据不足也要给结论
96
+
97
+ - 允许建快照、跑模块、提交 `partial` / `blocked` 产物;**不允许**用训练记忆或行业常识补缺的数字。
98
+ - `evidence_level=insufficient` 时产物 `status` 不能写 `completed`。
99
+ - 结论强度跟着证据走:官方披露 > 媒体转述 > 用户提供;单一来源的关键判断要标"待交叉验证"。