vela-protocol 0.230.0

Core library for the Vela scientific knowledge protocol: replayable frontier state, signed canonical events, and proof packets.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
//! Tool registry — tools defined as data, separate from execution.
//! Borrowed from Codex (MIT) tool-as-data pattern.

use crate::permission::PermissionLevel;
use serde::Serialize;
use serde_json::{Value, json};

#[derive(Debug, Clone, Serialize)]
pub struct ToolDefinition {
    pub name: String,
    pub description: String,
    pub parameters: Value,
    pub permission_level: PermissionLevel,
    pub mutating: bool,
    pub caveats: Vec<String>,
}

/// All MCP tools registered in Vela
pub fn all_tools() -> Vec<ToolDefinition> {
    vec![
        tool(
            "frontier_stats",
            "Return frontier metadata and statistics: finding count, links, confidence distribution, gaps, categories, and review state.",
            json!({"type": "object", "properties": {}}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "search_findings",
            "Search findings by text content, entity name, entity type, or assertion type. Returns matching findings.",
            json!({"type": "object", "properties": {
                "query": {"type": "string"}, "entity": {"type": "string"},
                "entity_type": {"type": "string"}, "assertion_type": {"type": "string"},
                "limit": {"type": "integer"}
            }}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "get_finding",
            "Get a single finding by ID, including evidence, conditions, links, confidence, and provenance.",
            json!({"type": "object", "properties": {"id": {"type": "string"}}, "required": ["id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "get_finding_history",
            "v0.17: Return the chronological event log for one finding (asserted, reviewed, caveated, noted, confidence-revised, superseded, retracted). Use this to walk the supersedes chain, audit corrections, or detect that a target has been refined since you last linked to it.",
            json!({"type": "object", "properties": {"id": {"type": "string"}}, "required": ["id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![
                "Event order reflects timestamps as recorded; sort client-side if you need a different ordering.",
            ],
        ),
        tool(
            "list_gaps",
            "List findings flagged as candidate gap review leads.",
            json!({"type": "object", "properties": {}}),
            PermissionLevel::ReadOnly,
            false,
            vec![
                "Candidate gap rankings are review leads, not guaranteed underexplored areas or experiment targets.",
            ],
        ),
        tool(
            "list_contradictions",
            "List contradiction and dispute links between findings.",
            json!({"type": "object", "properties": {}}),
            PermissionLevel::ReadOnly,
            false,
            vec![
                "Automated contradiction links are candidates for review, not definitive disagreements.",
            ],
        ),
        tool(
            "find_bridges",
            "Find entities spanning multiple assertion categories, suggesting candidate cross-domain connections.",
            json!({"type": "object", "properties": {
                "min_categories": {"type": "integer"}, "limit": {"type": "integer"}
            }}),
            PermissionLevel::ReadOnly,
            false,
            vec!["Candidate bridges require review before being treated as domain knowledge."],
        ),
        tool(
            "check_pubmed",
            "Run a rough PubMed prior-art check for a hypothesis.",
            json!({"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]}),
            PermissionLevel::ReadOnly,
            false,
            vec!["PubMed counts are rough prior-art signals, not proof of novelty."],
        ),
        tool(
            "apply_observer",
            "Rerank findings under an observer policy such as pharma, academic, regulatory, clinical, or exploration.",
            json!({"type": "object", "properties": {
                "policy": {"type": "string"}, "limit": {"type": "integer"}
            }, "required": ["policy"]}),
            PermissionLevel::ReadOnly,
            false,
            vec!["Observer policy output is a weighted view, not definitive disagreement."],
        ),
        tool(
            "propagate_retraction",
            "Simulate retraction cascade impact over declared dependency/support links.",
            json!({"type": "object", "properties": {"finding_id": {"type": "string"}}, "required": ["finding_id"]}),
            PermissionLevel::Dangerous,
            false,
            vec!["Retraction impact is simulated over declared links only."],
        ),
        tool(
            "trace_evidence_chain",
            "Trace evidence lineage for a finding, including support, dependency, contradiction, and chain strength.",
            json!({"type": "object", "properties": {
                "finding_id": {"type": "string"}, "depth": {"type": "integer"}
            }, "required": ["finding_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec!["Evidence-chain strength is heuristic and depends on declared links."],
        ),
        // Phase Q-r (v0.5): cursor-paginated read over the canonical
        // event log. Agent loops use this to learn when their proposals
        // were accepted, rejected, or had cascade events emitted on
        // their behalf. Public consumers use it to track frontier state
        // changes without re-reading the full log.
        tool(
            "list_events_since",
            "List canonical events from the event log strictly after `cursor` (a `vev_…` id), ordered chronologically. Returns events plus a `next_cursor` for further pagination, or null when the tail is reached. Omit `cursor` to start from the genesis event.",
            json!({"type": "object", "properties": {
                "cursor": {"type": "string"},
                "limit": {"type": "integer"}
            }}),
            PermissionLevel::ReadOnly,
            false,
            vec![
                "Cursor must reference an event currently in the log; out-of-sync clients should restart from the beginning.",
            ],
        ),
        // Phase Q-w (v0.5): write surface — propose-* and decision tools.
        // Each requires a registered actor and a verifying Ed25519 signature
        // over the canonical preimage. Idempotent under Phase P:
        // identical logical proposals produce the same `vpr_…` and a retry
        // returns the existing record without duplicating state.
        tool(
            "propose_review",
            "Propose a `finding.review` decision on a finding (status: accepted/approved/contested/needs_revision/rejected). Requires the actor's Ed25519 signature over the canonical proposal preimage. Idempotent: identical logical proposals return the same `vpr_…`.",
            json!({"type": "object", "properties": {
                "actor_id": {"type": "string"},
                "target_finding_id": {"type": "string"},
                "status": {"type": "string"},
                "reason": {"type": "string"},
                "created_at": {"type": "string"},
                "signature": {"type": "string"}
            }, "required": ["actor_id", "target_finding_id", "status", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "actor_id must be registered in `frontier.actors` via `vela actor add` before writes verify.",
            ],
        ),
        tool(
            "propose_note",
            "Propose attaching a `finding.note` annotation to a finding. Requires a registered actor and signature. Optional structured `provenance` (Phase β, v0.6): `{doi?, pmid?, title?, span?}` with at least one identifier. Stays `pending_review` until accepted.",
            json!({"type": "object", "properties": {
                "actor_id": {"type": "string"},
                "target_finding_id": {"type": "string"},
                "text": {"type": "string"},
                "reason": {"type": "string"},
                "created_at": {"type": "string"},
                "signature": {"type": "string"},
                "provenance": {
                    "type": "object",
                    "properties": {
                        "doi": {"type": "string"},
                        "pmid": {"type": "string"},
                        "title": {"type": "string"},
                        "span": {"type": "string"}
                    }
                }
            }, "required": ["actor_id", "target_finding_id", "text", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec!["Notes do not change finding state; they accrete review context."],
        ),
        // Phase α (v0.6): one-call propose-and-apply for `finding.note`,
        // gated on actor `tier="auto-notes"`. Halves the signing surface
        // for trusted bulk-note extractors. Identical signing preimage and
        // arguments as `propose_note`; idempotent under Phase P.
        tool(
            "propose_and_apply_note",
            "Propose AND apply a `finding.note` annotation in one signed call. Requires the actor to have `tier=\"auto-notes\"` registered (`vela actor add --tier auto-notes`). Optional structured `provenance` (Phase β). Idempotent: a retry with identical content returns the same `applied_event_id`.",
            json!({"type": "object", "properties": {
                "actor_id": {"type": "string"},
                "target_finding_id": {"type": "string"},
                "text": {"type": "string"},
                "reason": {"type": "string"},
                "created_at": {"type": "string"},
                "signature": {"type": "string"},
                "provenance": {
                    "type": "object",
                    "properties": {
                        "doi": {"type": "string"},
                        "pmid": {"type": "string"},
                        "title": {"type": "string"},
                        "span": {"type": "string"}
                    }
                }
            }, "required": ["actor_id", "target_finding_id", "text", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Requires actor.tier=auto-notes; calls from non-tiered actors are rejected.",
                "Notes still do not change finding state — they accrete review context.",
            ],
        ),
        tool(
            "propose_revise_confidence",
            "Propose a confidence revision (`finding.confidence_revise`) on a finding. `new_score` must be in [0.0, 1.0]. Requires a registered actor and signature.",
            json!({"type": "object", "properties": {
                "actor_id": {"type": "string"},
                "target_finding_id": {"type": "string"},
                "new_score": {"type": "number"},
                "reason": {"type": "string"},
                "created_at": {"type": "string"},
                "signature": {"type": "string"}
            }, "required": ["actor_id", "target_finding_id", "new_score", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Confidence revisions update score and basis; they do not change scope or evidence.",
            ],
        ),
        tool(
            "propose_retract",
            "Propose retracting a finding (`finding.retract`). Applying triggers per-dependent `finding.dependency_invalidated` events through the propagation graph. Requires a registered actor and signature.",
            json!({"type": "object", "properties": {
                "actor_id": {"type": "string"},
                "target_finding_id": {"type": "string"},
                "reason": {"type": "string"},
                "created_at": {"type": "string"},
                "signature": {"type": "string"}
            }, "required": ["actor_id", "target_finding_id", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Retraction propagates through declared dependency/support links; review impact before applying.",
            ],
        ),
        tool(
            "accept_proposal",
            "Apply a pending proposal as the named reviewer. The reviewer must be registered. Signature is over `{action: \"accept\", proposal_id, reviewer_id, reason, timestamp}` canonicalized. Idempotent: re-applying returns the same `applied_event_id`.",
            json!({"type": "object", "properties": {
                "proposal_id": {"type": "string"},
                "reviewer_id": {"type": "string"},
                "reason": {"type": "string"},
                "timestamp": {"type": "string"},
                "signature": {"type": "string"}
            }, "required": ["proposal_id", "reviewer_id", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Accepting an applied proposal returns its existing event_id; no duplicate event is emitted.",
            ],
        ),
        tool(
            "reject_proposal",
            "Reject a pending proposal as the named reviewer. The reviewer must be registered. Signature is over `{action: \"reject\", proposal_id, reviewer_id, reason, timestamp}` canonicalized.",
            json!({"type": "object", "properties": {
                "proposal_id": {"type": "string"},
                "reviewer_id": {"type": "string"},
                "reason": {"type": "string"},
                "timestamp": {"type": "string"},
                "signature": {"type": "string"}
            }, "required": ["proposal_id", "reviewer_id", "reason", "signature"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Rejection records the decision but emits no canonical event; rejected proposals stay on the proposal log.",
            ],
        ),
        // v0.206: write-side tools that bridge the vela_agent SDK.
        // Both require VELA_AGENT_KEY_HEX to be set in the server
        // environment so the substrate has an Ed25519 signing key
        // for the produced vaa_* + vsd_* artifacts.
        tool(
            "vela_agent_submit_diff_pack",
            "v0.206: one-shot agent submission. Signs a vaa_* Agent Attestation envelope + a vsd_* Scientific Diff Pack bundling N proposals, writes both to the frontier's .vela/ tree, and returns the resulting ids. Requires VELA_AGENT_KEY_HEX in the server env.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "agent_actor": {"type": "string", "description": "Must start with `agent:`."},
                "model_name": {"type": "string"},
                "model_version": {"type": "string"},
                "prompt": {"type": "string", "description": "Hashed server-side; not stored verbatim."},
                "started_at": {"type": "string"},
                "finished_at": {"type": "string"},
                "total_tokens": {"type": "integer"},
                "tool_calls": {"type": "array", "items": {"type": "object", "properties": {
                    "tool_name": {"type": "string"},
                    "input": {},
                    "output": {},
                    "duration_ms": {"type": "integer"}
                }}},
                "proposals": {"type": "array", "items": {"type": "object", "properties": {
                    "kind": {"type": "string"},
                    "payload": {}
                }, "required": ["kind", "payload"]}, "minItems": 1},
                "summary": {"type": "string"},
                "aggregate_kind": {"type": "string"},
                "parent_attestation": {"type": "string"},
                "parent_pack": {"type": "string"}
            }, "required": ["frontier_path", "agent_actor", "model_name", "model_version", "summary", "aggregate_kind", "proposals"]}),
            PermissionLevel::Write,
            true,
            vec![
                "Refuses to operate without VELA_AGENT_KEY_HEX set; no silent unsigned submissions.",
                "Writes to .vela/agent_attestations/, .vela/diff_packs/, .vela/agent_proposals/ — does NOT pass through the canonical proposal reducer.",
                "Resulting pack is reviewer-pending until a reviewer issues a verdict via the v0.203 workbench + v0.205 promoter.",
            ],
        ),
        tool(
            "vela_agent_open_trajectory",
            "v0.206: write a vtr_* Trajectory with N typed steps to .vela/trajectories/. Trajectories are content-addressed but unsigned; the chain of custody lives in the `deposited_by` actor id.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "target_findings": {"type": "array", "items": {"type": "string"}},
                "deposited_by": {"type": "string"},
                "notes": {"type": "string"},
                "steps": {"type": "array", "items": {"type": "object", "properties": {
                    "kind": {"type": "string", "description": "One of the 17 v0.194 step kinds: hypothesis, tried, ruled_out, observed, refined, question, context, data, tool, model, expert, decision, protocol, output, review, risk, outcome."},
                    "description": {"type": "string"},
                    "references": {"type": "array", "items": {"type": "string"}},
                    "actor": {"type": "string"}
                }, "required": ["kind", "description"]}, "minItems": 1}
            }, "required": ["frontier_path", "deposited_by", "steps"]}),
            PermissionLevel::Write,
            true,
            vec!["Trajectories are unsigned — they document a search path, not a truth claim."],
        ),
        // v0.214: read-side tools. None require a signing key. They
        // give a multi-turn LLM session a way to inspect prior
        // context before composing a submission.
        tool(
            "vela_agent_frontier_summary",
            "v0.214: counts of every v0.193+ primitive on a frontier. Use as the first call in a multi-turn agent session to see what already exists before submitting new work.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"}
            }, "required": ["frontier_path"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_get_pack",
            "v0.214: fetch a Scientific Diff Pack body by id from a frontier's .vela/diff_packs/.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "pack_id": {"type": "string", "description": "vsd_<16hex>"}
            }, "required": ["frontier_path", "pack_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_list_packs",
            "v0.214: list every Scientific Diff Pack on a frontier. Set only_pending=true to filter to packs awaiting reviewer verdict.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "only_pending": {"type": "boolean"}
            }, "required": ["frontier_path"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_get_attestation",
            "v0.214: fetch an Agent Attestation envelope body by id from a frontier's .vela/agent_attestations/.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "attestation_id": {"type": "string", "description": "vaa_<16hex>"}
            }, "required": ["frontier_path", "attestation_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_list_trajectories",
            "v0.214: list every Trajectory on a frontier. Returns full bodies including steps.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"}
            }, "required": ["frontier_path"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        // v0.220: parity read tools for tool descriptors, evaluation
        // records, and verdict conflicts. None require a signing key.
        tool(
            "vela_agent_get_tool_descriptor",
            "v0.220: fetch a Tool Descriptor body by id from a frontier's .vela/tool_descriptors/.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "descriptor_id": {"type": "string", "description": "vtd_<16hex>"}
            }, "required": ["frontier_path", "descriptor_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_get_evaluation",
            "v0.220: fetch an Evaluation Record body by id from a frontier's .vela/evaluations/.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "evaluation_id": {"type": "string", "description": "ver_<16hex>"}
            }, "required": ["frontier_path", "evaluation_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_list_evaluations",
            "v0.220: list every Evaluation Record on a frontier. Optionally filter by target Tool Descriptor.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "target_descriptor_id": {"type": "string", "description": "Optional vtd_<16hex> to filter on"}
            }, "required": ["frontier_path"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_get_conflict",
            "v0.220: fetch a resolved Verdict Conflict body by id from a frontier's .vela/verdict_conflicts/.",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "conflict_id": {"type": "string", "description": "vdc_<16hex>"}
            }, "required": ["frontier_path", "conflict_id"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
        tool(
            "vela_agent_list_conflicts",
            "v0.220: list every resolved Verdict Conflict on a frontier. Optionally filter by resolution_mode (majority, owner_override, escalation).",
            json!({"type": "object", "properties": {
                "frontier_path": {"type": "string"},
                "resolution_mode": {"type": "string", "description": "Optional filter: majority, owner_override, or escalation"}
            }, "required": ["frontier_path"]}),
            PermissionLevel::ReadOnly,
            false,
            vec![],
        ),
    ]
}

pub fn get_tool(name: &str) -> Option<ToolDefinition> {
    all_tools().into_iter().find(|tool| tool.name == name)
}

pub fn tool_caveats(name: &str) -> Vec<String> {
    get_tool(name).map(|tool| tool.caveats).unwrap_or_default()
}

pub fn mcp_tools_json() -> Value {
    Value::Array(
        all_tools()
            .into_iter()
            .map(|tool| {
                json!({
                    "name": tool.name,
                    "description": tool.description,
                    "inputSchema": tool.parameters,
                    "metadata": {
                        "permission_level": tool.permission_level,
                        "mutating": tool.mutating,
                        "caveats": tool.caveats,
                    }
                })
            })
            .collect(),
    )
}

fn tool(
    name: &str,
    description: &str,
    parameters: Value,
    permission_level: PermissionLevel,
    mutating: bool,
    caveats: Vec<&str>,
) -> ToolDefinition {
    ToolDefinition {
        name: name.to_string(),
        description: description.to_string(),
        parameters,
        permission_level,
        mutating,
        caveats: caveats.into_iter().map(str::to_string).collect(),
    }
}