@v587d/capital-generation 2.30.1 → 2.31.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.
- package/CHANGELOG.md +79 -0
- package/README.md +4 -4
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/automation/package.json +1 -1
- package/automation/storage.js +4 -0
- package/chart-ui/package.json +1 -1
- package/config/client.js +1 -1
- package/config/package.json +1 -1
- package/lib/agents/messaging-policy.d.ts +1 -1
- package/lib/agents/role-tool-policy.d.ts +3 -0
- package/lib/agents/role-tool-policy.js +12 -2
- package/lib/agents/selected-skills-provider.d.ts +1 -1
- package/lib/agents/selected-skills-provider.js +3 -1
- package/lib/analysis/registry.d.ts +12 -0
- package/lib/analysis/registry.js +76 -0
- package/lib/analysis/runtime.d.ts +87 -0
- package/lib/analysis/runtime.js +225 -0
- package/lib/analysis/schemas.d.ts +52 -0
- package/lib/analysis/schemas.js +270 -0
- package/lib/analysis/snapshot.d.ts +102 -0
- package/lib/analysis/snapshot.js +266 -0
- package/lib/analysis/storage.d.ts +64 -0
- package/lib/analysis/storage.js +96 -0
- package/lib/analysis/tools.d.ts +17 -0
- package/lib/analysis/tools.js +352 -0
- package/lib/analysis/types.d.ts +201 -0
- package/lib/analysis/types.js +44 -0
- package/lib/analysis/validation.d.ts +44 -0
- package/lib/analysis/validation.js +338 -0
- package/lib/analysis-entry.d.ts +10 -0
- package/lib/analysis-entry.js +7 -0
- package/lib/data-collector/store.d.ts +14 -1
- package/lib/data-collector/store.js +44 -0
- package/lib/data-contract.d.ts +3 -2
- package/lib/data-contract.js +18 -2
- package/lib/preset-ids.d.ts +5 -0
- package/lib/preset-ids.js +7 -1
- package/lib/python-runtime/errors.d.ts +7 -1
- package/lib/python-runtime/errors.js +9 -1
- package/lib/python-runtime/manager.d.ts +30 -0
- package/lib/python-runtime/manager.js +88 -0
- package/lib/python-runtime/probe.js +5 -1
- package/lib/selected-skills-entry.js +1 -1
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +6 -1
- package/preset/capital-generation/README.md +5 -6
- package/preset/capital-generation/agent.patch.yml +47 -58
- package/preset/capital-generation/skills/capital-analysis-evidence/SKILL.md +99 -0
- package/preset/capital-generation/skills/capital-analysis-synthesis/SKILL.md +110 -0
- package/preset/capital-generation/skills/capital-analysis-validation/SKILL.md +93 -0
- package/preset/capital-generation/skills/capital-data-query/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-equity-research/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-event-impact/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-orchestration/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-portfolio-review/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-senior-analysis/SKILL.md +100 -0
- package/python/analysis/modules/financial_quality/LICENSE +27 -0
- package/python/analysis/modules/financial_quality/module.json +65 -0
- package/python/analysis/modules/financial_quality/module.py +535 -0
- package/python/analysis/modules/hello/LICENSE +21 -0
- package/python/analysis/modules/hello/module.json +46 -0
- package/python/analysis/modules/hello/module.py +56 -0
- package/python/worker.py +152 -5
- package/selected-skills/routing.js +5 -2
- package/watchlist/package.json +1 -1
|
@@ -188,7 +188,7 @@ export interface ProfilePayload {
|
|
|
188
188
|
validation?: ProfileValidation;
|
|
189
189
|
warnings: string[];
|
|
190
190
|
}
|
|
191
|
-
export type DatasetStoreErrorCode = 'workspace_not_writable' | 'session_unavailable' | 'session_cwd_unavailable' | 'sandbox_policy_unavailable' | 'filesystem_unavailable' | 'dataset_write_failed' | 'dataset_id_invalid' | 'dataset_not_found' | 'dataset_expired' | 'dataset_session_mismatch' | 'dataset_manifest_invalid' | 'dataset_format_unsupported' | 'dataset_not_row_readable' | 'dataset_too_large' | 'profile_invalid' | 'profile_too_large' | 'profile_dataset_mismatch' | 'workspace_path_invalid' | 'workspace_file_invalid';
|
|
191
|
+
export type DatasetStoreErrorCode = 'workspace_not_writable' | 'session_unavailable' | 'session_cwd_unavailable' | 'sandbox_policy_unavailable' | 'filesystem_unavailable' | 'dataset_write_failed' | 'dataset_id_invalid' | 'dataset_not_found' | 'dataset_expired' | 'dataset_session_mismatch' | 'dataset_manifest_invalid' | 'dataset_format_unsupported' | 'dataset_not_row_readable' | 'dataset_too_large' | 'profile_invalid' | 'profile_not_found' | 'profile_expired' | 'profile_too_large' | 'profile_dataset_mismatch' | 'workspace_path_invalid' | 'workspace_file_invalid';
|
|
192
192
|
export declare class DatasetStoreError extends Error {
|
|
193
193
|
readonly code: DatasetStoreErrorCode;
|
|
194
194
|
constructor(code: DatasetStoreErrorCode, detail: string);
|
|
@@ -356,6 +356,19 @@ export declare class WorkspaceDatasetStore {
|
|
|
356
356
|
signal?: AbortSignal;
|
|
357
357
|
}): Promise<TimeAxisSnapshot | undefined>;
|
|
358
358
|
writeProfile(input: WriteProfileInput): Promise<ProfileRef>;
|
|
359
|
+
/**
|
|
360
|
+
* Host-internal profile read (analysis staging and `read_profile`). Same scope and expiry rules as
|
|
361
|
+
* Datasets: a profile belongs to the parent session scope and an expired one must not be analyzed.
|
|
362
|
+
* There is no model-facing read path for the raw profile object.
|
|
363
|
+
*/
|
|
364
|
+
readProfile(input: {
|
|
365
|
+
session: SessionLike;
|
|
366
|
+
profile_id: string;
|
|
367
|
+
signal?: AbortSignal;
|
|
368
|
+
}): Promise<{
|
|
369
|
+
ref: ProfileRef;
|
|
370
|
+
profile: ProfilePayload;
|
|
371
|
+
}>;
|
|
359
372
|
/**
|
|
360
373
|
* Host-internal presentation read (charts). The returned rows must never enter any agent message,
|
|
361
374
|
* tool result or model context; this is the only path that hands raw rows outside the store.
|
|
@@ -393,6 +393,50 @@ export class WorkspaceDatasetStore {
|
|
|
393
393
|
}
|
|
394
394
|
return profileRef;
|
|
395
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Host-internal profile read (analysis staging and `read_profile`). Same scope and expiry rules as
|
|
398
|
+
* Datasets: a profile belongs to the parent session scope and an expired one must not be analyzed.
|
|
399
|
+
* There is no model-facing read path for the raw profile object.
|
|
400
|
+
*/
|
|
401
|
+
async readProfile(input) {
|
|
402
|
+
if (!PROFILE_ID_PATTERN.test(input.profile_id))
|
|
403
|
+
throw new DatasetStoreError('profile_invalid', 'profile_id is invalid');
|
|
404
|
+
const root = this.readRoot(input.session);
|
|
405
|
+
if (!root || !this.fs)
|
|
406
|
+
throw new DatasetStoreError('filesystem_unavailable', 'workspace filesystem is unavailable');
|
|
407
|
+
let text;
|
|
408
|
+
try {
|
|
409
|
+
const target = await this.resolveContained(`${PROFILES_SUBDIR}/${input.profile_id}/${PROFILE_FILE}`, root, input.signal);
|
|
410
|
+
text = await this.fs.readText(target, input.signal);
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
if (errorCodeOf(error) === 'FS_NOT_FOUND')
|
|
414
|
+
throw new DatasetStoreError('profile_not_found', `profile ${input.profile_id} was not found`);
|
|
415
|
+
if (error instanceof DatasetStoreError)
|
|
416
|
+
throw error;
|
|
417
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json could not be read');
|
|
418
|
+
}
|
|
419
|
+
let parsed;
|
|
420
|
+
try {
|
|
421
|
+
parsed = JSON.parse(text);
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json is not valid JSON');
|
|
425
|
+
}
|
|
426
|
+
if (!isRecord(parsed) || !isRecord(parsed.ref))
|
|
427
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json is missing its ref');
|
|
428
|
+
const ref = parsed.ref;
|
|
429
|
+
if (typeof ref.profile_id !== 'string' || ref.profile_id !== input.profile_id) {
|
|
430
|
+
throw new DatasetStoreError('profile_invalid', 'profile ref does not match its directory');
|
|
431
|
+
}
|
|
432
|
+
if (ref.session_id !== sessionScopeFor(input.session)) {
|
|
433
|
+
throw new DatasetStoreError('dataset_session_mismatch', 'profile belongs to another session scope');
|
|
434
|
+
}
|
|
435
|
+
if (typeof ref.retention_until === 'number' && ref.retention_until <= this.now()) {
|
|
436
|
+
throw new DatasetStoreError('profile_expired', `profile ${input.profile_id} has expired`);
|
|
437
|
+
}
|
|
438
|
+
return { ref, profile: validateProfile(parsed.profile) };
|
|
439
|
+
}
|
|
396
440
|
/**
|
|
397
441
|
* Host-internal presentation read (charts). The returned rows must never enter any agent message,
|
|
398
442
|
* tool result or model context; this is the only path that hands raw rows outside the store.
|
package/lib/data-contract.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
export declare const DATA_CONTRACT_SECTION = "capital:data-contract";
|
|
8
8
|
/** Just before the selected-skill brief (order 60). */
|
|
9
9
|
export declare const DATA_CONTRACT_ORDER = 59;
|
|
10
|
-
export
|
|
10
|
+
export interface DataContractSection {
|
|
11
11
|
name: string;
|
|
12
12
|
order: number;
|
|
13
13
|
interpolate: false;
|
|
14
14
|
text: string;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
export declare function dataContractSection(role?: string): DataContractSection;
|
package/lib/data-contract.js
CHANGED
|
@@ -21,6 +21,22 @@ const TEXT = `# 数据边界
|
|
|
21
21
|
每个数字都要带出处(场所、文档名、文档日期、accession 或该次检索返回的链接)、取数路径与缺口。缺字段就点名缺哪个并停止该字段下的分析,不估算、不回填;用户粘贴的材料标 pasted by user,不因此提高置信度。
|
|
22
22
|
|
|
23
23
|
skill 正文只写"要什么证据",不写服务商、密钥、URL、下载步骤或脚本命令。`;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The senior analyst has no delegation right: its inputs arrive as an AnalysisSnapshot, and every
|
|
26
|
+
* request for more goes through the lead. Same section name, different text — one home per role.
|
|
27
|
+
*/
|
|
28
|
+
const SENIOR_TEXT = `# 数据边界
|
|
29
|
+
|
|
30
|
+
你的输入由宿主冻结的 \`AnalysisSnapshot\` 给出:Dataset / profile / 证据都以 opaque ref 出现,快照在前、分析在后。你不取数、不检索、不读原始 rows,也没有 shell 或文件入口。
|
|
31
|
+
|
|
32
|
+
- 缺数据(快照里没有的字段、期间或来源)→ 经主 Agent 发 \`analysis_data_request\`,写清标的、字段、期间与用途;由主 Agent 决定是否扩大范围。
|
|
33
|
+
- 需要补计算(用快照里已有的 Dataset/profile)→ 也经主 Agent 转交,并在请求里带 task_id 与要算的口径;不自己找 data_collector / web_retriever。
|
|
34
|
+
- \`run_analysis\` 只返回指标、假设、缺口与 run ref;原始 rows 留在快照的宿主副本里,不会进你的上下文。
|
|
35
|
+
|
|
36
|
+
每个数字都要能被宿主追溯:claim 的 \`number_anchors\`、\`calculations\` 必须指向快照里的 dataset / profile / evidence 或本次计算,否则 \`submit_analysis\` 会拒。缺字段就点名缺哪个并写进 \`data_gaps\`,不估算、不回填、不用训练记忆补数字。用户粘贴的材料标 pasted by user,不因此提高置信度。
|
|
37
|
+
|
|
38
|
+
skill 正文只写"要什么证据",不写服务商、密钥、URL、下载步骤或脚本命令。`;
|
|
39
|
+
export function dataContractSection(role) {
|
|
40
|
+
const text = role === 'senior_analyst' ? SENIOR_TEXT : TEXT;
|
|
41
|
+
return { name: DATA_CONTRACT_SECTION, order: DATA_CONTRACT_ORDER, interpolate: false, text };
|
|
26
42
|
}
|
package/lib/preset-ids.d.ts
CHANGED
|
@@ -36,3 +36,8 @@ export declare const DATA_COLLECTION_PRESET_IDS: readonly string[];
|
|
|
36
36
|
export declare const DATASET_READING_PRESET_IDS: readonly string[];
|
|
37
37
|
/** May issue `chart_source_ref` for chart reads. */
|
|
38
38
|
export declare const CHART_SOURCE_PRESET_IDS: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* May call the `tools/analysis` family. The senior analyst consumes snapshot refs and never reads
|
|
41
|
+
* raw rows, so it is deliberately absent from `DATASET_READING_PRESET_IDS` above.
|
|
42
|
+
*/
|
|
43
|
+
export declare const ANALYSIS_PRESET_IDS: readonly string[];
|
package/lib/preset-ids.js
CHANGED
|
@@ -28,6 +28,7 @@ export function isCapitalPresetId(id) {
|
|
|
28
28
|
export const INTERNAL_ROLE_PRESET_IDS = [
|
|
29
29
|
ROLE_PRESET_IDS.junior,
|
|
30
30
|
ROLE_PRESET_IDS.specialist,
|
|
31
|
+
ROLE_PRESET_IDS.analyst,
|
|
31
32
|
];
|
|
32
33
|
const INTERNAL_ROLE_PRESET_ID_SET = new Set(INTERNAL_ROLE_PRESET_IDS);
|
|
33
34
|
export function isInternalRolePresetId(id) {
|
|
@@ -41,6 +42,11 @@ export function isInternalRolePresetId(id) {
|
|
|
41
42
|
* data and chart layers must not depend on the agents layer.
|
|
42
43
|
*/
|
|
43
44
|
export const DATA_COLLECTION_PRESET_IDS = [ROLE_PRESET_IDS.collector];
|
|
44
|
-
export const DATASET_READING_PRESET_IDS = [ROLE_PRESET_IDS.junior
|
|
45
|
+
export const DATASET_READING_PRESET_IDS = [ROLE_PRESET_IDS.junior];
|
|
45
46
|
/** May issue `chart_source_ref` for chart reads. */
|
|
46
47
|
export const CHART_SOURCE_PRESET_IDS = [ROLE_PRESET_IDS.junior];
|
|
48
|
+
/**
|
|
49
|
+
* May call the `tools/analysis` family. The senior analyst consumes snapshot refs and never reads
|
|
50
|
+
* raw rows, so it is deliberately absent from `DATASET_READING_PRESET_IDS` above.
|
|
51
|
+
*/
|
|
52
|
+
export const ANALYSIS_PRESET_IDS = [ROLE_PRESET_IDS.analyst];
|
|
@@ -2,7 +2,13 @@ export type PythonRuntimeErrorCode = 'unsupported-platform' | 'manifest-invalid'
|
|
|
2
2
|
export declare class PythonRuntimeError extends Error {
|
|
3
3
|
readonly code: PythonRuntimeErrorCode;
|
|
4
4
|
readonly diagnostics?: string;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Stable analysis code raised by a reviewed module (e.g. `analysis_input_invalid`). The worker
|
|
7
|
+
* reports it because a module cannot throw a TypeScript error; `script-failed` alone would hide
|
|
8
|
+
* "this input shape is unsupported" behind "the module crashed".
|
|
9
|
+
*/
|
|
10
|
+
readonly analysisCode?: string;
|
|
11
|
+
constructor(code: PythonRuntimeErrorCode, message?: string, diagnostics?: string, analysisCode?: string);
|
|
6
12
|
}
|
|
7
13
|
export declare function isPythonRuntimeError(value: unknown): value is PythonRuntimeError;
|
|
8
14
|
export declare function messageOf(value: unknown): string;
|
|
@@ -21,11 +21,19 @@ const MESSAGES = {
|
|
|
21
21
|
export class PythonRuntimeError extends Error {
|
|
22
22
|
code;
|
|
23
23
|
diagnostics;
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Stable analysis code raised by a reviewed module (e.g. `analysis_input_invalid`). The worker
|
|
26
|
+
* reports it because a module cannot throw a TypeScript error; `script-failed` alone would hide
|
|
27
|
+
* "this input shape is unsupported" behind "the module crashed".
|
|
28
|
+
*/
|
|
29
|
+
analysisCode;
|
|
30
|
+
constructor(code, message, diagnostics, analysisCode) {
|
|
25
31
|
super(message ?? MESSAGES[code]);
|
|
26
32
|
this.name = 'PythonRuntimeError';
|
|
27
33
|
this.code = code;
|
|
28
34
|
this.diagnostics = diagnostics;
|
|
35
|
+
if (analysisCode !== undefined)
|
|
36
|
+
this.analysisCode = analysisCode;
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
39
|
export function isPythonRuntimeError(value) {
|
|
@@ -35,6 +35,28 @@ export interface DataScriptResult {
|
|
|
35
35
|
pythonVersion: string;
|
|
36
36
|
durationMs: number;
|
|
37
37
|
}
|
|
38
|
+
export interface RunAnalysisModuleOptions {
|
|
39
|
+
/** Absolute directory of the reviewed module inside the package. */
|
|
40
|
+
moduleDir: string;
|
|
41
|
+
entrypoint: string;
|
|
42
|
+
/** Absolute run directory the worker reads `request.json` from and writes `result.json` into. */
|
|
43
|
+
runDir: string;
|
|
44
|
+
/** Absolute `inputs/` directory of the snapshot (staged dataset/profile/evidence copies). */
|
|
45
|
+
inputsDir: string;
|
|
46
|
+
capabilities: readonly string[];
|
|
47
|
+
limits: {
|
|
48
|
+
max_input_rows: number;
|
|
49
|
+
max_output_bytes: number;
|
|
50
|
+
max_log_bytes: number;
|
|
51
|
+
};
|
|
52
|
+
timeoutMs: number;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}
|
|
55
|
+
export interface AnalysisModuleRunResult {
|
|
56
|
+
result: unknown;
|
|
57
|
+
pythonVersion: string;
|
|
58
|
+
durationMs: number;
|
|
59
|
+
}
|
|
38
60
|
export declare class PythonRuntimeManager {
|
|
39
61
|
readonly manifest: RuntimeManifest;
|
|
40
62
|
readonly dshHome: string;
|
|
@@ -81,6 +103,14 @@ export declare class PythonRuntimeManager {
|
|
|
81
103
|
* an extra `--site-packages` entry so no pip/venv/pack is involved.
|
|
82
104
|
*/
|
|
83
105
|
runDataScript(options: RunDataScriptOptions): Promise<DataScriptResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Run one reviewed analysis module and return the object it wrote.
|
|
108
|
+
*
|
|
109
|
+
* The child gets a run directory inside the workspace: `request.json` is already there (the store
|
|
110
|
+
* wrote it), and the module's `outputs/` and `logs/` land beside it. The run directory is not
|
|
111
|
+
* deleted here — it is the audit trail; retention is the analysis layer's decision.
|
|
112
|
+
*/
|
|
113
|
+
runAnalysisModule(options: RunAnalysisModuleOptions): Promise<AnalysisModuleRunResult>;
|
|
84
114
|
resolve(packs?: unknown): Promise<RuntimeHandle>;
|
|
85
115
|
remove(pack: PackName): Promise<void>;
|
|
86
116
|
dispose(): Promise<void>;
|
|
@@ -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
|
-
|
|
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.
|
|
6
|
+
export declare const LOCAL_FETCH_CLIENT_VERSION = "2.31.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.
|
|
7
|
+
export const LOCAL_FETCH_CLIENT_VERSION = '2.31.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.
|
|
38
|
+
export declare const WIND_CLIENT_VERSION = "2.31.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
|
+
export const WIND_CLIENT_VERSION = '2.31.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.
|
|
3
|
+
"version": "2.31.0",
|
|
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
|
-
|
|
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
|
-
- `
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|