@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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schemas for the analysis family and the module protocol. One carrier per shape: tools,
|
|
3
|
+
* host validation and the worker all read these, so a hand-written second copy would drift.
|
|
4
|
+
*
|
|
5
|
+
* `additionalProperties: false` everywhere is deliberate — an undeclared field is a protocol
|
|
6
|
+
* change, and silently accepting it would make the artifact contract a suggestion.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Submit-time budgets; exceeding one names the offending section (`analysis_result_too_large`).
|
|
10
|
+
* 30k: a comprehensive multi-period artifact naturally lands at 20–22k, and a 20k cap made the
|
|
11
|
+
* model rewrite the same artifact for minutes instead of finishing (2026-11-25 real session).
|
|
12
|
+
*/
|
|
13
|
+
export declare const ARTIFACT_MAX_CHARS = 30000;
|
|
14
|
+
export declare const HEADLINE_MAX_CHARS = 300;
|
|
15
|
+
export declare const THESIS_MAX_CHARS = 1200;
|
|
16
|
+
export declare const STATEMENT_MAX_CHARS = 600;
|
|
17
|
+
export declare const MAX_CLAIMS = 20;
|
|
18
|
+
export declare const MAX_SCENARIOS = 8;
|
|
19
|
+
/** §5.6-2 peer round-trip budget per task_id. The send edge stops the fourth request; this is the record check. */
|
|
20
|
+
export declare const MAX_PEER_EXCHANGES = 3;
|
|
21
|
+
/** Bounded evidence intake: single item bytes and total count. */
|
|
22
|
+
export declare const EVIDENCE_ITEM_MAX_BYTES = 2048;
|
|
23
|
+
export declare const EVIDENCE_MAX_ITEMS = 20;
|
|
24
|
+
/** `expires_at = min(created_at + 7d, earliest input retention)`. */
|
|
25
|
+
export declare const SNAPSHOT_TTL_MS: number;
|
|
26
|
+
/** Module limits when a manifest omits one; the manifest may only tighten them. */
|
|
27
|
+
export declare const MODULE_DEFAULT_LIMITS: {
|
|
28
|
+
readonly timeout_ms: 30000;
|
|
29
|
+
readonly max_input_rows: 200000;
|
|
30
|
+
readonly max_output_bytes: 1048576;
|
|
31
|
+
readonly max_log_bytes: 65536;
|
|
32
|
+
};
|
|
33
|
+
export declare const EVIDENCE_SCHEMA: Record<string, unknown>;
|
|
34
|
+
export declare const NUMBER_ANCHOR_SCHEMA: Record<string, unknown>;
|
|
35
|
+
export declare const CLAIM_SCHEMA: Record<string, unknown>;
|
|
36
|
+
export declare const CALCULATION_SCHEMA: Record<string, unknown>;
|
|
37
|
+
export declare const PEER_EXCHANGE_SCHEMA: Record<string, unknown>;
|
|
38
|
+
export declare const SCENARIO_SCHEMA: Record<string, unknown>;
|
|
39
|
+
/** `submit_analysis` parameters: the final artifact, minus the host-written `validation`. */
|
|
40
|
+
export declare const ANALYSIS_ARTIFACT_SCHEMA: Record<string, unknown>;
|
|
41
|
+
export declare const MODULE_MANIFEST_SCHEMA: Record<string, unknown>;
|
|
42
|
+
export declare const MODULE_REQUEST_SCHEMA: Record<string, unknown>;
|
|
43
|
+
/** Worker result. `outputs` carry refs only; large payloads live under `modules/<id>/outputs/`. */
|
|
44
|
+
export declare const MODULE_RESULT_SCHEMA: Record<string, unknown>;
|
|
45
|
+
/** `context.read_dataset` shape handed to a module; `rows` never crosses the tool boundary. */
|
|
46
|
+
export declare const DATASET_VIEW_SCHEMA: Record<string, unknown>;
|
|
47
|
+
export declare const CREATE_SNAPSHOT_PARAMETERS: Record<string, unknown>;
|
|
48
|
+
export declare const CREATE_SNAPSHOT_OUTPUT: Record<string, unknown>;
|
|
49
|
+
export declare const READ_PROFILE_PARAMETERS: Record<string, unknown>;
|
|
50
|
+
/** Bounded profile facts; `hint` is present when the payload was cut by the shared size gate. */
|
|
51
|
+
export declare const READ_PROFILE_OUTPUT: Record<string, unknown>;
|
|
52
|
+
export declare const LIST_MODULES_OUTPUT: Record<string, unknown>;
|
|
53
|
+
export declare const DESCRIBE_MODULE_OUTPUT: Record<string, unknown>;
|
|
54
|
+
export declare const LIST_MODULES_PARAMETERS: Record<string, unknown>;
|
|
55
|
+
export declare const DESCRIBE_MODULE_PARAMETERS: Record<string, unknown>;
|
|
56
|
+
export declare const RUN_ANALYSIS_PARAMETERS: Record<string, unknown>;
|
|
57
|
+
export declare const RUN_ANALYSIS_OUTPUT: Record<string, unknown>;
|
|
58
|
+
export declare const SUBMIT_ANALYSIS_OUTPUT: Record<string, unknown>;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schemas for the analysis family and the module protocol. One carrier per shape: tools,
|
|
3
|
+
* host validation and the worker all read these, so a hand-written second copy would drift.
|
|
4
|
+
*
|
|
5
|
+
* `additionalProperties: false` everywhere is deliberate — an undeclared field is a protocol
|
|
6
|
+
* change, and silently accepting it would make the artifact contract a suggestion.
|
|
7
|
+
*/
|
|
8
|
+
const jsonObject = (properties = {}, required = []) => ({ type: 'object', properties, required, additionalProperties: false });
|
|
9
|
+
const strings = (description) => ({ type: 'array', items: { type: 'string' }, ...(description === undefined ? {} : { description }) });
|
|
10
|
+
// `oneOf`, not `anyOf`: the host's enforced JSON-Schema subset (dsh-tools) accepts exact-one only,
|
|
11
|
+
// and a tool definition outside that subset makes the whole family row unsupported at boot.
|
|
12
|
+
const nullable = (schema) => ({ oneOf: [schema, { type: 'null' }] });
|
|
13
|
+
/**
|
|
14
|
+
* Submit-time budgets; exceeding one names the offending section (`analysis_result_too_large`).
|
|
15
|
+
* 30k: a comprehensive multi-period artifact naturally lands at 20–22k, and a 20k cap made the
|
|
16
|
+
* model rewrite the same artifact for minutes instead of finishing (2026-11-25 real session).
|
|
17
|
+
*/
|
|
18
|
+
export const ARTIFACT_MAX_CHARS = 30_000;
|
|
19
|
+
export const HEADLINE_MAX_CHARS = 300;
|
|
20
|
+
export const THESIS_MAX_CHARS = 1_200;
|
|
21
|
+
export const STATEMENT_MAX_CHARS = 600;
|
|
22
|
+
export const MAX_CLAIMS = 20;
|
|
23
|
+
export const MAX_SCENARIOS = 8;
|
|
24
|
+
/** §5.6-2 peer round-trip budget per task_id. The send edge stops the fourth request; this is the record check. */
|
|
25
|
+
export const MAX_PEER_EXCHANGES = 3;
|
|
26
|
+
/** Bounded evidence intake: single item bytes and total count. */
|
|
27
|
+
export const EVIDENCE_ITEM_MAX_BYTES = 2_048;
|
|
28
|
+
export const EVIDENCE_MAX_ITEMS = 20;
|
|
29
|
+
/** `expires_at = min(created_at + 7d, earliest input retention)`. */
|
|
30
|
+
export const SNAPSHOT_TTL_MS = 7 * 24 * 60 * 60 * 1_000;
|
|
31
|
+
/** Module limits when a manifest omits one; the manifest may only tighten them. */
|
|
32
|
+
export const MODULE_DEFAULT_LIMITS = {
|
|
33
|
+
timeout_ms: 30_000,
|
|
34
|
+
max_input_rows: 200_000,
|
|
35
|
+
max_output_bytes: 1_048_576,
|
|
36
|
+
max_log_bytes: 65_536,
|
|
37
|
+
};
|
|
38
|
+
export const EVIDENCE_SCHEMA = jsonObject({
|
|
39
|
+
source_id: { type: 'string' },
|
|
40
|
+
kind: { type: 'string', enum: ['filing', 'news', 'research', 'user_material'] },
|
|
41
|
+
title: { type: 'string' },
|
|
42
|
+
source: { type: 'string' },
|
|
43
|
+
published_at: { type: 'string' },
|
|
44
|
+
url: { type: 'string' },
|
|
45
|
+
excerpt: { type: 'string' },
|
|
46
|
+
verification: { type: 'string', enum: ['verified_official', 'unverified', 'not_verified'] },
|
|
47
|
+
}, ['source_id', 'kind', 'title', 'verification']);
|
|
48
|
+
export const NUMBER_ANCHOR_SCHEMA = jsonObject({
|
|
49
|
+
value: { type: 'number' },
|
|
50
|
+
unit: { type: 'string' },
|
|
51
|
+
period: { type: 'string' },
|
|
52
|
+
source: jsonObject({
|
|
53
|
+
kind: { type: 'string', enum: ['dataset', 'profile', 'evidence', 'computation'] },
|
|
54
|
+
ref: { type: 'string' },
|
|
55
|
+
}, ['kind', 'ref']),
|
|
56
|
+
precision: { type: 'integer' },
|
|
57
|
+
}, ['value', 'unit', 'source']);
|
|
58
|
+
export const CLAIM_SCHEMA = jsonObject({
|
|
59
|
+
claim_id: { type: 'string' },
|
|
60
|
+
type: { type: 'string', enum: ['fact', 'observation', 'inference', 'hypothesis'] },
|
|
61
|
+
statement: { type: 'string' },
|
|
62
|
+
evidence_refs: strings(),
|
|
63
|
+
number_anchors: { type: 'array', items: NUMBER_ANCHOR_SCHEMA },
|
|
64
|
+
confidence: { type: 'string', enum: ['low', 'medium', 'high'] },
|
|
65
|
+
confidence_basis: { type: 'string' },
|
|
66
|
+
falsifier: { type: 'string' },
|
|
67
|
+
limitations: strings(),
|
|
68
|
+
}, ['claim_id', 'type', 'statement', 'confidence']);
|
|
69
|
+
export const CALCULATION_SCHEMA = jsonObject({
|
|
70
|
+
calculation_id: { type: 'string' },
|
|
71
|
+
module_id: { type: 'string' },
|
|
72
|
+
module_version: { type: 'string' },
|
|
73
|
+
metric: { type: 'string' },
|
|
74
|
+
value: { type: 'number' },
|
|
75
|
+
unit: { type: 'string' },
|
|
76
|
+
params_digest: { type: 'string' },
|
|
77
|
+
}, ['calculation_id', 'module_id', 'module_version', 'metric', 'value', 'unit']);
|
|
78
|
+
export const PEER_EXCHANGE_SCHEMA = jsonObject({
|
|
79
|
+
peer: { type: 'string' },
|
|
80
|
+
type: { type: 'string' },
|
|
81
|
+
request_id: { type: 'string' },
|
|
82
|
+
answered: { type: 'boolean' },
|
|
83
|
+
}, ['peer', 'type', 'request_id', 'answered']);
|
|
84
|
+
export const SCENARIO_SCHEMA = jsonObject({
|
|
85
|
+
name: { type: 'string' },
|
|
86
|
+
assumptions: strings(),
|
|
87
|
+
outcome: { type: 'string' },
|
|
88
|
+
triggers: strings(),
|
|
89
|
+
}, ['name', 'assumptions']);
|
|
90
|
+
/** `submit_analysis` parameters: the final artifact, minus the host-written `validation`. */
|
|
91
|
+
export const ANALYSIS_ARTIFACT_SCHEMA = jsonObject({
|
|
92
|
+
analysis_id: { type: 'string' },
|
|
93
|
+
task_id: { type: 'string' },
|
|
94
|
+
snapshot_id: { type: 'string' },
|
|
95
|
+
status: { type: 'string', enum: ['completed', 'partial', 'blocked'] },
|
|
96
|
+
evidence_level: { type: 'string', enum: ['sufficient', 'limited', 'insufficient'] },
|
|
97
|
+
headline: { type: 'string' },
|
|
98
|
+
thesis: { type: 'string' },
|
|
99
|
+
support_claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
100
|
+
counter_claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
101
|
+
alternative_explanations: strings(),
|
|
102
|
+
contradictions: strings(),
|
|
103
|
+
calculations: { type: 'array', items: CALCULATION_SCHEMA },
|
|
104
|
+
scenarios: { type: 'array', items: SCENARIO_SCHEMA },
|
|
105
|
+
invalidation_conditions: strings(),
|
|
106
|
+
unresolved_gaps: strings(),
|
|
107
|
+
limitations: strings(),
|
|
108
|
+
methods_used: {
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: jsonObject({ module_id: { type: 'string' }, module_version: { type: 'string' } }, ['module_id', 'module_version']),
|
|
111
|
+
},
|
|
112
|
+
peer_exchanges: { type: 'array', items: PEER_EXCHANGE_SCHEMA },
|
|
113
|
+
}, [
|
|
114
|
+
'analysis_id', 'task_id', 'snapshot_id', 'status', 'evidence_level', 'headline', 'thesis',
|
|
115
|
+
'support_claims', 'counter_claims', 'alternative_explanations', 'contradictions', 'calculations',
|
|
116
|
+
'scenarios', 'invalidation_conditions', 'unresolved_gaps', 'limitations', 'methods_used', 'peer_exchanges',
|
|
117
|
+
]);
|
|
118
|
+
export const MODULE_MANIFEST_SCHEMA = jsonObject({
|
|
119
|
+
id: { type: 'string' },
|
|
120
|
+
version: { type: 'string' },
|
|
121
|
+
entrypoint: { type: 'string' },
|
|
122
|
+
runtime: { type: 'string', enum: ['python'] },
|
|
123
|
+
description: { type: 'string' },
|
|
124
|
+
roles: strings(),
|
|
125
|
+
capabilities: { type: 'array', items: { type: 'string', enum: ['dataset.read', 'profile.read', 'evidence.read'] } },
|
|
126
|
+
required_fields: strings(),
|
|
127
|
+
input_schema: { type: 'object' },
|
|
128
|
+
output_schema: { type: 'object' },
|
|
129
|
+
assumptions: strings(),
|
|
130
|
+
applicability: strings(),
|
|
131
|
+
limits: jsonObject({
|
|
132
|
+
timeout_ms: { type: 'integer' },
|
|
133
|
+
max_input_rows: { type: 'integer' },
|
|
134
|
+
max_output_bytes: { type: 'integer' },
|
|
135
|
+
max_log_bytes: { type: 'integer' },
|
|
136
|
+
}, ['timeout_ms', 'max_input_rows', 'max_output_bytes', 'max_log_bytes']),
|
|
137
|
+
provenance: jsonObject({
|
|
138
|
+
source_type: { type: 'string', enum: ['original', 'adapted'] },
|
|
139
|
+
repository: { type: 'string' },
|
|
140
|
+
commit: { type: 'string' },
|
|
141
|
+
license: { type: 'string' },
|
|
142
|
+
}, ['source_type', 'license']),
|
|
143
|
+
}, ['id', 'version', 'entrypoint', 'runtime', 'description', 'roles', 'capabilities', 'limits', 'provenance']);
|
|
144
|
+
export const MODULE_REQUEST_SCHEMA = jsonObject({
|
|
145
|
+
protocol: { type: 'string', enum: ['capital.analysis/v1'] },
|
|
146
|
+
task_id: { type: 'string' },
|
|
147
|
+
analysis_id: { type: 'string' },
|
|
148
|
+
module_run_id: { type: 'string' },
|
|
149
|
+
snapshot_id: { type: 'string' },
|
|
150
|
+
as_of: { type: 'string' },
|
|
151
|
+
inputs: jsonObject({
|
|
152
|
+
datasets: { type: 'array', items: jsonObject({ dataset_id: { type: 'string' } }, ['dataset_id']) },
|
|
153
|
+
profiles: { type: 'array', items: jsonObject({ profile_id: { type: 'string' } }, ['profile_id']) },
|
|
154
|
+
evidence: { type: 'array', items: EVIDENCE_SCHEMA },
|
|
155
|
+
}, ['datasets', 'profiles', 'evidence']),
|
|
156
|
+
params: { type: 'object' },
|
|
157
|
+
}, ['protocol', 'task_id', 'analysis_id', 'module_run_id', 'snapshot_id', 'as_of', 'inputs', 'params']);
|
|
158
|
+
/** Worker result. `outputs` carry refs only; large payloads live under `modules/<id>/outputs/`. */
|
|
159
|
+
export const MODULE_RESULT_SCHEMA = jsonObject({
|
|
160
|
+
status: { type: 'string', enum: ['completed', 'partial', 'blocked', 'failed'] },
|
|
161
|
+
summary: { type: 'string' },
|
|
162
|
+
metrics: { type: 'object' },
|
|
163
|
+
claims: { type: 'array', items: CLAIM_SCHEMA },
|
|
164
|
+
assumptions: strings(),
|
|
165
|
+
methodology_log: strings(),
|
|
166
|
+
sensitivity: { type: 'object' },
|
|
167
|
+
limitations: strings(),
|
|
168
|
+
data_gaps: strings(),
|
|
169
|
+
outputs: { type: 'array', items: jsonObject({ name: { type: 'string' }, ref: { type: 'string' } }, ['name', 'ref']) },
|
|
170
|
+
}, [
|
|
171
|
+
'status', 'summary', 'metrics', 'claims', 'assumptions', 'methodology_log', 'sensitivity',
|
|
172
|
+
'limitations', 'data_gaps', 'outputs',
|
|
173
|
+
]);
|
|
174
|
+
/** `context.read_dataset` shape handed to a module; `rows` never crosses the tool boundary. */
|
|
175
|
+
export const DATASET_VIEW_SCHEMA = jsonObject({
|
|
176
|
+
shape: { type: 'string', enum: ['rows', 'document'] },
|
|
177
|
+
columns: { type: 'array', items: jsonObject({ name: { type: 'string' }, type: { type: 'string' }, nullable: { type: 'boolean' } }, ['name', 'type', 'nullable']) },
|
|
178
|
+
row_count: { type: 'integer' },
|
|
179
|
+
rows: { type: 'array', items: { type: 'object' } },
|
|
180
|
+
envelope: nullable({ type: 'object' }),
|
|
181
|
+
time_axis: nullable(jsonObject({ column: { type: 'string' }, unit: { type: 'string' }, tz: { type: 'string' } }, ['column', 'unit', 'tz'])),
|
|
182
|
+
truncated: { type: 'boolean' },
|
|
183
|
+
source: jsonObject({ dataset_id: { type: 'string' }, captured_at: { type: 'integer' }, params_digest: { type: 'string' } }, ['dataset_id', 'captured_at', 'params_digest']),
|
|
184
|
+
}, ['shape', 'columns', 'row_count', 'rows', 'truncated', 'source']);
|
|
185
|
+
export const CREATE_SNAPSHOT_PARAMETERS = jsonObject({
|
|
186
|
+
task_id: { type: 'string' },
|
|
187
|
+
question: { type: 'string' },
|
|
188
|
+
instrument: { type: 'string' },
|
|
189
|
+
purpose: { type: 'string', enum: ['observe', 'research', 'holding_review'] },
|
|
190
|
+
horizon: { type: 'string' },
|
|
191
|
+
depth: { type: 'string', enum: ['quick', 'standard', 'deep'] },
|
|
192
|
+
as_of: { type: 'string' },
|
|
193
|
+
data_cutoff: { type: 'string' },
|
|
194
|
+
dataset_refs: { type: 'array', items: jsonObject({ dataset_id: { type: 'string' } }, ['dataset_id']) },
|
|
195
|
+
profile_refs: { type: 'array', items: jsonObject({ profile_id: { type: 'string' } }, ['profile_id']) },
|
|
196
|
+
evidence: { type: 'array', items: EVIDENCE_SCHEMA },
|
|
197
|
+
prior_analysis_refs: strings(),
|
|
198
|
+
constraints: { type: 'object' },
|
|
199
|
+
}, ['task_id', 'question', 'purpose', 'depth', 'as_of']);
|
|
200
|
+
export const CREATE_SNAPSHOT_OUTPUT = jsonObject({
|
|
201
|
+
analysis_snapshot_ref: { type: 'string' },
|
|
202
|
+
analysis_id: { type: 'string' },
|
|
203
|
+
input_fingerprint: { type: 'string' },
|
|
204
|
+
expires_at: { type: 'string' },
|
|
205
|
+
coverage: { type: 'object' },
|
|
206
|
+
limitations: strings(),
|
|
207
|
+
}, ['analysis_snapshot_ref', 'analysis_id', 'input_fingerprint', 'expires_at', 'coverage', 'limitations']);
|
|
208
|
+
export const READ_PROFILE_PARAMETERS = jsonObject({
|
|
209
|
+
profile_ref: { type: 'string' },
|
|
210
|
+
columns_of_interest: strings(),
|
|
211
|
+
}, ['profile_ref']);
|
|
212
|
+
/** Bounded profile facts; `hint` is present when the payload was cut by the shared size gate. */
|
|
213
|
+
export const READ_PROFILE_OUTPUT = jsonObject({
|
|
214
|
+
profile_ref: { type: 'string' },
|
|
215
|
+
columns: strings(),
|
|
216
|
+
facts: { type: 'object' },
|
|
217
|
+
time_axis: nullable(jsonObject({ column: { type: 'string' }, unit: { type: 'string' }, tz: { type: 'string' } }, ['column', 'unit', 'tz'])),
|
|
218
|
+
hint: { type: 'string' },
|
|
219
|
+
}, ['profile_ref', 'columns']);
|
|
220
|
+
export const LIST_MODULES_OUTPUT = jsonObject({
|
|
221
|
+
modules: {
|
|
222
|
+
type: 'array',
|
|
223
|
+
items: jsonObject({
|
|
224
|
+
id: { type: 'string' },
|
|
225
|
+
version: { type: 'string' },
|
|
226
|
+
description: { type: 'string' },
|
|
227
|
+
capabilities: strings(),
|
|
228
|
+
applicability: strings(),
|
|
229
|
+
limits: { type: 'object' },
|
|
230
|
+
}, ['id', 'version', 'description', 'capabilities', 'applicability', 'limits']),
|
|
231
|
+
},
|
|
232
|
+
}, ['modules']);
|
|
233
|
+
export const DESCRIBE_MODULE_OUTPUT = jsonObject({
|
|
234
|
+
module_id: { type: 'string' },
|
|
235
|
+
version: { type: 'string' },
|
|
236
|
+
input_schema: { type: 'object' },
|
|
237
|
+
output_schema: { type: 'object' },
|
|
238
|
+
required_fields: strings(),
|
|
239
|
+
assumptions: strings(),
|
|
240
|
+
capabilities: strings(),
|
|
241
|
+
limits: { type: 'object' },
|
|
242
|
+
}, ['module_id', 'version', 'input_schema', 'output_schema', 'required_fields', 'assumptions', 'capabilities', 'limits']);
|
|
243
|
+
export const LIST_MODULES_PARAMETERS = jsonObject({});
|
|
244
|
+
export const DESCRIBE_MODULE_PARAMETERS = jsonObject({ module_id: { type: 'string' } }, ['module_id']);
|
|
245
|
+
export const RUN_ANALYSIS_PARAMETERS = jsonObject({
|
|
246
|
+
analysis_snapshot_ref: { type: 'string' },
|
|
247
|
+
module_id: { type: 'string' },
|
|
248
|
+
params: { type: 'object' },
|
|
249
|
+
}, ['analysis_snapshot_ref', 'module_id']);
|
|
250
|
+
export const RUN_ANALYSIS_OUTPUT = jsonObject({
|
|
251
|
+
analysis_run_ref: { type: 'string' },
|
|
252
|
+
module_id: { type: 'string' },
|
|
253
|
+
module_version: { type: 'string' },
|
|
254
|
+
status: { type: 'string', enum: ['completed', 'partial', 'blocked', 'failed'] },
|
|
255
|
+
summary: { type: 'string' },
|
|
256
|
+
metrics: { type: 'object' },
|
|
257
|
+
assumptions: strings(),
|
|
258
|
+
limitations: strings(),
|
|
259
|
+
data_gaps: strings(),
|
|
260
|
+
validation: jsonObject({
|
|
261
|
+
status: { type: 'string', enum: ['pass', 'warning'] },
|
|
262
|
+
issues: { type: 'array', items: { type: 'object' } },
|
|
263
|
+
}, ['status', 'issues']),
|
|
264
|
+
reused: { type: 'boolean' },
|
|
265
|
+
}, [
|
|
266
|
+
'analysis_run_ref', 'module_id', 'module_version', 'status', 'summary', 'metrics', 'assumptions',
|
|
267
|
+
'limitations', 'data_gaps', 'validation', 'reused',
|
|
268
|
+
]);
|
|
269
|
+
export const SUBMIT_ANALYSIS_OUTPUT = jsonObject({
|
|
270
|
+
analysis_ref: { type: 'string' },
|
|
271
|
+
status: { type: 'string', enum: ['accepted'] },
|
|
272
|
+
validation: jsonObject({
|
|
273
|
+
status: { type: 'string', enum: ['pass', 'warning'] },
|
|
274
|
+
issues: { type: 'array', items: { type: 'object' } },
|
|
275
|
+
}, ['status', 'issues']),
|
|
276
|
+
}, ['analysis_ref', 'status', 'validation']);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type DatasetRef, type ProfilePayload, type ProfileRef, type SessionLike } from '../data-collector/store.js';
|
|
2
|
+
import { type AnalysisFileWriter } from './storage.js';
|
|
3
|
+
import { type AnalysisSnapshot, type DatasetRefLike, type EvidenceItem, type ProfileRefLike } from './types.js';
|
|
4
|
+
/** Narrow seam over the Dataset store: staging only needs these two host-internal reads. */
|
|
5
|
+
export interface AnalysisInputReader {
|
|
6
|
+
readPresentationRows(input: {
|
|
7
|
+
session: SessionLike;
|
|
8
|
+
dataset_id: string;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
maxRows?: number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
ref: DatasetRef;
|
|
13
|
+
rows: unknown[];
|
|
14
|
+
envelope?: Record<string, unknown>;
|
|
15
|
+
}>;
|
|
16
|
+
readProfile(input: {
|
|
17
|
+
session: SessionLike;
|
|
18
|
+
profile_id: string;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
ref: ProfileRef;
|
|
22
|
+
profile: ProfilePayload;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateSnapshotInput {
|
|
26
|
+
readonly task_id: string;
|
|
27
|
+
readonly question: string;
|
|
28
|
+
readonly instrument?: string;
|
|
29
|
+
readonly purpose: AnalysisSnapshot['purpose'];
|
|
30
|
+
readonly horizon?: string;
|
|
31
|
+
readonly depth: AnalysisSnapshot['depth'];
|
|
32
|
+
readonly as_of: string;
|
|
33
|
+
readonly data_cutoff?: string;
|
|
34
|
+
readonly dataset_refs: readonly DatasetRefLike[];
|
|
35
|
+
readonly profile_refs: readonly ProfileRefLike[];
|
|
36
|
+
readonly evidence: readonly EvidenceItem[];
|
|
37
|
+
readonly prior_analysis_refs: readonly string[];
|
|
38
|
+
readonly constraints: Readonly<Record<string, unknown>>;
|
|
39
|
+
}
|
|
40
|
+
export interface SnapshotRecord extends AnalysisSnapshot {
|
|
41
|
+
/** Host-only absolute paths handed to the worker; never returned to the model. */
|
|
42
|
+
readonly paths: {
|
|
43
|
+
readonly dir: string;
|
|
44
|
+
readonly inputs_dir: string;
|
|
45
|
+
};
|
|
46
|
+
readonly datasets: readonly StagedDataset[];
|
|
47
|
+
readonly profiles: readonly {
|
|
48
|
+
readonly ref: ProfileRef;
|
|
49
|
+
}[];
|
|
50
|
+
}
|
|
51
|
+
/** What the worker sees through `context.read_dataset` (docs/dev/senior-analysis.md §1.9). */
|
|
52
|
+
export interface StagedDataset {
|
|
53
|
+
readonly shape: 'rows' | 'document';
|
|
54
|
+
readonly columns: ReadonlyArray<{
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly type: string;
|
|
57
|
+
readonly nullable: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
readonly row_count: number;
|
|
60
|
+
readonly rows: readonly unknown[];
|
|
61
|
+
readonly envelope: Readonly<Record<string, unknown>> | null;
|
|
62
|
+
readonly time_axis: {
|
|
63
|
+
readonly column: string;
|
|
64
|
+
readonly unit: string;
|
|
65
|
+
readonly tz: string;
|
|
66
|
+
} | null;
|
|
67
|
+
readonly truncated: boolean;
|
|
68
|
+
readonly source: {
|
|
69
|
+
readonly dataset_id: string;
|
|
70
|
+
readonly captured_at: number;
|
|
71
|
+
readonly params_digest: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Deterministic JSON: key order must not change a fingerprint. */
|
|
75
|
+
export declare function stableStringify(value: unknown): string;
|
|
76
|
+
/**
|
|
77
|
+
* Create the snapshot and stage its inputs.
|
|
78
|
+
*
|
|
79
|
+
* Any ref that cannot be read fails the whole call and names the object: a snapshot that silently
|
|
80
|
+
* drops an input is worse than no snapshot, because every downstream number looks sourced.
|
|
81
|
+
*/
|
|
82
|
+
export declare function createSnapshot(options: {
|
|
83
|
+
reader: AnalysisInputReader;
|
|
84
|
+
writer: AnalysisFileWriter;
|
|
85
|
+
session: SessionLike;
|
|
86
|
+
input: CreateSnapshotInput;
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
now?: number;
|
|
89
|
+
}): Promise<{
|
|
90
|
+
record: SnapshotRecord;
|
|
91
|
+
ref: string;
|
|
92
|
+
}>;
|
|
93
|
+
/** Load a snapshot by ref and fail loudly when it is missing or expired. */
|
|
94
|
+
export declare function loadSnapshot(options: {
|
|
95
|
+
reader: AnalysisFileWriter;
|
|
96
|
+
session: SessionLike;
|
|
97
|
+
analysisId: string;
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
now?: number;
|
|
100
|
+
}): Promise<SnapshotRecord>;
|
|
101
|
+
/** Coverage summary returned to the model: counts and ranges only, never rows. */
|
|
102
|
+
export declare function snapshotCoverage(record: SnapshotRecord): Record<string, unknown>;
|