@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.
- package/CHANGELOG.md +127 -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 +23 -6
- package/lib/agents/messaging-policy.js +64 -9
- package/lib/agents/role-tool-policy.d.ts +3 -0
- package/lib/agents/role-tool-policy.js +15 -5
- 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 +58 -0
- package/lib/analysis/schemas.js +276 -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 +357 -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 +381 -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 +47 -1
- 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 +54 -65
- 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 +96 -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 +32 -27
- package/preset/capital-generation/skills/capital-portfolio-review/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-senior-analysis/SKILL.md +105 -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
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { HEADLINE_MAX_CHARS, MAX_CLAIMS, MAX_PEER_EXCHANGES, MAX_SCENARIOS, STATEMENT_MAX_CHARS, THESIS_MAX_CHARS } from './schemas.js';
|
|
2
|
+
/** Subset of JSON Schema used by the protocol: types, properties, required, items, enum, bounds. */
|
|
3
|
+
export function validateAgainstSchema(value, schema, path = '$') {
|
|
4
|
+
if (schema === undefined || Object.keys(schema).length === 0)
|
|
5
|
+
return [];
|
|
6
|
+
const issues = [];
|
|
7
|
+
if (Array.isArray(schema.anyOf)) {
|
|
8
|
+
const failures = schema.anyOf.map((option) => validateAgainstSchema(value, option, path));
|
|
9
|
+
if (failures.every((items) => items.length > 0))
|
|
10
|
+
issues.push(`${path} 不满足任何允许的形态`);
|
|
11
|
+
return issues;
|
|
12
|
+
}
|
|
13
|
+
const type = schema.type;
|
|
14
|
+
if (typeof type === 'string' && !matchesType(value, type)) {
|
|
15
|
+
issues.push(`${path} 应为 ${type},实际是 ${describeType(value)}`);
|
|
16
|
+
return issues;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((item) => item === value)) {
|
|
19
|
+
issues.push(`${path} 必须是 ${schema.enum.join(' / ')} 之一`);
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
const maxLength = schema.maxLength;
|
|
23
|
+
if (typeof maxLength === 'number' && value.length > maxLength)
|
|
24
|
+
issues.push(`${path} 超长:${value.length} > ${maxLength}`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === 'number' && typeof schema.minimum === 'number' && value < schema.minimum) {
|
|
27
|
+
issues.push(`${path} 小于最小值 ${schema.minimum}`);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
if (typeof schema.maxItems === 'number' && value.length > schema.maxItems) {
|
|
31
|
+
issues.push(`${path} 条目过多:${value.length} > ${schema.maxItems}`);
|
|
32
|
+
}
|
|
33
|
+
if (schema.items !== undefined) {
|
|
34
|
+
value.forEach((item, index) => issues.push(...validateAgainstSchema(item, schema.items, `${path}[${index}]`)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
38
|
+
const record = value;
|
|
39
|
+
const properties = (schema.properties ?? {});
|
|
40
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
41
|
+
for (const key of required) {
|
|
42
|
+
if (record[key] === undefined)
|
|
43
|
+
issues.push(`${path}.${key} 是必填字段`);
|
|
44
|
+
}
|
|
45
|
+
if (schema.additionalProperties === false) {
|
|
46
|
+
for (const key of Object.keys(record)) {
|
|
47
|
+
if (!(key in properties))
|
|
48
|
+
issues.push(`${path}.${key} 是未声明的字段`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const [key, childSchema] of Object.entries(properties)) {
|
|
52
|
+
if (record[key] !== undefined)
|
|
53
|
+
issues.push(...validateAgainstSchema(record[key], childSchema, `${path}.${key}`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return issues;
|
|
57
|
+
}
|
|
58
|
+
function matchesType(value, type) {
|
|
59
|
+
switch (type) {
|
|
60
|
+
case 'object': return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
61
|
+
case 'array': return Array.isArray(value);
|
|
62
|
+
case 'string': return typeof value === 'string';
|
|
63
|
+
case 'boolean': return typeof value === 'boolean';
|
|
64
|
+
case 'integer': return typeof value === 'number' && Number.isInteger(value);
|
|
65
|
+
case 'number': return typeof value === 'number' && Number.isFinite(value);
|
|
66
|
+
case 'null': return value === null;
|
|
67
|
+
default: return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function describeType(value) {
|
|
71
|
+
if (value === null)
|
|
72
|
+
return 'null';
|
|
73
|
+
if (Array.isArray(value))
|
|
74
|
+
return 'array';
|
|
75
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
76
|
+
return 'non-finite number';
|
|
77
|
+
return typeof value;
|
|
78
|
+
}
|
|
79
|
+
/** Lossless JSON: `undefined`, `NaN`, `Infinity` and array holes must not cross the boundary. */
|
|
80
|
+
export function losslessIssues(value, path = '$') {
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return [`${path} 是 undefined`];
|
|
83
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
84
|
+
return [`${path} 是 ${String(value)}(非有限数)`];
|
|
85
|
+
if (typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint')
|
|
86
|
+
return [`${path} 是 ${typeof value}`];
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
const issues = [];
|
|
89
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
90
|
+
if (!(index in value))
|
|
91
|
+
issues.push(`${path}[${index}] 是数组空洞`);
|
|
92
|
+
else
|
|
93
|
+
issues.push(...losslessIssues(value[index], `${path}[${index}]`));
|
|
94
|
+
}
|
|
95
|
+
return issues;
|
|
96
|
+
}
|
|
97
|
+
if (value !== null && typeof value === 'object') {
|
|
98
|
+
const issues = [];
|
|
99
|
+
for (const [key, item] of Object.entries(value))
|
|
100
|
+
issues.push(...losslessIssues(item, `${path}.${key}`));
|
|
101
|
+
return issues;
|
|
102
|
+
}
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
/** Validate the worker's result object: lossless, then the manifest's declared output schema. */
|
|
106
|
+
export function validateModuleResult(value, manifest) {
|
|
107
|
+
const issues = [];
|
|
108
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
issues: [{ code: 'analysis_output_invalid', severity: 'error', detail: '模块结果必须是 JSON 对象' }],
|
|
112
|
+
result: undefined,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
for (const detail of losslessIssues(value)) {
|
|
116
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', detail });
|
|
117
|
+
}
|
|
118
|
+
const schema = (manifest.output_schema ?? {});
|
|
119
|
+
for (const detail of validateAgainstSchema(value, schema)) {
|
|
120
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', detail });
|
|
121
|
+
}
|
|
122
|
+
const result = value;
|
|
123
|
+
if (typeof result.status !== 'string')
|
|
124
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field: 'status', detail: '模块结果缺 status' });
|
|
125
|
+
if (typeof result.summary !== 'string')
|
|
126
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field: 'summary', detail: '模块结果缺 summary' });
|
|
127
|
+
if (!Array.isArray(result.limitations))
|
|
128
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field: 'limitations', detail: '模块结果缺 limitations 数组' });
|
|
129
|
+
if (!Array.isArray(result.data_gaps))
|
|
130
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field: 'data_gaps', detail: '模块结果缺 data_gaps 数组' });
|
|
131
|
+
// §12.2: a result without assumptions or a method log is not reproducible, so it cannot be audited.
|
|
132
|
+
for (const [field, label] of [['assumptions', '假设'], ['methodology_log', '方法日志']]) {
|
|
133
|
+
const items = result[field];
|
|
134
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
135
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field, detail: `模块结果必须写明${label}(至少一条)` });
|
|
136
|
+
}
|
|
137
|
+
else if (items.some((item) => typeof item !== 'string' || item.trim() === '')) {
|
|
138
|
+
issues.push({ code: 'analysis_output_invalid', severity: 'error', field, detail: `${label}里不能有空串或非字符串` });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { ok: issues.every((issue) => issue.severity !== 'error'), issues, result };
|
|
142
|
+
}
|
|
143
|
+
const UNIT_CONSTANTS = new Set([1e4, 1e6, 1e8, 1e12]);
|
|
144
|
+
const YEAR = /^(?:19|20)\d{2}$/u;
|
|
145
|
+
const NUMBER_TOKEN = /-?\d+(?:\.\d+)?/gu;
|
|
146
|
+
const PERCENT_AFTER = /^\s*[%%]/u;
|
|
147
|
+
// Six-digit securities codes (`600519`, `000858`, `300750`, `920000`, funds `510300`) are identifiers,
|
|
148
|
+
// not measured values. Amounts that start with 1 or 2 still need an anchor.
|
|
149
|
+
const SECURITY_CODE = /^(?:0|[3-9])\d{5}$/u;
|
|
150
|
+
const COUNT_CLASSIFIER = /^\s*[个条项期只家次类轮档组段页册笔位名张份套种年]/u;
|
|
151
|
+
/** Numeric tokens with just enough context to honour the exemption set. */
|
|
152
|
+
export function numberTokens(text) {
|
|
153
|
+
const tokens = [];
|
|
154
|
+
for (const match of text.matchAll(NUMBER_TOKEN)) {
|
|
155
|
+
const start = match.index ?? 0;
|
|
156
|
+
const raw = match[0];
|
|
157
|
+
const value = Number(raw);
|
|
158
|
+
if (!Number.isFinite(value))
|
|
159
|
+
continue;
|
|
160
|
+
tokens.push({ text: raw, value, percent: PERCENT_AFTER.test(text.slice(start + raw.length)), start });
|
|
161
|
+
}
|
|
162
|
+
return tokens;
|
|
163
|
+
}
|
|
164
|
+
function tolerance(precision) {
|
|
165
|
+
const digits = typeof precision === 'number' && precision >= 0 && precision <= 12 ? precision : 4;
|
|
166
|
+
return 0.5 * 10 ** -digits;
|
|
167
|
+
}
|
|
168
|
+
function exemptToken(token, source) {
|
|
169
|
+
// Digits inside an identifier (`claim_1`, `FY2025`) are not quantities.
|
|
170
|
+
const before = source[token.start - 1];
|
|
171
|
+
const after = source[token.start + token.text.length];
|
|
172
|
+
if ((before !== undefined && /[A-Za-z_]/u.test(before)) || (after !== undefined && /[A-Za-z_]/u.test(after)))
|
|
173
|
+
return true;
|
|
174
|
+
if (!token.percent && YEAR.test(token.text))
|
|
175
|
+
return true;
|
|
176
|
+
// A securities code is an identifier, not a measured value.
|
|
177
|
+
if (!token.percent && SECURITY_CODE.test(token.text))
|
|
178
|
+
return true;
|
|
179
|
+
if (Number.isInteger(token.value) && Math.abs(token.value) <= 20) {
|
|
180
|
+
const head = source.slice(Math.max(0, token.start - 2), token.start);
|
|
181
|
+
if (/[第期条项]/u.test(head))
|
|
182
|
+
return true;
|
|
183
|
+
// Structural counts ("5 条"、"0 次"、"3 个情景") are not quantities to trace either.
|
|
184
|
+
if (!token.percent && COUNT_CLASSIFIER.test(source.slice(token.start + token.text.length)))
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (UNIT_CONSTANTS.has(token.value) && /^\d+$/u.test(token.text))
|
|
188
|
+
return true;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
/** Digits after the decimal point as written: `18.00` → 2, an integer → 0. */
|
|
192
|
+
function shownDecimals(text) {
|
|
193
|
+
const dot = text.indexOf('.');
|
|
194
|
+
return dot === -1 ? 0 : text.length - dot - 1;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Prose rounds stored values: `1.23` is how `1.2345` is written, `4.44%` is how `4.4444%` is
|
|
198
|
+
* written. Compare at the precision the prose actually shows, for fractional tokens only — an
|
|
199
|
+
* integer is a quantity in its own right, not a rounded fraction.
|
|
200
|
+
*/
|
|
201
|
+
function displayMatch(token, value) {
|
|
202
|
+
const decimals = shownDecimals(token.text);
|
|
203
|
+
if (decimals === 0)
|
|
204
|
+
return false;
|
|
205
|
+
// Symmetric half-digit tolerance, so negative values round the same way as positive ones.
|
|
206
|
+
return Math.abs(value - token.value) <= 0.5 * 10 ** -decimals + 1e-12;
|
|
207
|
+
}
|
|
208
|
+
function matchesToken(token, value, precision) {
|
|
209
|
+
const tol = tolerance(precision);
|
|
210
|
+
if (Math.abs(value - token.value) <= tol)
|
|
211
|
+
return true;
|
|
212
|
+
// Ratio written as a percentage (0.1823 ↔ 18.23) — same precision, scaled by 100.
|
|
213
|
+
if (Math.abs(value * 100 - token.value) <= Math.max(tol * 100, 0.5 * 10 ** -2))
|
|
214
|
+
return true;
|
|
215
|
+
if (displayMatch(token, value) || displayMatch(token, value * 100))
|
|
216
|
+
return true;
|
|
217
|
+
// Whole-number percentages are a rounded display too: 0.1804 written as 18%.
|
|
218
|
+
return token.percent && shownDecimals(token.text) === 0 && Math.abs(value * 100 - token.value) < 0.5;
|
|
219
|
+
}
|
|
220
|
+
function anchoredNumbers(artifact) {
|
|
221
|
+
const anchors = [];
|
|
222
|
+
const values = [];
|
|
223
|
+
for (const claim of [...artifact.support_claims, ...artifact.counter_claims]) {
|
|
224
|
+
for (const anchor of claim.number_anchors ?? []) {
|
|
225
|
+
if (typeof anchor?.value === 'number' && Number.isFinite(anchor.value))
|
|
226
|
+
anchors.push(anchor);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (const calculation of artifact.calculations ?? []) {
|
|
230
|
+
if (typeof calculation?.value === 'number' && Number.isFinite(calculation.value))
|
|
231
|
+
values.push(calculation.value);
|
|
232
|
+
}
|
|
233
|
+
return { anchors, values };
|
|
234
|
+
}
|
|
235
|
+
function unmatchedNumbers(text, anchors, calculations) {
|
|
236
|
+
const misses = [];
|
|
237
|
+
const seen = new Set();
|
|
238
|
+
for (const token of numberTokens(text)) {
|
|
239
|
+
if (exemptToken(token, text))
|
|
240
|
+
continue;
|
|
241
|
+
if (anchors.some((anchor) => matchesToken(token, anchor.value, anchor.precision)))
|
|
242
|
+
continue;
|
|
243
|
+
if (calculations.some((value) => matchesToken(token, value, undefined)))
|
|
244
|
+
continue;
|
|
245
|
+
// The same unanchored value repeated in one field is one problem, not six.
|
|
246
|
+
if (seen.has(token.text))
|
|
247
|
+
continue;
|
|
248
|
+
seen.add(token.text);
|
|
249
|
+
misses.push(token.text);
|
|
250
|
+
}
|
|
251
|
+
return misses;
|
|
252
|
+
}
|
|
253
|
+
function claimIssues(claim, path, tier1, tier2) {
|
|
254
|
+
if (typeof claim?.statement === 'string' && claim.statement.length > STATEMENT_MAX_CHARS) {
|
|
255
|
+
tier1.push({ code: 'analysis_result_too_large', severity: 'error', field: `${path}.statement`, detail: `单条 statement 超过 ${STATEMENT_MAX_CHARS} 字符` });
|
|
256
|
+
}
|
|
257
|
+
if (typeof claim?.confidence_basis !== 'string' || claim.confidence_basis.trim() === '') {
|
|
258
|
+
tier2.push({ code: 'confidence_basis_missing', severity: 'warning', field: `${path}.confidence_basis`, detail: 'confidence 必须带一句依据' });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Artifact validation in the three tiers of the design (Tier 1 rejects, Tier 2 downgrades to
|
|
263
|
+
* `partial`, Tier 3 is advisory). Returns issues; persistence is the caller's decision.
|
|
264
|
+
*/
|
|
265
|
+
export function validateArtifact(artifact, snapshot) {
|
|
266
|
+
const tier1 = [];
|
|
267
|
+
const tier2 = [];
|
|
268
|
+
const tier3 = [];
|
|
269
|
+
if (typeof artifact.headline === 'string' && artifact.headline.length > HEADLINE_MAX_CHARS) {
|
|
270
|
+
tier1.push({ code: 'analysis_result_too_large', severity: 'error', field: 'headline', detail: `headline 超过 ${HEADLINE_MAX_CHARS} 字符` });
|
|
271
|
+
}
|
|
272
|
+
if (typeof artifact.thesis === 'string' && artifact.thesis.length > THESIS_MAX_CHARS) {
|
|
273
|
+
tier1.push({ code: 'analysis_result_too_large', severity: 'error', field: 'thesis', detail: `thesis 超过 ${THESIS_MAX_CHARS} 字符` });
|
|
274
|
+
}
|
|
275
|
+
const claims = [...(artifact.support_claims ?? []), ...(artifact.counter_claims ?? [])];
|
|
276
|
+
if (claims.length > MAX_CLAIMS * 2) {
|
|
277
|
+
tier1.push({ code: 'analysis_result_too_large', severity: 'error', field: 'support_claims', detail: `正反论据合计 ${claims.length} 条,超过 ${MAX_CLAIMS * 2} 条上限` });
|
|
278
|
+
}
|
|
279
|
+
// §10.6 budgets live here, not in the tool schema: the host's JSON-Schema subset has no `maxItems`,
|
|
280
|
+
// so a schema keyword would cost the whole family row at boot.
|
|
281
|
+
for (const [field, list, limit] of [
|
|
282
|
+
['support_claims', artifact.support_claims, MAX_CLAIMS],
|
|
283
|
+
['counter_claims', artifact.counter_claims, MAX_CLAIMS],
|
|
284
|
+
['scenarios', artifact.scenarios, MAX_SCENARIOS],
|
|
285
|
+
]) {
|
|
286
|
+
if (Array.isArray(list) && list.length > limit) {
|
|
287
|
+
tier1.push({ code: 'analysis_result_too_large', severity: 'error', field, detail: `${field} ${list.length} 条,超过 ${limit} 条上限` });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
claims.forEach((claim, index) => claimIssues(claim, `claims[${index}]`, tier1, tier2));
|
|
291
|
+
// Hard rule: a conclusion with no invalidation condition is not a judgement, it is a slogan.
|
|
292
|
+
if (!Array.isArray(artifact.invalidation_conditions) || artifact.invalidation_conditions.length === 0) {
|
|
293
|
+
tier1.push({ code: 'invalidation_missing', severity: 'error', field: 'invalidation_conditions', detail: '至少要一条能推翻主判断的条件' });
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
const ids = [...claims.map((claim) => claim.claim_id), ...(artifact.calculations ?? []).map((item) => item.calculation_id)]
|
|
297
|
+
.filter((id) => typeof id === 'string' && id !== '');
|
|
298
|
+
const references = artifact.invalidation_conditions.some((condition) => ids.some((id) => condition.includes(id)));
|
|
299
|
+
if (!references) {
|
|
300
|
+
tier2.push({ code: 'invalidation_unreferenced', severity: 'warning', field: 'invalidation_conditions', detail: '失效条件没有引用任何 claim_id / calculation_id,无法核对它推翻的是哪一条' });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Evidence level and status must agree; `completed` also requires a clean validation.
|
|
304
|
+
if (artifact.evidence_level === 'insufficient' && artifact.status === 'completed') {
|
|
305
|
+
tier1.push({ code: 'evidence_level_conflict', severity: 'error', field: 'status', detail: 'evidence_level=insufficient 时 status 只能是 partial / blocked' });
|
|
306
|
+
}
|
|
307
|
+
if (artifact.status === 'completed' && !Array.isArray(artifact.limitations)) {
|
|
308
|
+
tier1.push({ code: 'limitations_missing', severity: 'error', field: 'limitations', detail: 'completed 的产物必须有 limitations 字段(可以为空数组,但不能缺)' });
|
|
309
|
+
}
|
|
310
|
+
if (Array.isArray(artifact.limitations) && artifact.limitations.length === 0) {
|
|
311
|
+
tier2.push({ code: 'limitations_empty', severity: 'warning', field: 'limitations', detail: 'limitations 为空:至少写明一条口径或数据限制' });
|
|
312
|
+
}
|
|
313
|
+
// Refs must exist inside this snapshot.
|
|
314
|
+
const datasetIds = new Set(snapshot.dataset_refs.map((item) => item.dataset_id));
|
|
315
|
+
const profileIds = new Set(snapshot.profile_refs.map((item) => item.profile_id));
|
|
316
|
+
const evidenceIds = new Set(snapshot.evidence.map((item) => item.source_id));
|
|
317
|
+
const calcIds = new Set((artifact.calculations ?? []).map((item) => item.calculation_id));
|
|
318
|
+
for (const claim of claims) {
|
|
319
|
+
for (const ref of claim.evidence_refs ?? []) {
|
|
320
|
+
if (!evidenceIds.has(ref)) {
|
|
321
|
+
tier1.push({ code: 'evidence_ref_missing', severity: 'error', field: claim.claim_id, detail: `引用的证据 ${ref} 不在本次快照里` });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const anchor of claim.number_anchors ?? []) {
|
|
325
|
+
const ref = anchor?.source?.ref;
|
|
326
|
+
if (typeof ref !== 'string')
|
|
327
|
+
continue;
|
|
328
|
+
const known = anchor.source.kind === 'dataset' ? datasetIds.has(ref)
|
|
329
|
+
: anchor.source.kind === 'profile' ? profileIds.has(ref)
|
|
330
|
+
: anchor.source.kind === 'evidence' ? evidenceIds.has(ref)
|
|
331
|
+
: calcIds.has(ref);
|
|
332
|
+
if (!known) {
|
|
333
|
+
tier1.push({ code: 'anchor_ref_missing', severity: 'error', field: claim.claim_id, detail: `数字锚点引用的 ${ref} 不在本次快照/计算里` });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// Number traceability on the conclusion fields only (Tier 1) and on calculations (Tier 2).
|
|
338
|
+
const { anchors, values } = anchoredNumbers(artifact);
|
|
339
|
+
const conclusionTexts = [
|
|
340
|
+
{ field: 'headline', text: artifact.headline ?? '' },
|
|
341
|
+
{ field: 'thesis', text: artifact.thesis ?? '' },
|
|
342
|
+
...claims.map((claim, index) => ({ field: `claims[${index}].statement`, text: claim.statement ?? '' })),
|
|
343
|
+
...(artifact.invalidation_conditions ?? []).map((condition, index) => ({ field: `invalidation_conditions[${index}]`, text: condition })),
|
|
344
|
+
];
|
|
345
|
+
for (const { field, text } of conclusionTexts) {
|
|
346
|
+
const misses = unmatchedNumbers(text, anchors, values);
|
|
347
|
+
if (misses.length > 0) {
|
|
348
|
+
tier1.push({ code: 'number_without_anchor', severity: 'error', field, detail: `这些数字没有来源锚点:${misses.slice(0, 6).join('、')}` });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (const [index, calculation] of (artifact.calculations ?? []).entries()) {
|
|
352
|
+
const known = anchors.some((anchor) => Math.abs(anchor.value - calculation.value) <= tolerance(anchor.precision));
|
|
353
|
+
if (!known) {
|
|
354
|
+
tier2.push({ code: 'calculation_without_anchor', severity: 'warning', field: `calculations[${index}]`, detail: `计算结果 ${calculation.metric}=${calculation.value} 没有对应锚点` });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Peer exchanges: an unanswered peer request means the result is not final, and the round-trip
|
|
358
|
+
// budget is a hard rule (§5.6-2). The send edge prevents the fourth request; this rejects a record
|
|
359
|
+
// that claims more than the budget (fabricated or from an unguarded client).
|
|
360
|
+
const exchanges = artifact.peer_exchanges ?? [];
|
|
361
|
+
const unanswered = exchanges.filter((item) => item?.answered !== true);
|
|
362
|
+
if (unanswered.length > 0) {
|
|
363
|
+
tier2.push({ code: 'peer_unanswered', severity: 'warning', field: 'peer_exchanges', detail: `${unanswered.length} 条 peer 请求没有回执;产物最多 partial` });
|
|
364
|
+
}
|
|
365
|
+
if (exchanges.length > MAX_PEER_EXCHANGES) {
|
|
366
|
+
tier1.push({ code: 'peer_budget_exhausted', severity: 'error', field: 'peer_exchanges', detail: `peer 往返 ${exchanges.length} 条,超过 ${MAX_PEER_EXCHANGES} 次预算;超出部分应回 analysis_blocked + peer_budget_exhausted 交 lead 裁决` });
|
|
367
|
+
}
|
|
368
|
+
if (artifact.status === 'completed' && unanswered.length > 0) {
|
|
369
|
+
tier1.push({ code: 'peer_unanswered_completed', severity: 'error', field: 'status', detail: '存在未回执的 peer 请求时不能写 completed' });
|
|
370
|
+
}
|
|
371
|
+
for (const [index, scenario] of (artifact.scenarios ?? []).entries()) {
|
|
372
|
+
const assumptions = scenario?.assumptions;
|
|
373
|
+
if (!Array.isArray(assumptions) || assumptions.length === 0) {
|
|
374
|
+
tier2.push({ code: 'scenario_assumptions_missing', severity: 'warning', field: `scenarios[${index}]`, detail: '情景必须写明假设' });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if ((artifact.alternative_explanations ?? []).length === 0) {
|
|
378
|
+
tier3.push({ code: 'no_alternative_explanation', severity: 'notice', field: 'alternative_explanations', detail: '没有替代解释:审阅者会问"还可能是别的什么"' });
|
|
379
|
+
}
|
|
380
|
+
return { tier1, tier2, tier3 };
|
|
381
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tools/analysis` row: the senior analyst's analysis family (snapshot / module run / submit).
|
|
3
|
+
*
|
|
4
|
+
* A family row, not a host row — the role preset mounts it and `src/tool-exec.ts` authorizes the
|
|
5
|
+
* caller by preset identity. The store is built per mount (same rule as the dataset-read row).
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
export declare const name = "capital-analysis-tools";
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
export declare function apply(ctx: Context): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerAnalysisTools } from './analysis/tools.js';
|
|
2
|
+
import { capitalDatasetStore } from './runtime.js';
|
|
3
|
+
export const name = 'capital-analysis-tools';
|
|
4
|
+
export const inject = ['tools'];
|
|
5
|
+
export function apply(ctx) {
|
|
6
|
+
registerAnalysisTools({ ctx, store: capitalDatasetStore(ctx) });
|
|
7
|
+
}
|
|
@@ -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.
|
|
@@ -379,7 +379,9 @@ export class WorkspaceDatasetStore {
|
|
|
379
379
|
profile_id: profileId,
|
|
380
380
|
dataset_id: ref.dataset_id,
|
|
381
381
|
task_id: input.task_id ?? null,
|
|
382
|
-
|
|
382
|
+
// Scope id, not the producing session: siblings under one root must read the same profile
|
|
383
|
+
// (senior read_profile / snapshot staging), and `readProfile` compares against the scope.
|
|
384
|
+
session_id: sessionScopeFor(session),
|
|
383
385
|
artifact_ref: canonicalProfileRef(profileId),
|
|
384
386
|
created_at: createdAt,
|
|
385
387
|
retention_until: Math.min(ref.retention_until, createdAt + this.retentionMs),
|
|
@@ -393,6 +395,50 @@ export class WorkspaceDatasetStore {
|
|
|
393
395
|
}
|
|
394
396
|
return profileRef;
|
|
395
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Host-internal profile read (analysis staging and `read_profile`). Same scope and expiry rules as
|
|
400
|
+
* Datasets: a profile belongs to the parent session scope and an expired one must not be analyzed.
|
|
401
|
+
* There is no model-facing read path for the raw profile object.
|
|
402
|
+
*/
|
|
403
|
+
async readProfile(input) {
|
|
404
|
+
if (!PROFILE_ID_PATTERN.test(input.profile_id))
|
|
405
|
+
throw new DatasetStoreError('profile_invalid', 'profile_id is invalid');
|
|
406
|
+
const root = this.readRoot(input.session);
|
|
407
|
+
if (!root || !this.fs)
|
|
408
|
+
throw new DatasetStoreError('filesystem_unavailable', 'workspace filesystem is unavailable');
|
|
409
|
+
let text;
|
|
410
|
+
try {
|
|
411
|
+
const target = await this.resolveContained(`${PROFILES_SUBDIR}/${input.profile_id}/${PROFILE_FILE}`, root, input.signal);
|
|
412
|
+
text = await this.fs.readText(target, input.signal);
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
if (errorCodeOf(error) === 'FS_NOT_FOUND')
|
|
416
|
+
throw new DatasetStoreError('profile_not_found', `profile ${input.profile_id} was not found`);
|
|
417
|
+
if (error instanceof DatasetStoreError)
|
|
418
|
+
throw error;
|
|
419
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json could not be read');
|
|
420
|
+
}
|
|
421
|
+
let parsed;
|
|
422
|
+
try {
|
|
423
|
+
parsed = JSON.parse(text);
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json is not valid JSON');
|
|
427
|
+
}
|
|
428
|
+
if (!isRecord(parsed) || !isRecord(parsed.ref))
|
|
429
|
+
throw new DatasetStoreError('profile_invalid', 'profile.json is missing its ref');
|
|
430
|
+
const ref = parsed.ref;
|
|
431
|
+
if (typeof ref.profile_id !== 'string' || ref.profile_id !== input.profile_id) {
|
|
432
|
+
throw new DatasetStoreError('profile_invalid', 'profile ref does not match its directory');
|
|
433
|
+
}
|
|
434
|
+
if (ref.session_id !== sessionScopeFor(input.session)) {
|
|
435
|
+
throw new DatasetStoreError('dataset_session_mismatch', 'profile belongs to another session scope');
|
|
436
|
+
}
|
|
437
|
+
if (typeof ref.retention_until === 'number' && ref.retention_until <= this.now()) {
|
|
438
|
+
throw new DatasetStoreError('profile_expired', `profile ${input.profile_id} has expired`);
|
|
439
|
+
}
|
|
440
|
+
return { ref, profile: validateProfile(parsed.profile) };
|
|
441
|
+
}
|
|
396
442
|
/**
|
|
397
443
|
* Host-internal presentation read (charts). The returned rows must never enter any agent message,
|
|
398
444
|
* 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>;
|