@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
package/lib/analysis/types.d.ts
CHANGED
|
@@ -5,11 +5,70 @@
|
|
|
5
5
|
* Protocol versions are literals, not configuration: a module built for v1 must not be run under a
|
|
6
6
|
* v2 request shape, and the mismatch has to fail loudly rather than be coerced.
|
|
7
7
|
*/
|
|
8
|
-
export declare const ANALYSIS_PROTOCOL = "capital.analysis/
|
|
8
|
+
export declare const ANALYSIS_PROTOCOL = "capital.analysis/v2";
|
|
9
9
|
export declare const AGENT_MESSAGE_PROTOCOL = "capital.agent.message/v1";
|
|
10
10
|
/** Stable error codes (`docs/dev/senior-analysis.md` §1.9). Adding one is a protocol change. */
|
|
11
|
-
export declare const ANALYSIS_ERROR_CODES: readonly ["analysis_snapshot_invalid", "analysis_snapshot_expired", "analysis_ref_unauthorized", "analysis_module_not_found", "analysis_module_not_applicable", "analysis_input_invalid", "analysis_runtime_not_ready", "analysis_timeout", "analysis_cancelled", "analysis_output_invalid", "analysis_result_too_large", "analysis_validation_failed", "analysis_peer_budget_exhausted", "analysis_not_implemented"];
|
|
11
|
+
export declare const ANALYSIS_ERROR_CODES: readonly ["analysis_snapshot_invalid", "analysis_snapshot_expired", "analysis_ref_unauthorized", "analysis_module_not_found", "analysis_module_not_applicable", "analysis_input_invalid", "analysis_runtime_not_ready", "analysis_timeout", "analysis_cancelled", "analysis_output_invalid", "analysis_result_too_large", "analysis_validation_failed", "analysis_peer_budget_exhausted", "analysis_not_implemented", "analysis_snapshot_too_large", "analysis_snapshot_corrupt", "analysis_snapshot_legacy", "analysis_input_hash_mismatch", "analysis_point_in_time_conflict", "analysis_event_time_missing", "analysis_adjustment_unknown", "analysis_calendar_mismatch", "analysis_run_not_found", "analysis_run_binding_mismatch", "analysis_method_version_mismatch", "analysis_metric_binding_invalid", "analysis_metric_undefined", "analysis_artifact_revision_conflict", "analysis_simulation_insufficient_data", "analysis_simulation_overclaim", "analysis_event_insufficient_data", "analysis_event_overclaim", "analysis_queue_timeout"];
|
|
12
12
|
export type AnalysisErrorCode = (typeof ANALYSIS_ERROR_CODES)[number];
|
|
13
|
+
/** On-disk contract versions. Missing `schema_version` means V1 (legacy read-only). */
|
|
14
|
+
export declare const SNAPSHOT_SCHEMA_VERSION = 2;
|
|
15
|
+
export declare const ARTIFACT_SCHEMA_VERSION = 2;
|
|
16
|
+
/** Worker protocol version recorded in the run fingerprint (V1 workers stay runnable). */
|
|
17
|
+
export declare const WORKER_PROTOCOL_VERSION = 2;
|
|
18
|
+
export type TemporalMode = 'as_known_then' | 'ex_post';
|
|
19
|
+
export type TemporalBasis = 'exchange_time' | 'disclosure' | 'report_period' | 'unknown';
|
|
20
|
+
export type SnapshotInputKind = 'dataset' | 'profile' | 'evidence';
|
|
21
|
+
export type RunStatus = 'queued' | 'running' | AnalysisStatus | 'cancelled' | 'timed_out';
|
|
22
|
+
export type CausalStrength = 'descriptive' | 'associational' | 'causal_with_assumptions' | 'not_supported';
|
|
23
|
+
export type SimulationGrade = 'signal_replay' | 'constrained_simulation' | 'insufficient_data';
|
|
24
|
+
export type SimulationAuditStatus = 'PASS' | 'WARN' | 'FAIL';
|
|
25
|
+
/**
|
|
26
|
+
* The simulation credential a module returns with a backtest result (plan §5.7/Q-01). The host copies
|
|
27
|
+
* the cited run's block into the artifact; a grade or audit status typed by the model is not accepted.
|
|
28
|
+
*/
|
|
29
|
+
export interface SimulationAudit {
|
|
30
|
+
readonly status: SimulationAuditStatus;
|
|
31
|
+
readonly reasons: readonly string[];
|
|
32
|
+
readonly evidence?: readonly string[];
|
|
33
|
+
readonly uncovered_risks: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
export interface SimulationFacts {
|
|
36
|
+
readonly grade: SimulationGrade;
|
|
37
|
+
readonly cost_basis?: 'net' | 'gross';
|
|
38
|
+
readonly out_of_sample?: boolean;
|
|
39
|
+
readonly restated_history?: boolean;
|
|
40
|
+
readonly constraints?: Readonly<Record<string, unknown>>;
|
|
41
|
+
readonly fee_rules?: readonly unknown[];
|
|
42
|
+
readonly audit: SimulationAudit;
|
|
43
|
+
readonly [extra: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** Event-study facts (`event_study`): the module owns sample size, window, method version and causal bound. */
|
|
46
|
+
export interface EventStudyAudit {
|
|
47
|
+
readonly status: SimulationAuditStatus;
|
|
48
|
+
readonly reasons: readonly string[];
|
|
49
|
+
readonly evidence?: readonly string[];
|
|
50
|
+
readonly uncovered_risks: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
export interface EventStudyFacts {
|
|
53
|
+
readonly method: string;
|
|
54
|
+
readonly methodology_version: string;
|
|
55
|
+
readonly sample_size: number;
|
|
56
|
+
readonly requested_events: number;
|
|
57
|
+
readonly excluded_events: number;
|
|
58
|
+
readonly window: Readonly<Record<string, unknown>>;
|
|
59
|
+
readonly estimation_window: number;
|
|
60
|
+
readonly estimation_observations: number;
|
|
61
|
+
readonly benchmark: Readonly<Record<string, unknown>>;
|
|
62
|
+
readonly calendar: Readonly<Record<string, unknown>>;
|
|
63
|
+
readonly causal_strength: Extract<CausalStrength, 'descriptive' | 'associational'>;
|
|
64
|
+
readonly point_in_time: TemporalMode;
|
|
65
|
+
readonly clustering: Readonly<Record<string, unknown>>;
|
|
66
|
+
readonly multiple_testing: Readonly<Record<string, unknown>>;
|
|
67
|
+
readonly audit: EventStudyAudit;
|
|
68
|
+
/** Host-added when the facts land in the artifact; modules do not author it. */
|
|
69
|
+
readonly analysis_run_ref?: string;
|
|
70
|
+
readonly [extra: string]: unknown;
|
|
71
|
+
}
|
|
13
72
|
/** One tool failure. The code travels in the message so a model can act on it without a parser. */
|
|
14
73
|
export declare class AnalysisError extends Error {
|
|
15
74
|
readonly code: AnalysisErrorCode;
|
|
@@ -21,7 +80,9 @@ export type EvidenceLevel = 'sufficient' | 'limited' | 'insufficient';
|
|
|
21
80
|
export type ValidationStatus = 'pass' | 'warning';
|
|
22
81
|
export type EvidenceKind = 'filing' | 'news' | 'research' | 'user_material';
|
|
23
82
|
export type EvidenceVerification = 'verified_official' | 'unverified' | 'not_verified';
|
|
24
|
-
|
|
83
|
+
/** Claim V2 vocabulary. V1 files used `observation` / `hypothesis`; read them through the display map. */
|
|
84
|
+
export type ClaimType = 'fact' | 'inference' | 'assumption' | 'scenario';
|
|
85
|
+
export type LegacyClaimType = 'observation' | 'hypothesis';
|
|
25
86
|
export type Confidence = 'low' | 'medium' | 'high';
|
|
26
87
|
export type AnchorSourceKind = 'dataset' | 'profile' | 'evidence' | 'computation';
|
|
27
88
|
/** Bounded structured evidence item; the full document body stays with the retriever/OCR layer. */
|
|
@@ -77,6 +138,11 @@ export interface NumberAnchor {
|
|
|
77
138
|
};
|
|
78
139
|
readonly precision?: number;
|
|
79
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* `calculation_id` + `unit` (+ `period` / `display`) are the model's; every other field is derived by
|
|
143
|
+
* the host from the cited `ModuleRun`, so a conclusion number can always be replayed from
|
|
144
|
+
* `run.json` + `result.json`.
|
|
145
|
+
*/
|
|
80
146
|
export interface Calculation {
|
|
81
147
|
readonly calculation_id: string;
|
|
82
148
|
readonly module_id: string;
|
|
@@ -84,7 +150,15 @@ export interface Calculation {
|
|
|
84
150
|
readonly metric: string;
|
|
85
151
|
readonly value: number;
|
|
86
152
|
readonly unit: string;
|
|
153
|
+
readonly period?: string;
|
|
154
|
+
readonly display?: string;
|
|
155
|
+
readonly assumption_source?: CalculationV2['assumption_source'];
|
|
87
156
|
readonly params_digest?: string;
|
|
157
|
+
readonly analysis_run_ref?: string;
|
|
158
|
+
readonly metric_key?: string;
|
|
159
|
+
readonly methodology_version?: string;
|
|
160
|
+
/** Dataset / profile ids the cited run read, taken from the run's `request.json`. */
|
|
161
|
+
readonly input_refs?: readonly string[];
|
|
88
162
|
}
|
|
89
163
|
export interface Claim {
|
|
90
164
|
readonly claim_id: string;
|
|
@@ -93,10 +167,20 @@ export interface Claim {
|
|
|
93
167
|
readonly evidence_refs: readonly string[];
|
|
94
168
|
readonly number_anchors: readonly NumberAnchor[];
|
|
95
169
|
readonly confidence: Confidence;
|
|
170
|
+
/** How strong a causal reading the claim allows; absent means the type's default strength. */
|
|
171
|
+
readonly causal_strength?: CausalStrength;
|
|
96
172
|
readonly confidence_basis?: string;
|
|
97
173
|
readonly falsifier?: string;
|
|
98
174
|
readonly limitations?: readonly string[];
|
|
99
175
|
}
|
|
176
|
+
/** V1 → V2 display mapping (plan §5.7). Reading an old artifact must not fail on the old words. */
|
|
177
|
+
export declare const LEGACY_CLAIM_TYPES: Readonly<Record<LegacyClaimType, ClaimType>>;
|
|
178
|
+
/** Categories of a cross-revision change (plan §5.7 / M4-4). */
|
|
179
|
+
export type ArtifactChangeCategory = 'data_update' | 'method_change' | 'assumption_change' | 'conclusion_change';
|
|
180
|
+
export interface ArtifactChange {
|
|
181
|
+
readonly category: ArtifactChangeCategory;
|
|
182
|
+
readonly detail: string;
|
|
183
|
+
}
|
|
100
184
|
export interface PeerExchange {
|
|
101
185
|
readonly peer: string;
|
|
102
186
|
readonly type: string;
|
|
@@ -130,8 +214,17 @@ export interface AnalysisArtifact {
|
|
|
130
214
|
readonly methods_used: readonly {
|
|
131
215
|
readonly module_id: string;
|
|
132
216
|
readonly module_version: string;
|
|
217
|
+
readonly module_run_ids?: readonly string[];
|
|
133
218
|
}[];
|
|
134
219
|
readonly peer_exchanges: readonly PeerExchange[];
|
|
220
|
+
/** Model names the run whose result carries `simulation`; the host copies the facts from it. */
|
|
221
|
+
readonly simulation_run_ref?: string;
|
|
222
|
+
/** Host-attached simulation credential (`grade` + `audit` + constraints); never model-authored. */
|
|
223
|
+
readonly simulation?: SimulationFacts;
|
|
224
|
+
/** Model names the run whose result carries `event_study`; the host copies the facts from it. */
|
|
225
|
+
readonly event_study_run_ref?: string;
|
|
226
|
+
/** Host-attached event-study facts (sample size + window + causal bound); never model-authored. */
|
|
227
|
+
readonly event_study?: EventStudyFacts;
|
|
135
228
|
readonly validation?: {
|
|
136
229
|
readonly status: ValidationStatus;
|
|
137
230
|
readonly issues: readonly ValidationIssue[];
|
|
@@ -153,6 +246,15 @@ export interface ModuleManifest {
|
|
|
153
246
|
readonly assumptions: readonly string[];
|
|
154
247
|
readonly applicability: readonly string[];
|
|
155
248
|
readonly limits: ModuleLimits;
|
|
249
|
+
/** Only a PIT-aware module may run on an `as_known_then` snapshot. */
|
|
250
|
+
readonly temporal_aware: boolean;
|
|
251
|
+
/** Human-facing label for listing/description; never part of the id or the protocol. */
|
|
252
|
+
readonly display_name?: string;
|
|
253
|
+
/** Reuse is opt-in: `completed` is always reusable, `partial/blocked` only when declared here. */
|
|
254
|
+
readonly reuse: {
|
|
255
|
+
readonly allow_partial: boolean;
|
|
256
|
+
readonly allow_blocked: boolean;
|
|
257
|
+
};
|
|
156
258
|
readonly provenance: ModuleProvenance;
|
|
157
259
|
}
|
|
158
260
|
export interface ModuleLimits {
|
|
@@ -195,7 +297,159 @@ export interface ModuleResult {
|
|
|
195
297
|
readonly name: string;
|
|
196
298
|
readonly ref: string;
|
|
197
299
|
}[];
|
|
300
|
+
/** Simulation modules only (`simple_backtest`): grade, constraints and audit for the host gate. */
|
|
301
|
+
readonly simulation?: SimulationFacts;
|
|
302
|
+
/** Event-study modules (`event_study`): sample size, window, method and causal bound for the host gate. */
|
|
303
|
+
readonly event_study?: EventStudyFacts;
|
|
198
304
|
}
|
|
199
305
|
/** The six model-facing tools of the `tools/analysis` family, in registration order. */
|
|
200
306
|
export declare const ANALYSIS_TOOL_NAMES: readonly ["create_analysis_snapshot", "read_profile", "list_analysis_modules", "describe_analysis_module", "run_analysis", "submit_analysis"];
|
|
201
307
|
export type AnalysisToolName = (typeof ANALYSIS_TOOL_NAMES)[number];
|
|
308
|
+
/** One staged input in Snapshot V2. Metadata only: rows live in the `inputs/` copy. */
|
|
309
|
+
export interface SnapshotInputV2 {
|
|
310
|
+
readonly input_id: string;
|
|
311
|
+
readonly kind: SnapshotInputKind;
|
|
312
|
+
readonly source_ref: string;
|
|
313
|
+
/** Workspace-relative path of the staged copy; never an absolute host path. */
|
|
314
|
+
readonly path: string;
|
|
315
|
+
readonly sha256: string;
|
|
316
|
+
readonly byte_size: number;
|
|
317
|
+
readonly row_count?: number;
|
|
318
|
+
readonly column_count?: number;
|
|
319
|
+
readonly schema_digest: string;
|
|
320
|
+
readonly time_axis?: {
|
|
321
|
+
readonly column: string;
|
|
322
|
+
readonly unit: string;
|
|
323
|
+
readonly tz: string;
|
|
324
|
+
};
|
|
325
|
+
readonly temporal_basis: TemporalBasis;
|
|
326
|
+
readonly available_at?: string;
|
|
327
|
+
readonly published_at?: string;
|
|
328
|
+
readonly effective_at?: string;
|
|
329
|
+
readonly retention_until?: number;
|
|
330
|
+
}
|
|
331
|
+
/** `snapshot.json` V2. No rows, no absolute paths; written last as the commit marker. */
|
|
332
|
+
export interface SnapshotFileV2 {
|
|
333
|
+
readonly schema_version: typeof SNAPSHOT_SCHEMA_VERSION;
|
|
334
|
+
readonly analysis_id: string;
|
|
335
|
+
readonly task_id: string;
|
|
336
|
+
readonly question: string;
|
|
337
|
+
readonly instrument?: string;
|
|
338
|
+
readonly purpose: AnalysisSnapshot['purpose'];
|
|
339
|
+
readonly horizon?: string;
|
|
340
|
+
readonly depth: AnalysisSnapshot['depth'];
|
|
341
|
+
readonly as_of: string;
|
|
342
|
+
readonly data_cutoff?: string;
|
|
343
|
+
readonly temporal_mode: TemporalMode;
|
|
344
|
+
readonly inputs: readonly SnapshotInputV2[];
|
|
345
|
+
readonly dataset_refs: readonly DatasetRefLike[];
|
|
346
|
+
readonly profile_refs: readonly ProfileRefLike[];
|
|
347
|
+
readonly evidence: readonly EvidenceItem[];
|
|
348
|
+
readonly prior_analysis_refs: readonly string[];
|
|
349
|
+
readonly constraints: Readonly<Record<string, unknown>>;
|
|
350
|
+
readonly limitations: readonly string[];
|
|
351
|
+
readonly input_fingerprint: string;
|
|
352
|
+
readonly created_at: number;
|
|
353
|
+
readonly expires_at: number;
|
|
354
|
+
}
|
|
355
|
+
/** What `loadSnapshot` returns: either a verified V2 snapshot or a legacy V1 file. */
|
|
356
|
+
export interface LoadedSnapshot extends AnalysisSnapshot {
|
|
357
|
+
readonly schema_version?: 1 | typeof SNAPSHOT_SCHEMA_VERSION;
|
|
358
|
+
readonly temporal_mode: TemporalMode;
|
|
359
|
+
readonly inputs: readonly SnapshotInputV2[];
|
|
360
|
+
readonly paths: {
|
|
361
|
+
readonly dir: string;
|
|
362
|
+
readonly inputs_dir?: string;
|
|
363
|
+
};
|
|
364
|
+
/** V1 file or V2 read while the V2 contract is disabled; run/submit refuse it. */
|
|
365
|
+
readonly legacy: boolean;
|
|
366
|
+
}
|
|
367
|
+
/** Append-only `run.json` row for ModuleRun V2. */
|
|
368
|
+
export interface ModuleRunRecordV2 {
|
|
369
|
+
readonly module_run_id: string;
|
|
370
|
+
readonly analysis_id: string;
|
|
371
|
+
readonly snapshot_id: string;
|
|
372
|
+
readonly module_id: string;
|
|
373
|
+
readonly module_version: string;
|
|
374
|
+
readonly module_code_hash: string;
|
|
375
|
+
readonly worker_protocol_version: typeof WORKER_PROTOCOL_VERSION;
|
|
376
|
+
readonly runtime: Readonly<Record<string, string | null>>;
|
|
377
|
+
readonly params_digest: string;
|
|
378
|
+
readonly run_fingerprint: string;
|
|
379
|
+
readonly status: RunStatus;
|
|
380
|
+
readonly queued_at?: number;
|
|
381
|
+
readonly started_at?: number;
|
|
382
|
+
readonly finished_at?: number;
|
|
383
|
+
readonly queue_ms?: number;
|
|
384
|
+
readonly exec_ms?: number;
|
|
385
|
+
readonly error?: {
|
|
386
|
+
readonly code: string;
|
|
387
|
+
readonly message: string;
|
|
388
|
+
} | null;
|
|
389
|
+
readonly result_ref?: string;
|
|
390
|
+
readonly output_refs?: readonly string[];
|
|
391
|
+
readonly reused_from?: string | null;
|
|
392
|
+
}
|
|
393
|
+
/** Calculation V2: the model names a run + metric, the host fills the authoritative value. */
|
|
394
|
+
export interface CalculationV2 {
|
|
395
|
+
readonly calculation_id: string;
|
|
396
|
+
readonly analysis_run_ref: string;
|
|
397
|
+
readonly metric_key: string;
|
|
398
|
+
readonly unit: string;
|
|
399
|
+
readonly period?: string;
|
|
400
|
+
readonly display?: string;
|
|
401
|
+
readonly assumption_source?: 'user' | 'dataset' | 'evidence' | 'model_assumption' | 'default';
|
|
402
|
+
}
|
|
403
|
+
/** Artifact V2 on-disk contract: `artifacts/rev-<n>.json` is immutable, `artifact.json` is the latest. */
|
|
404
|
+
export interface ArtifactV2 {
|
|
405
|
+
readonly schema_version: typeof ARTIFACT_SCHEMA_VERSION;
|
|
406
|
+
readonly artifact_id: string;
|
|
407
|
+
readonly task_id: string;
|
|
408
|
+
readonly snapshot_id: string;
|
|
409
|
+
readonly revision: number;
|
|
410
|
+
readonly supersedes?: string;
|
|
411
|
+
readonly artifact_hash: string;
|
|
412
|
+
readonly status: ArtifactStatus;
|
|
413
|
+
readonly evidence_level: EvidenceLevel;
|
|
414
|
+
readonly headline: string;
|
|
415
|
+
readonly thesis: string;
|
|
416
|
+
readonly support_claims: readonly Claim[];
|
|
417
|
+
readonly counter_claims: readonly Claim[];
|
|
418
|
+
readonly alternative_explanations: readonly string[];
|
|
419
|
+
readonly contradictions: readonly string[];
|
|
420
|
+
readonly calculations: readonly Calculation[];
|
|
421
|
+
readonly scenarios: readonly unknown[];
|
|
422
|
+
readonly invalidation_conditions: readonly string[];
|
|
423
|
+
readonly unresolved_gaps: readonly string[];
|
|
424
|
+
readonly limitations: readonly string[];
|
|
425
|
+
readonly methods_used: readonly {
|
|
426
|
+
readonly module_id: string;
|
|
427
|
+
readonly module_version: string;
|
|
428
|
+
readonly module_run_ids?: readonly string[];
|
|
429
|
+
}[];
|
|
430
|
+
readonly peer_exchanges: readonly PeerExchange[];
|
|
431
|
+
/** Simulation credential, host-attached from the cited run's result. */
|
|
432
|
+
readonly simulation?: SimulationFacts;
|
|
433
|
+
/** Cross-revision diff; empty on the first revision (and for a V2 taken over from a V1 file). */
|
|
434
|
+
readonly changes: readonly ArtifactChange[];
|
|
435
|
+
/** Event-study facts, host-attached from the cited run's result. */
|
|
436
|
+
readonly event_study?: EventStudyFacts;
|
|
437
|
+
readonly validation: {
|
|
438
|
+
readonly status: ValidationStatus;
|
|
439
|
+
readonly issues: readonly ValidationIssue[];
|
|
440
|
+
};
|
|
441
|
+
readonly created_at: number;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* What `loadArtifact` returns. `artifact` keeps the submission-side shape (`analysis_id`) whatever
|
|
445
|
+
* version was on disk, with V1 claim types already mapped for display; `revision` is 0 for a V1 file
|
|
446
|
+
* so the V2 revision series starts at 1 instead of continuing someone else's numbering.
|
|
447
|
+
*/
|
|
448
|
+
export interface LoadedArtifact {
|
|
449
|
+
readonly analysis_id: string;
|
|
450
|
+
readonly revision: number;
|
|
451
|
+
readonly legacy: boolean;
|
|
452
|
+
readonly artifact: AnalysisArtifact;
|
|
453
|
+
/** Absent for V1 files (they never carried a hash). */
|
|
454
|
+
readonly artifact_hash?: string;
|
|
455
|
+
}
|
package/lib/analysis/types.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Protocol versions are literals, not configuration: a module built for v1 must not be run under a
|
|
6
6
|
* v2 request shape, and the mismatch has to fail loudly rather than be coerced.
|
|
7
7
|
*/
|
|
8
|
-
export const ANALYSIS_PROTOCOL = 'capital.analysis/
|
|
8
|
+
export const ANALYSIS_PROTOCOL = 'capital.analysis/v2';
|
|
9
9
|
export const AGENT_MESSAGE_PROTOCOL = 'capital.agent.message/v1';
|
|
10
10
|
/** Stable error codes (`docs/dev/senior-analysis.md` §1.9). Adding one is a protocol change. */
|
|
11
11
|
export const ANALYSIS_ERROR_CODES = [
|
|
@@ -23,7 +23,32 @@ export const ANALYSIS_ERROR_CODES = [
|
|
|
23
23
|
'analysis_validation_failed',
|
|
24
24
|
'analysis_peer_budget_exhausted',
|
|
25
25
|
'analysis_not_implemented',
|
|
26
|
+
// V2 contract (`docs/design/data-calculation-conclusion-engineering-plan.md`).
|
|
27
|
+
'analysis_snapshot_too_large',
|
|
28
|
+
'analysis_snapshot_corrupt',
|
|
29
|
+
'analysis_snapshot_legacy',
|
|
30
|
+
'analysis_input_hash_mismatch',
|
|
31
|
+
'analysis_point_in_time_conflict',
|
|
32
|
+
'analysis_event_time_missing',
|
|
33
|
+
'analysis_adjustment_unknown',
|
|
34
|
+
'analysis_calendar_mismatch',
|
|
35
|
+
'analysis_run_not_found',
|
|
36
|
+
'analysis_run_binding_mismatch',
|
|
37
|
+
'analysis_method_version_mismatch',
|
|
38
|
+
'analysis_metric_binding_invalid',
|
|
39
|
+
'analysis_metric_undefined',
|
|
40
|
+
'analysis_artifact_revision_conflict',
|
|
41
|
+
'analysis_simulation_insufficient_data',
|
|
42
|
+
'analysis_simulation_overclaim',
|
|
43
|
+
'analysis_event_insufficient_data',
|
|
44
|
+
'analysis_event_overclaim',
|
|
45
|
+
'analysis_queue_timeout',
|
|
26
46
|
];
|
|
47
|
+
/** On-disk contract versions. Missing `schema_version` means V1 (legacy read-only). */
|
|
48
|
+
export const SNAPSHOT_SCHEMA_VERSION = 2;
|
|
49
|
+
export const ARTIFACT_SCHEMA_VERSION = 2;
|
|
50
|
+
/** Worker protocol version recorded in the run fingerprint (V1 workers stay runnable). */
|
|
51
|
+
export const WORKER_PROTOCOL_VERSION = 2;
|
|
27
52
|
/** One tool failure. The code travels in the message so a model can act on it without a parser. */
|
|
28
53
|
export class AnalysisError extends Error {
|
|
29
54
|
code;
|
|
@@ -33,6 +58,11 @@ export class AnalysisError extends Error {
|
|
|
33
58
|
this.code = code;
|
|
34
59
|
}
|
|
35
60
|
}
|
|
61
|
+
/** V1 → V2 display mapping (plan §5.7). Reading an old artifact must not fail on the old words. */
|
|
62
|
+
export const LEGACY_CLAIM_TYPES = {
|
|
63
|
+
observation: 'inference',
|
|
64
|
+
hypothesis: 'assumption',
|
|
65
|
+
};
|
|
36
66
|
/** The six model-facing tools of the `tools/analysis` family, in registration order. */
|
|
37
67
|
export const ANALYSIS_TOOL_NAMES = [
|
|
38
68
|
'create_analysis_snapshot',
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Number traceability only covers numbers it can extract. It does NOT prove the prose is unembellished;
|
|
11
11
|
* do not describe it as such.
|
|
12
12
|
*/
|
|
13
|
-
import type { AnalysisArtifact, AnalysisSnapshot, ModuleManifest, ValidationIssue } from './types.js';
|
|
13
|
+
import type { AnalysisArtifact, AnalysisErrorCode, AnalysisSnapshot, Calculation, CalculationV2, ModuleManifest, ModuleResult, ModuleRunRecordV2, ValidationIssue } from './types.js';
|
|
14
14
|
type Json = Record<string, unknown>;
|
|
15
15
|
/** Subset of JSON Schema used by the protocol: types, properties, required, items, enum, bounds. */
|
|
16
16
|
export declare function validateAgainstSchema(value: unknown, schema: Json | undefined, path?: string): string[];
|
|
@@ -41,4 +41,40 @@ export declare function numberTokens(text: string): NumberToken[];
|
|
|
41
41
|
* `partial`, Tier 3 is advisory). Returns issues; persistence is the caller's decision.
|
|
42
42
|
*/
|
|
43
43
|
export declare function validateArtifact(artifact: AnalysisArtifact, snapshot: AnalysisSnapshot): ArtifactValidation;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate V2: the model names a `ModuleRun` plus a `metric_key`; the host reads the authoritative
|
|
46
|
+
* value from that run's `result.json`. A number the model types itself cannot be replayed, so it is
|
|
47
|
+
* not accepted — this is the replacement for "calculation values are whatever the prose says".
|
|
48
|
+
*/
|
|
49
|
+
export interface RunRequestFacts {
|
|
50
|
+
readonly params?: Readonly<Record<string, unknown>>;
|
|
51
|
+
readonly inputs?: {
|
|
52
|
+
readonly datasets?: readonly {
|
|
53
|
+
readonly dataset_id?: string;
|
|
54
|
+
}[];
|
|
55
|
+
readonly profiles?: readonly {
|
|
56
|
+
readonly profile_id?: string;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface RunBindingContext {
|
|
61
|
+
readonly analysis_id: string;
|
|
62
|
+
readonly runs: readonly ModuleRunRecordV2[];
|
|
63
|
+
readResult(record: ModuleRunRecordV2): Promise<ModuleResult | undefined>;
|
|
64
|
+
readRequest(record: ModuleRunRecordV2): Promise<RunRequestFacts | undefined>;
|
|
65
|
+
}
|
|
66
|
+
export interface CalculationBindingIssue {
|
|
67
|
+
readonly code: AnalysisErrorCode;
|
|
68
|
+
readonly detail: string;
|
|
69
|
+
}
|
|
70
|
+
export interface CalculationBinding {
|
|
71
|
+
readonly calculations: readonly Calculation[];
|
|
72
|
+
readonly issues: readonly CalculationBindingIssue[];
|
|
73
|
+
}
|
|
74
|
+
/** Parse `analysis_run:<analysis_id>/<module_run_id>`; the binding code is the only parser. */
|
|
75
|
+
export declare function parseRunRef(ref: string): {
|
|
76
|
+
analysisId: string;
|
|
77
|
+
moduleRunId: string;
|
|
78
|
+
} | undefined;
|
|
79
|
+
export declare function bindCalculations(raw: readonly CalculationV2[], context: RunBindingContext, methodsUsed: AnalysisArtifact['methods_used']): Promise<CalculationBinding>;
|
|
44
80
|
export {};
|