@v587d/capital-generation 2.31.8 → 2.32.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 +68 -0
- package/README.md +11 -7
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/analysis/artifact.d.ts +35 -0
- package/lib/analysis/artifact.js +250 -0
- package/lib/analysis/registry.d.ts +16 -2
- package/lib/analysis/registry.js +133 -23
- package/lib/analysis/runtime.d.ts +46 -19
- package/lib/analysis/runtime.js +485 -116
- package/lib/analysis/schemas.d.ts +46 -0
- package/lib/analysis/schemas.js +260 -7
- package/lib/analysis/snapshot.d.ts +10 -3
- package/lib/analysis/snapshot.js +298 -46
- package/lib/analysis/storage.d.ts +29 -1
- package/lib/analysis/storage.js +39 -6
- package/lib/analysis/tools.js +270 -29
- package/lib/analysis/types.d.ts +257 -3
- package/lib/analysis/types.js +31 -1
- package/lib/analysis/validation.d.ts +37 -1
- package/lib/analysis/validation.js +315 -1
- package/lib/chart/tool.js +1 -0
- package/lib/data-collector/store.d.ts +7 -1
- package/lib/data-collector/store.js +14 -0
- package/lib/python-runtime/child-env.d.ts +4 -2
- package/lib/python-runtime/child-env.js +21 -14
- package/lib/python-runtime/manager.d.ts +8 -0
- package/lib/python-runtime/manager.js +30 -14
- package/lib/sources/ftshare-rest.js +1 -1
- package/lib/sources/tencent-http.js +210 -53
- 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 +2 -1
- package/plugin-page/README.en.md +1 -1
- package/plugin-page/README.zh.md +1 -1
- package/preset/capital-generation/agent.patch.yml +1 -1
- package/preset/capital-generation/skills/capital-analysis-evidence/SKILL.md +15 -2
- package/preset/capital-generation/skills/capital-analysis-synthesis/SKILL.md +54 -9
- package/preset/capital-generation/skills/capital-analysis-validation/SKILL.md +41 -7
- package/preset/capital-generation/skills/capital-equity-research/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-event-impact/SKILL.md +20 -1
- package/preset/capital-generation/skills/capital-orchestration/SKILL.md +1 -1
- package/preset/capital-generation/skills/capital-senior-analysis/SKILL.md +38 -8
- package/python/analysis/lib/__init__.py +9 -0
- package/python/analysis/lib/errors.py +12 -0
- package/python/analysis/lib/eventstudy.py +164 -0
- package/python/analysis/lib/frames.py +95 -0
- package/python/analysis/lib/gaps.py +54 -0
- package/python/analysis/lib/jsonio.py +61 -0
- package/python/analysis/lib/metrics.py +147 -0
- package/python/analysis/lib/pit.py +84 -0
- package/python/analysis/lib/prices.py +140 -0
- package/python/analysis/lib/timeaxis.py +142 -0
- package/python/analysis/lib/version.py +3 -0
- package/python/analysis/modules/comps_valuation/module.py +26 -59
- package/python/analysis/modules/earnings_bridge/module.py +20 -77
- package/python/analysis/modules/event_study/LICENSE +21 -0
- package/python/analysis/modules/event_study/module.json +217 -0
- package/python/analysis/modules/event_study/module.py +979 -0
- package/python/analysis/modules/financial_quality/module.py +25 -88
- package/python/analysis/modules/hello/module.py +4 -0
- package/python/analysis/modules/kline_quality/module.py +26 -132
- package/python/analysis/modules/portfolio_stress/module.py +27 -112
- package/python/analysis/modules/returns_risk/module.json +108 -25
- package/python/analysis/modules/returns_risk/module.py +68 -227
- package/python/analysis/modules/scenario_sensitivity/module.py +11 -44
- package/python/analysis/modules/simple_backtest/module.json +244 -36
- package/python/analysis/modules/simple_backtest/module.py +1146 -459
- package/python/analysis/modules/statement_integrity/module.py +35 -87
- package/python/analysis/modules/technical_indicators/module.py +33 -152
- package/python/analysis/modules/valuation_sensitivity/module.py +30 -61
- package/python/worker.py +5 -0
- package/watchlist/package.json +1 -1
|
@@ -16,6 +16,8 @@ export declare const THESIS_MAX_CHARS = 1200;
|
|
|
16
16
|
export declare const STATEMENT_MAX_CHARS = 600;
|
|
17
17
|
export declare const MAX_CLAIMS = 20;
|
|
18
18
|
export declare const MAX_SCENARIOS = 8;
|
|
19
|
+
/** Data-gap prefixes (plan §5.10): an unregistered prefix means the module invented a vocabulary. */
|
|
20
|
+
export declare const GAP_PREFIXES: readonly ["source_unavailable", "field_missing", "period_conflict", "time_unavailable", "adjustment_unknown", "calendar_mismatch", "sample_insufficient", "assumption_missing"];
|
|
19
21
|
/** §5.6-2 peer round-trip budget per task_id. The send edge stops the fourth request; this is the record check. */
|
|
20
22
|
export declare const MAX_PEER_EXCHANGES = 3;
|
|
21
23
|
/** Bounded evidence intake: single item bytes and total count. */
|
|
@@ -33,9 +35,24 @@ export declare const MODULE_DEFAULT_LIMITS: {
|
|
|
33
35
|
export declare const EVIDENCE_SCHEMA: Record<string, unknown>;
|
|
34
36
|
export declare const NUMBER_ANCHOR_SCHEMA: Record<string, unknown>;
|
|
35
37
|
export declare const CLAIM_SCHEMA: Record<string, unknown>;
|
|
38
|
+
/** Persisted Calculation, V1 shape. Kept for reading old artifacts; not a model input any more. */
|
|
36
39
|
export declare const CALCULATION_SCHEMA: Record<string, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Calculation V2 as the model submits it: a run ref plus a metric key. The host fills the value from
|
|
42
|
+
* that run's `result.json` — a number the model types itself is not replayable and is not accepted.
|
|
43
|
+
*/
|
|
44
|
+
export declare const CALCULATION_V2_SCHEMA: Record<string, unknown>;
|
|
45
|
+
/** Host gate shape for a module's `simulation` block (plan §5.7 G5). Model text never fills this. */
|
|
46
|
+
export declare const SIMULATION_FACTS_SCHEMA: Record<string, unknown>;
|
|
47
|
+
/** Host gate shape for a module's `event_study` block (plan §M6-4/§M6-5). Model text never fills this. */
|
|
48
|
+
export declare const EVENT_STUDY_FACTS_SCHEMA: Record<string, unknown>;
|
|
37
49
|
export declare const PEER_EXCHANGE_SCHEMA: Record<string, unknown>;
|
|
38
50
|
export declare const SCENARIO_SCHEMA: Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* `submit_analysis` receipt (plan §5.8). The credential is what the senior analyst relays in
|
|
53
|
+
* `analysis_result`; the host guarantees the fields, not that the final answer repeats them.
|
|
54
|
+
*/
|
|
55
|
+
export declare const ARTIFACT_CREDENTIAL_SCHEMA: Record<string, unknown>;
|
|
39
56
|
/** `submit_analysis` parameters: the final artifact, minus the host-written `validation`. */
|
|
40
57
|
export declare const ANALYSIS_ARTIFACT_SCHEMA: Record<string, unknown>;
|
|
41
58
|
export declare const MODULE_MANIFEST_SCHEMA: Record<string, unknown>;
|
|
@@ -56,3 +73,32 @@ export declare const DESCRIBE_MODULE_PARAMETERS: Record<string, unknown>;
|
|
|
56
73
|
export declare const RUN_ANALYSIS_PARAMETERS: Record<string, unknown>;
|
|
57
74
|
export declare const RUN_ANALYSIS_OUTPUT: Record<string, unknown>;
|
|
58
75
|
export declare const SUBMIT_ANALYSIS_OUTPUT: Record<string, unknown>;
|
|
76
|
+
/**
|
|
77
|
+
* Snapshot V2 budgets. The hard cap must stay well below `MAX_RAW_READ_BYTES` in
|
|
78
|
+
* `src/data-collector/store.ts` (16 MiB): `readWorkspaceJson` rejects anything larger, so a
|
|
79
|
+
* snapshot above it can be created and then never loaded.
|
|
80
|
+
*/
|
|
81
|
+
export declare const SNAPSHOT_METADATA_TARGET_BYTES = 1048576;
|
|
82
|
+
export declare const SNAPSHOT_METADATA_HARD_BYTES = 4194304;
|
|
83
|
+
export declare const SNAPSHOT_INPUT_TOTAL_BYTES: number;
|
|
84
|
+
export declare const SNAPSHOT_INPUT_FILE_BYTES: number;
|
|
85
|
+
export declare const SNAPSHOT_INPUT_MAX_COUNT = 16;
|
|
86
|
+
/** Queue wait cap for one analysis run (global slots = 2, one run per snapshot). */
|
|
87
|
+
export declare const ANALYSIS_QUEUE_WAIT_MS = 120000;
|
|
88
|
+
export declare const SNAPSHOT_LIMITS: {
|
|
89
|
+
readonly metadata_target_bytes: 1048576;
|
|
90
|
+
readonly metadata_hard_bytes: 4194304;
|
|
91
|
+
readonly input_total_bytes: number;
|
|
92
|
+
readonly input_file_bytes: number;
|
|
93
|
+
readonly input_max_count: 16;
|
|
94
|
+
};
|
|
95
|
+
export type SnapshotLimits = {
|
|
96
|
+
-readonly [K in keyof typeof SNAPSHOT_LIMITS]: number;
|
|
97
|
+
};
|
|
98
|
+
export declare const SNAPSHOT_INPUT_V2_SCHEMA: Record<string, unknown>;
|
|
99
|
+
/** `snapshot.json` V2. `additionalProperties:false` is what keeps rows and absolute paths out. */
|
|
100
|
+
export declare const SNAPSHOT_FILE_V2_SCHEMA: Record<string, unknown>;
|
|
101
|
+
export declare const MODULE_RUN_V2_SCHEMA: Record<string, unknown>;
|
|
102
|
+
export declare const ARTIFACT_CHANGE_SCHEMA: Record<string, unknown>;
|
|
103
|
+
/** Persisted artifact V2 (`artifacts/rev-<n>.json`). The host writes every field except the conclusions. */
|
|
104
|
+
export declare const ARTIFACT_V2_SCHEMA: Record<string, unknown>;
|
package/lib/analysis/schemas.js
CHANGED
|
@@ -21,6 +21,11 @@ export const THESIS_MAX_CHARS = 1_200;
|
|
|
21
21
|
export const STATEMENT_MAX_CHARS = 600;
|
|
22
22
|
export const MAX_CLAIMS = 20;
|
|
23
23
|
export const MAX_SCENARIOS = 8;
|
|
24
|
+
/** Data-gap prefixes (plan §5.10): an unregistered prefix means the module invented a vocabulary. */
|
|
25
|
+
export const GAP_PREFIXES = [
|
|
26
|
+
'source_unavailable', 'field_missing', 'period_conflict', 'time_unavailable',
|
|
27
|
+
'adjustment_unknown', 'calendar_mismatch', 'sample_insufficient', 'assumption_missing',
|
|
28
|
+
];
|
|
24
29
|
/** §5.6-2 peer round-trip budget per task_id. The send edge stops the fourth request; this is the record check. */
|
|
25
30
|
export const MAX_PEER_EXCHANGES = 3;
|
|
26
31
|
/** Bounded evidence intake: single item bytes and total count. */
|
|
@@ -57,15 +62,17 @@ export const NUMBER_ANCHOR_SCHEMA = jsonObject({
|
|
|
57
62
|
}, ['value', 'unit', 'source']);
|
|
58
63
|
export const CLAIM_SCHEMA = jsonObject({
|
|
59
64
|
claim_id: { type: 'string' },
|
|
60
|
-
type: { type: 'string', enum: ['fact', '
|
|
65
|
+
type: { type: 'string', enum: ['fact', 'inference', 'assumption', 'scenario'] },
|
|
61
66
|
statement: { type: 'string' },
|
|
62
67
|
evidence_refs: strings(),
|
|
63
68
|
number_anchors: { type: 'array', items: NUMBER_ANCHOR_SCHEMA },
|
|
64
69
|
confidence: { type: 'string', enum: ['low', 'medium', 'high'] },
|
|
70
|
+
causal_strength: { type: 'string', enum: ['descriptive', 'associational', 'causal_with_assumptions', 'not_supported'] },
|
|
65
71
|
confidence_basis: { type: 'string' },
|
|
66
72
|
falsifier: { type: 'string' },
|
|
67
73
|
limitations: strings(),
|
|
68
74
|
}, ['claim_id', 'type', 'statement', 'confidence']);
|
|
75
|
+
/** Persisted Calculation, V1 shape. Kept for reading old artifacts; not a model input any more. */
|
|
69
76
|
export const CALCULATION_SCHEMA = jsonObject({
|
|
70
77
|
calculation_id: { type: 'string' },
|
|
71
78
|
module_id: { type: 'string' },
|
|
@@ -73,8 +80,72 @@ export const CALCULATION_SCHEMA = jsonObject({
|
|
|
73
80
|
metric: { type: 'string' },
|
|
74
81
|
value: { type: 'number' },
|
|
75
82
|
unit: { type: 'string' },
|
|
83
|
+
period: { type: 'string' },
|
|
84
|
+
display: { type: 'string' },
|
|
85
|
+
assumption_source: { type: 'string', enum: ['user', 'dataset', 'evidence', 'model_assumption', 'default'] },
|
|
76
86
|
params_digest: { type: 'string' },
|
|
87
|
+
analysis_run_ref: { type: 'string' },
|
|
88
|
+
metric_key: { type: 'string' },
|
|
89
|
+
methodology_version: { type: 'string' },
|
|
90
|
+
input_refs: strings(),
|
|
77
91
|
}, ['calculation_id', 'module_id', 'module_version', 'metric', 'value', 'unit']);
|
|
92
|
+
/**
|
|
93
|
+
* Calculation V2 as the model submits it: a run ref plus a metric key. The host fills the value from
|
|
94
|
+
* that run's `result.json` — a number the model types itself is not replayable and is not accepted.
|
|
95
|
+
*/
|
|
96
|
+
export const CALCULATION_V2_SCHEMA = jsonObject({
|
|
97
|
+
calculation_id: { type: 'string' },
|
|
98
|
+
analysis_run_ref: { type: 'string' },
|
|
99
|
+
metric_key: { type: 'string' },
|
|
100
|
+
unit: { type: 'string' },
|
|
101
|
+
period: { type: 'string' },
|
|
102
|
+
display: { type: 'string' },
|
|
103
|
+
assumption_source: { type: 'string', enum: ['user', 'dataset', 'evidence', 'model_assumption', 'default'] },
|
|
104
|
+
}, ['calculation_id', 'analysis_run_ref', 'metric_key', 'unit']);
|
|
105
|
+
/** Host gate shape for a module's `simulation` block (plan §5.7 G5). Model text never fills this. */
|
|
106
|
+
export const SIMULATION_FACTS_SCHEMA = jsonObject({
|
|
107
|
+
grade: { type: 'string', enum: ['signal_replay', 'constrained_simulation', 'insufficient_data'] },
|
|
108
|
+
cost_basis: { type: 'string', enum: ['net', 'gross'] },
|
|
109
|
+
out_of_sample: { type: 'boolean' },
|
|
110
|
+
restated_history: { type: 'boolean' },
|
|
111
|
+
constraints: { type: 'object' },
|
|
112
|
+
fee_rules: { type: 'array', items: { type: 'object' } },
|
|
113
|
+
/** Host-added when the facts land in the artifact; modules do not author it. */
|
|
114
|
+
analysis_run_ref: { type: 'string' },
|
|
115
|
+
audit: jsonObject({
|
|
116
|
+
status: { type: 'string', enum: ['PASS', 'WARN', 'FAIL'] },
|
|
117
|
+
reasons: strings(),
|
|
118
|
+
evidence: strings(),
|
|
119
|
+
uncovered_risks: strings(),
|
|
120
|
+
}, ['status', 'reasons', 'uncovered_risks']),
|
|
121
|
+
}, ['grade', 'audit']);
|
|
122
|
+
/** Host gate shape for a module's `event_study` block (plan §M6-4/§M6-5). Model text never fills this. */
|
|
123
|
+
export const EVENT_STUDY_FACTS_SCHEMA = jsonObject({
|
|
124
|
+
method: { type: 'string', enum: ['market_adjusted', 'market_model'] },
|
|
125
|
+
methodology_version: { type: 'string' },
|
|
126
|
+
sample_size: { type: 'integer' },
|
|
127
|
+
requested_events: { type: 'integer' },
|
|
128
|
+
excluded_events: { type: 'integer' },
|
|
129
|
+
window: jsonObject({ before: { type: 'integer' }, after: { type: 'integer' } }, ['before', 'after']),
|
|
130
|
+
estimation_window: { type: 'integer' },
|
|
131
|
+
estimation_observations: { type: 'integer' },
|
|
132
|
+
benchmark: { type: 'object' },
|
|
133
|
+
calendar: { type: 'object' },
|
|
134
|
+
causal_strength: { type: 'string', enum: ['descriptive', 'associational'] },
|
|
135
|
+
point_in_time: { type: 'string', enum: ['as_known_then', 'ex_post'] },
|
|
136
|
+
clustering: { type: 'object' },
|
|
137
|
+
multiple_testing: { type: 'object' },
|
|
138
|
+
/** Host-added when the facts land in the artifact; modules do not author it. */
|
|
139
|
+
analysis_run_ref: { type: 'string' },
|
|
140
|
+
audit: jsonObject({
|
|
141
|
+
status: { type: 'string', enum: ['PASS', 'WARN', 'FAIL'] },
|
|
142
|
+
reasons: strings(),
|
|
143
|
+
evidence: strings(),
|
|
144
|
+
uncovered_risks: strings(),
|
|
145
|
+
}, ['status', 'reasons', 'uncovered_risks']),
|
|
146
|
+
}, ['method', 'methodology_version', 'sample_size', 'requested_events', 'excluded_events', 'window',
|
|
147
|
+
'estimation_window', 'estimation_observations', 'benchmark', 'calendar', 'causal_strength',
|
|
148
|
+
'point_in_time', 'clustering', 'multiple_testing', 'audit']);
|
|
78
149
|
export const PEER_EXCHANGE_SCHEMA = jsonObject({
|
|
79
150
|
peer: { type: 'string' },
|
|
80
151
|
type: { type: 'string' },
|
|
@@ -87,6 +158,27 @@ export const SCENARIO_SCHEMA = jsonObject({
|
|
|
87
158
|
outcome: { type: 'string' },
|
|
88
159
|
triggers: strings(),
|
|
89
160
|
}, ['name', 'assumptions']);
|
|
161
|
+
/**
|
|
162
|
+
* `submit_analysis` receipt (plan §5.8). The credential is what the senior analyst relays in
|
|
163
|
+
* `analysis_result`; the host guarantees the fields, not that the final answer repeats them.
|
|
164
|
+
*/
|
|
165
|
+
export const ARTIFACT_CREDENTIAL_SCHEMA = jsonObject({
|
|
166
|
+
artifact_ref: { type: 'string' },
|
|
167
|
+
artifact_hash: { type: 'string' },
|
|
168
|
+
revision: { type: 'integer' },
|
|
169
|
+
status: { type: 'string', enum: ['completed', 'partial', 'blocked'] },
|
|
170
|
+
validation_status: { type: 'string', enum: ['pass', 'warning'] },
|
|
171
|
+
methods: strings(),
|
|
172
|
+
data_cutoff: nullable({ type: 'string' }),
|
|
173
|
+
temporal_mode: { type: 'string', enum: ['as_known_then', 'ex_post'] },
|
|
174
|
+
gaps: { type: 'integer' },
|
|
175
|
+
limitations: { type: 'integer' },
|
|
176
|
+
simulation_grade: nullable({ type: 'string' }),
|
|
177
|
+
event_sample_size: nullable({ type: 'integer' }),
|
|
178
|
+
}, [
|
|
179
|
+
'artifact_ref', 'artifact_hash', 'revision', 'status', 'validation_status', 'methods', 'data_cutoff',
|
|
180
|
+
'temporal_mode', 'gaps', 'limitations', 'simulation_grade', 'event_sample_size',
|
|
181
|
+
]);
|
|
90
182
|
/** `submit_analysis` parameters: the final artifact, minus the host-written `validation`. */
|
|
91
183
|
export const ANALYSIS_ARTIFACT_SCHEMA = jsonObject({
|
|
92
184
|
analysis_id: { type: 'string' },
|
|
@@ -100,16 +192,24 @@ export const ANALYSIS_ARTIFACT_SCHEMA = jsonObject({
|
|
|
100
192
|
counter_claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
101
193
|
alternative_explanations: strings(),
|
|
102
194
|
contradictions: strings(),
|
|
103
|
-
calculations: { type: 'array', items:
|
|
195
|
+
calculations: { type: 'array', items: CALCULATION_V2_SCHEMA },
|
|
104
196
|
scenarios: { type: 'array', items: SCENARIO_SCHEMA },
|
|
105
197
|
invalidation_conditions: strings(),
|
|
106
198
|
unresolved_gaps: strings(),
|
|
107
199
|
limitations: strings(),
|
|
108
200
|
methods_used: {
|
|
109
201
|
type: 'array',
|
|
110
|
-
items: jsonObject({
|
|
202
|
+
items: jsonObject({
|
|
203
|
+
module_id: { type: 'string' },
|
|
204
|
+
module_version: { type: 'string' },
|
|
205
|
+
module_run_ids: strings(),
|
|
206
|
+
}, ['module_id', 'module_version']),
|
|
111
207
|
},
|
|
112
208
|
peer_exchanges: { type: 'array', items: PEER_EXCHANGE_SCHEMA },
|
|
209
|
+
/** Names the run whose result carries `simulation`; values are copied from it by the host. */
|
|
210
|
+
simulation_run_ref: { type: 'string' },
|
|
211
|
+
/** Names the run whose result carries `event_study`; values are copied from it by the host. */
|
|
212
|
+
event_study_run_ref: { type: 'string' },
|
|
113
213
|
}, [
|
|
114
214
|
'analysis_id', 'task_id', 'snapshot_id', 'status', 'evidence_level', 'headline', 'thesis',
|
|
115
215
|
'support_claims', 'counter_claims', 'alternative_explanations', 'contradictions', 'calculations',
|
|
@@ -134,6 +234,12 @@ export const MODULE_MANIFEST_SCHEMA = jsonObject({
|
|
|
134
234
|
max_output_bytes: { type: 'integer' },
|
|
135
235
|
max_log_bytes: { type: 'integer' },
|
|
136
236
|
}, ['timeout_ms', 'max_input_rows', 'max_output_bytes', 'max_log_bytes']),
|
|
237
|
+
temporal_aware: { type: 'boolean' },
|
|
238
|
+
display_name: { type: 'string' },
|
|
239
|
+
reuse: jsonObject({
|
|
240
|
+
allow_partial: { type: 'boolean' },
|
|
241
|
+
allow_blocked: { type: 'boolean' },
|
|
242
|
+
}),
|
|
137
243
|
provenance: jsonObject({
|
|
138
244
|
source_type: { type: 'string', enum: ['original', 'adapted'] },
|
|
139
245
|
repository: { type: 'string' },
|
|
@@ -142,7 +248,7 @@ export const MODULE_MANIFEST_SCHEMA = jsonObject({
|
|
|
142
248
|
}, ['source_type', 'license']),
|
|
143
249
|
}, ['id', 'version', 'entrypoint', 'runtime', 'description', 'roles', 'capabilities', 'limits', 'provenance']);
|
|
144
250
|
export const MODULE_REQUEST_SCHEMA = jsonObject({
|
|
145
|
-
protocol: { type: 'string', enum: ['capital.analysis/
|
|
251
|
+
protocol: { type: 'string', enum: ['capital.analysis/v2'] },
|
|
146
252
|
task_id: { type: 'string' },
|
|
147
253
|
analysis_id: { type: 'string' },
|
|
148
254
|
module_run_id: { type: 'string' },
|
|
@@ -153,6 +259,11 @@ export const MODULE_REQUEST_SCHEMA = jsonObject({
|
|
|
153
259
|
profiles: { type: 'array', items: jsonObject({ profile_id: { type: 'string' } }, ['profile_id']) },
|
|
154
260
|
evidence: { type: 'array', items: EVIDENCE_SCHEMA },
|
|
155
261
|
}, ['datasets', 'profiles', 'evidence']),
|
|
262
|
+
temporal: jsonObject({
|
|
263
|
+
mode: { type: 'string', enum: ['as_known_then', 'ex_post'] },
|
|
264
|
+
as_of: { type: 'string' },
|
|
265
|
+
data_cutoff: { type: 'string' },
|
|
266
|
+
}, ['mode', 'as_of']),
|
|
156
267
|
params: { type: 'object' },
|
|
157
268
|
}, ['protocol', 'task_id', 'analysis_id', 'module_run_id', 'snapshot_id', 'as_of', 'inputs', 'params']);
|
|
158
269
|
/** Worker result. `outputs` carry refs only; large payloads live under `modules/<id>/outputs/`. */
|
|
@@ -167,6 +278,8 @@ export const MODULE_RESULT_SCHEMA = jsonObject({
|
|
|
167
278
|
limitations: strings(),
|
|
168
279
|
data_gaps: strings(),
|
|
169
280
|
outputs: { type: 'array', items: jsonObject({ name: { type: 'string' }, ref: { type: 'string' } }, ['name', 'ref']) },
|
|
281
|
+
simulation: SIMULATION_FACTS_SCHEMA,
|
|
282
|
+
event_study: EVENT_STUDY_FACTS_SCHEMA,
|
|
170
283
|
}, [
|
|
171
284
|
'status', 'summary', 'metrics', 'claims', 'assumptions', 'methodology_log', 'sensitivity',
|
|
172
285
|
'limitations', 'data_gaps', 'outputs',
|
|
@@ -196,6 +309,7 @@ export const CREATE_SNAPSHOT_PARAMETERS = jsonObject({
|
|
|
196
309
|
evidence: { type: 'array', items: EVIDENCE_SCHEMA },
|
|
197
310
|
prior_analysis_refs: strings(),
|
|
198
311
|
constraints: { type: 'object' },
|
|
312
|
+
temporal_mode: { type: 'string', enum: ['as_known_then', 'ex_post'] },
|
|
199
313
|
}, ['task_id', 'question', 'purpose', 'depth', 'as_of']);
|
|
200
314
|
export const CREATE_SNAPSHOT_OUTPUT = jsonObject({
|
|
201
315
|
analysis_snapshot_ref: { type: 'string' },
|
|
@@ -238,6 +352,7 @@ export const DESCRIBE_MODULE_OUTPUT = jsonObject({
|
|
|
238
352
|
required_fields: strings(),
|
|
239
353
|
assumptions: strings(),
|
|
240
354
|
capabilities: strings(),
|
|
355
|
+
temporal_aware: { type: 'boolean' },
|
|
241
356
|
limits: { type: 'object' },
|
|
242
357
|
}, ['module_id', 'version', 'input_schema', 'output_schema', 'required_fields', 'assumptions', 'capabilities', 'limits']);
|
|
243
358
|
export const LIST_MODULES_PARAMETERS = jsonObject({});
|
|
@@ -251,20 +366,29 @@ export const RUN_ANALYSIS_OUTPUT = jsonObject({
|
|
|
251
366
|
analysis_run_ref: { type: 'string' },
|
|
252
367
|
module_id: { type: 'string' },
|
|
253
368
|
module_version: { type: 'string' },
|
|
369
|
+
module_code_hash: { type: 'string' },
|
|
254
370
|
status: { type: 'string', enum: ['completed', 'partial', 'blocked', 'failed'] },
|
|
255
371
|
summary: { type: 'string' },
|
|
256
372
|
metrics: { type: 'object' },
|
|
257
373
|
assumptions: strings(),
|
|
374
|
+
methodology: strings(),
|
|
258
375
|
limitations: strings(),
|
|
259
376
|
data_gaps: strings(),
|
|
377
|
+
/** Opaque refs to large outputs; the payload itself never crosses the tool boundary. */
|
|
378
|
+
output_refs: strings(),
|
|
379
|
+
/** Simulation credential for backtest modules; absent for other modules. */
|
|
380
|
+
simulation: { type: 'object' },
|
|
381
|
+
/** Event-study facts for `event_study`; absent for other modules. */
|
|
382
|
+
event_study: { type: 'object' },
|
|
383
|
+
sensitivity: { type: 'object' },
|
|
260
384
|
validation: jsonObject({
|
|
261
385
|
status: { type: 'string', enum: ['pass', 'warning'] },
|
|
262
386
|
issues: { type: 'array', items: { type: 'object' } },
|
|
263
387
|
}, ['status', 'issues']),
|
|
264
388
|
reused: { type: 'boolean' },
|
|
265
389
|
}, [
|
|
266
|
-
'analysis_run_ref', 'module_id', 'module_version', '
|
|
267
|
-
'limitations', 'data_gaps', 'validation', 'reused',
|
|
390
|
+
'analysis_run_ref', 'module_id', 'module_version', 'module_code_hash', 'status', 'summary', 'metrics',
|
|
391
|
+
'assumptions', 'methodology', 'limitations', 'data_gaps', 'output_refs', 'validation', 'reused',
|
|
268
392
|
]);
|
|
269
393
|
export const SUBMIT_ANALYSIS_OUTPUT = jsonObject({
|
|
270
394
|
analysis_ref: { type: 'string' },
|
|
@@ -273,4 +397,133 @@ export const SUBMIT_ANALYSIS_OUTPUT = jsonObject({
|
|
|
273
397
|
status: { type: 'string', enum: ['pass', 'warning'] },
|
|
274
398
|
issues: { type: 'array', items: { type: 'object' } },
|
|
275
399
|
}, ['status', 'issues']),
|
|
276
|
-
|
|
400
|
+
credential: ARTIFACT_CREDENTIAL_SCHEMA,
|
|
401
|
+
}, ['analysis_ref', 'status', 'validation', 'credential']);
|
|
402
|
+
/**
|
|
403
|
+
* Snapshot V2 budgets. The hard cap must stay well below `MAX_RAW_READ_BYTES` in
|
|
404
|
+
* `src/data-collector/store.ts` (16 MiB): `readWorkspaceJson` rejects anything larger, so a
|
|
405
|
+
* snapshot above it can be created and then never loaded.
|
|
406
|
+
*/
|
|
407
|
+
export const SNAPSHOT_METADATA_TARGET_BYTES = 1_048_576;
|
|
408
|
+
export const SNAPSHOT_METADATA_HARD_BYTES = 4_194_304;
|
|
409
|
+
export const SNAPSHOT_INPUT_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
410
|
+
export const SNAPSHOT_INPUT_FILE_BYTES = 16 * 1024 * 1024;
|
|
411
|
+
export const SNAPSHOT_INPUT_MAX_COUNT = 16;
|
|
412
|
+
/** Queue wait cap for one analysis run (global slots = 2, one run per snapshot). */
|
|
413
|
+
export const ANALYSIS_QUEUE_WAIT_MS = 120_000;
|
|
414
|
+
export const SNAPSHOT_LIMITS = {
|
|
415
|
+
metadata_target_bytes: SNAPSHOT_METADATA_TARGET_BYTES,
|
|
416
|
+
metadata_hard_bytes: SNAPSHOT_METADATA_HARD_BYTES,
|
|
417
|
+
input_total_bytes: SNAPSHOT_INPUT_TOTAL_BYTES,
|
|
418
|
+
input_file_bytes: SNAPSHOT_INPUT_FILE_BYTES,
|
|
419
|
+
input_max_count: SNAPSHOT_INPUT_MAX_COUNT,
|
|
420
|
+
};
|
|
421
|
+
const schemaVersion = (version) => ({ type: 'integer', enum: [version] });
|
|
422
|
+
export const SNAPSHOT_INPUT_V2_SCHEMA = jsonObject({
|
|
423
|
+
input_id: { type: 'string' },
|
|
424
|
+
kind: { type: 'string', enum: ['dataset', 'profile', 'evidence'] },
|
|
425
|
+
source_ref: { type: 'string' },
|
|
426
|
+
path: { type: 'string' },
|
|
427
|
+
sha256: { type: 'string' },
|
|
428
|
+
byte_size: { type: 'integer' },
|
|
429
|
+
row_count: { type: 'integer' },
|
|
430
|
+
column_count: { type: 'integer' },
|
|
431
|
+
schema_digest: { type: 'string' },
|
|
432
|
+
time_axis: jsonObject({ column: { type: 'string' }, unit: { type: 'string' }, tz: { type: 'string' } }, ['column', 'unit', 'tz']),
|
|
433
|
+
temporal_basis: { type: 'string', enum: ['exchange_time', 'disclosure', 'report_period', 'unknown'] },
|
|
434
|
+
available_at: { type: 'string' },
|
|
435
|
+
published_at: { type: 'string' },
|
|
436
|
+
effective_at: { type: 'string' },
|
|
437
|
+
retention_until: { type: 'integer' },
|
|
438
|
+
}, ['input_id', 'kind', 'source_ref', 'path', 'sha256', 'byte_size', 'schema_digest', 'temporal_basis']);
|
|
439
|
+
/** `snapshot.json` V2. `additionalProperties:false` is what keeps rows and absolute paths out. */
|
|
440
|
+
export const SNAPSHOT_FILE_V2_SCHEMA = jsonObject({
|
|
441
|
+
schema_version: schemaVersion(2),
|
|
442
|
+
analysis_id: { type: 'string' },
|
|
443
|
+
task_id: { type: 'string' },
|
|
444
|
+
question: { type: 'string' },
|
|
445
|
+
instrument: { type: 'string' },
|
|
446
|
+
purpose: { type: 'string', enum: ['observe', 'research', 'holding_review'] },
|
|
447
|
+
horizon: { type: 'string' },
|
|
448
|
+
depth: { type: 'string', enum: ['quick', 'standard', 'deep'] },
|
|
449
|
+
as_of: { type: 'string' },
|
|
450
|
+
data_cutoff: { type: 'string' },
|
|
451
|
+
temporal_mode: { type: 'string', enum: ['as_known_then', 'ex_post'] },
|
|
452
|
+
inputs: { type: 'array', items: SNAPSHOT_INPUT_V2_SCHEMA },
|
|
453
|
+
dataset_refs: { type: 'array', items: { type: 'object' } },
|
|
454
|
+
profile_refs: { type: 'array', items: { type: 'object' } },
|
|
455
|
+
evidence: { type: 'array', items: { type: 'object' } },
|
|
456
|
+
prior_analysis_refs: strings(),
|
|
457
|
+
constraints: { type: 'object' },
|
|
458
|
+
limitations: strings(),
|
|
459
|
+
input_fingerprint: { type: 'string' },
|
|
460
|
+
created_at: { type: 'integer' },
|
|
461
|
+
expires_at: { type: 'integer' },
|
|
462
|
+
}, [
|
|
463
|
+
'schema_version', 'analysis_id', 'task_id', 'question', 'purpose', 'depth', 'as_of',
|
|
464
|
+
'temporal_mode', 'inputs', 'dataset_refs', 'profile_refs', 'evidence', 'prior_analysis_refs',
|
|
465
|
+
'constraints', 'limitations', 'input_fingerprint', 'created_at', 'expires_at',
|
|
466
|
+
]);
|
|
467
|
+
export const MODULE_RUN_V2_SCHEMA = jsonObject({
|
|
468
|
+
module_run_id: { type: 'string' },
|
|
469
|
+
analysis_id: { type: 'string' },
|
|
470
|
+
snapshot_id: { type: 'string' },
|
|
471
|
+
module_id: { type: 'string' },
|
|
472
|
+
module_version: { type: 'string' },
|
|
473
|
+
module_code_hash: { type: 'string' },
|
|
474
|
+
worker_protocol_version: schemaVersion(2),
|
|
475
|
+
runtime: { type: 'object' },
|
|
476
|
+
params_digest: { type: 'string' },
|
|
477
|
+
run_fingerprint: { type: 'string' },
|
|
478
|
+
status: { type: 'string', enum: ['queued', 'running', 'completed', 'partial', 'blocked', 'failed', 'cancelled', 'timed_out'] },
|
|
479
|
+
queued_at: { type: 'integer' },
|
|
480
|
+
started_at: { type: 'integer' },
|
|
481
|
+
finished_at: { type: 'integer' },
|
|
482
|
+
queue_ms: { type: 'integer' },
|
|
483
|
+
exec_ms: { type: 'integer' },
|
|
484
|
+
error: { type: 'object' },
|
|
485
|
+
result_ref: { type: 'string' },
|
|
486
|
+
output_refs: strings(),
|
|
487
|
+
reused_from: { type: 'string' },
|
|
488
|
+
}, ['module_run_id', 'analysis_id', 'snapshot_id', 'module_id', 'module_version', 'module_code_hash',
|
|
489
|
+
'worker_protocol_version', 'runtime', 'params_digest', 'run_fingerprint', 'status']);
|
|
490
|
+
export const ARTIFACT_CHANGE_SCHEMA = jsonObject({
|
|
491
|
+
category: { type: 'string', enum: ['data_update', 'method_change', 'assumption_change', 'conclusion_change'] },
|
|
492
|
+
detail: { type: 'string' },
|
|
493
|
+
}, ['category', 'detail']);
|
|
494
|
+
/** Persisted artifact V2 (`artifacts/rev-<n>.json`). The host writes every field except the conclusions. */
|
|
495
|
+
export const ARTIFACT_V2_SCHEMA = jsonObject({
|
|
496
|
+
schema_version: schemaVersion(2),
|
|
497
|
+
artifact_id: { type: 'string' },
|
|
498
|
+
task_id: { type: 'string' },
|
|
499
|
+
snapshot_id: { type: 'string' },
|
|
500
|
+
revision: { type: 'integer' },
|
|
501
|
+
supersedes: { type: 'string' },
|
|
502
|
+
artifact_hash: { type: 'string' },
|
|
503
|
+
status: { type: 'string', enum: ['completed', 'partial', 'blocked'] },
|
|
504
|
+
evidence_level: { type: 'string', enum: ['sufficient', 'limited', 'insufficient'] },
|
|
505
|
+
headline: { type: 'string' },
|
|
506
|
+
thesis: { type: 'string' },
|
|
507
|
+
support_claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
508
|
+
counter_claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
509
|
+
alternative_explanations: strings(),
|
|
510
|
+
contradictions: strings(),
|
|
511
|
+
calculations: { type: 'array', items: CALCULATION_SCHEMA },
|
|
512
|
+
scenarios: { type: 'array', items: { type: 'object' } },
|
|
513
|
+
invalidation_conditions: strings(),
|
|
514
|
+
unresolved_gaps: strings(),
|
|
515
|
+
limitations: strings(),
|
|
516
|
+
methods_used: { type: 'array', items: jsonObject({ module_id: { type: 'string' }, module_version: { type: 'string' }, module_run_ids: strings() }, ['module_id', 'module_version']) },
|
|
517
|
+
peer_exchanges: { type: 'array', items: PEER_EXCHANGE_SCHEMA },
|
|
518
|
+
changes: { type: 'array', items: ARTIFACT_CHANGE_SCHEMA },
|
|
519
|
+
simulation: { type: 'object' },
|
|
520
|
+
event_study: EVENT_STUDY_FACTS_SCHEMA,
|
|
521
|
+
validation: jsonObject({
|
|
522
|
+
status: { type: 'string', enum: ['pass', 'warning'] },
|
|
523
|
+
issues: { type: 'array', items: { type: 'object' } },
|
|
524
|
+
}, ['status', 'issues']),
|
|
525
|
+
created_at: { type: 'integer' },
|
|
526
|
+
}, ['schema_version', 'artifact_id', 'task_id', 'snapshot_id', 'revision', 'artifact_hash', 'status',
|
|
527
|
+
'evidence_level', 'headline', 'thesis', 'support_claims', 'counter_claims', 'alternative_explanations',
|
|
528
|
+
'contradictions', 'calculations', 'scenarios', 'invalidation_conditions', 'unresolved_gaps', 'limitations',
|
|
529
|
+
'methods_used', 'peer_exchanges', 'changes', 'validation', 'created_at']);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DatasetRef, type ProfilePayload, type ProfileRef, type SessionLike } from '../data-collector/store.js';
|
|
2
|
+
import { type SnapshotLimits } from './schemas.js';
|
|
2
3
|
import { type AnalysisFileWriter } from './storage.js';
|
|
3
|
-
import { type AnalysisSnapshot, type DatasetRefLike, type EvidenceItem, type ProfileRefLike } from './types.js';
|
|
4
|
+
import { SNAPSHOT_SCHEMA_VERSION, type AnalysisSnapshot, type DatasetRefLike, type EvidenceItem, type LoadedSnapshot, type ProfileRefLike, type SnapshotInputV2, type TemporalMode } from './types.js';
|
|
4
5
|
/** Narrow seam over the Dataset store: staging only needs these two host-internal reads. */
|
|
5
6
|
export interface AnalysisInputReader {
|
|
6
7
|
readPresentationRows(input: {
|
|
@@ -31,6 +32,7 @@ export interface CreateSnapshotInput {
|
|
|
31
32
|
readonly depth: AnalysisSnapshot['depth'];
|
|
32
33
|
readonly as_of: string;
|
|
33
34
|
readonly data_cutoff?: string;
|
|
35
|
+
readonly temporal_mode?: TemporalMode;
|
|
34
36
|
readonly dataset_refs: readonly DatasetRefLike[];
|
|
35
37
|
readonly profile_refs: readonly ProfileRefLike[];
|
|
36
38
|
readonly evidence: readonly EvidenceItem[];
|
|
@@ -38,6 +40,9 @@ export interface CreateSnapshotInput {
|
|
|
38
40
|
readonly constraints: Readonly<Record<string, unknown>>;
|
|
39
41
|
}
|
|
40
42
|
export interface SnapshotRecord extends AnalysisSnapshot {
|
|
43
|
+
readonly schema_version?: typeof SNAPSHOT_SCHEMA_VERSION;
|
|
44
|
+
readonly temporal_mode: TemporalMode;
|
|
45
|
+
readonly inputs: readonly SnapshotInputV2[];
|
|
41
46
|
/** Host-only absolute paths handed to the worker; never returned to the model. */
|
|
42
47
|
readonly paths: {
|
|
43
48
|
readonly dir: string;
|
|
@@ -86,17 +91,19 @@ export declare function createSnapshot(options: {
|
|
|
86
91
|
input: CreateSnapshotInput;
|
|
87
92
|
signal?: AbortSignal;
|
|
88
93
|
now?: number;
|
|
94
|
+
/** Test seam only: shrink the V2 budgets so size gates do not need multi-megabyte fixtures. */
|
|
95
|
+
limits?: Partial<SnapshotLimits>;
|
|
89
96
|
}): Promise<{
|
|
90
97
|
record: SnapshotRecord;
|
|
91
98
|
ref: string;
|
|
92
99
|
}>;
|
|
93
|
-
/** Load a snapshot by ref and fail loudly when it is missing or expired. */
|
|
100
|
+
/** Load a snapshot by ref and fail loudly when it is missing, corrupt or expired. */
|
|
94
101
|
export declare function loadSnapshot(options: {
|
|
95
102
|
reader: AnalysisFileWriter;
|
|
96
103
|
session: SessionLike;
|
|
97
104
|
analysisId: string;
|
|
98
105
|
signal?: AbortSignal;
|
|
99
106
|
now?: number;
|
|
100
|
-
}): Promise<
|
|
107
|
+
}): Promise<LoadedSnapshot>;
|
|
101
108
|
/** Coverage summary returned to the model: counts and ranges only, never rows. */
|
|
102
109
|
export declare function snapshotCoverage(record: SnapshotRecord): Record<string, unknown>;
|