everruns-core 0.29.0

Transport-neutral agent execution contracts for Everruns
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//! Fixtures shared by the test modules.

use super::*;
use crate::message::Message;
use crate::message_filter::{MessageFilter, MessageFilterProvider, MessageQuery};
use crate::tool_types::ToolCall;
use crate::tools::{Tool, ToolExecutionResult};
use crate::typed_id::SessionId;
use async_trait::async_trait;
use std::collections::HashMap;
use std::sync::Arc;

/// Test helper: dummy context with no file store
pub(crate) fn test_ctx() -> SystemPromptContext {
    SystemPromptContext::without_file_store(SessionId::new())
}

// -------------------------------------------------------------------------
// Local stand-ins for the fixture capabilities that moved to the
// `everruns-test-support` crate (EVE-875). The registry/apply/dependency
// mechanics tested here only need capabilities with these shapes: one
// that contributes nothing, one that contributes plain tools, and one
// that carries mounts plus a dependency.
// -------------------------------------------------------------------------

pub(crate) struct StubSubagentSpawnTool;

#[async_trait]
impl Tool for StubSubagentSpawnTool {
    fn name(&self) -> &str {
        "spawn_agent"
    }
    fn description(&self) -> &str {
        "stub subagent delegation"
    }
    fn parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({ "type": "object" })
    }
    fn narrate(
        &self,
        tool_call: &ToolCall,
        phase: crate::tool_narration::ToolNarrationPhase,
        locale: Option<&str>,
        _ctx: crate::tool_narration::ToolNarrationContext<'_>,
    ) -> Option<String> {
        Some(crate::tool_narration::narrate_subagent_spawn(
            &tool_call.arguments,
            phase,
            locale,
        ))
    }
    async fn execute(&self, _arguments: serde_json::Value) -> crate::ToolExecutionResult {
        crate::ToolExecutionResult::success(serde_json::json!({}))
    }
}

pub(crate) fn spawn_agent_call(arguments: serde_json::Value) -> ToolCall {
    ToolCall {
        id: "call-1".to_string(),
        name: "spawn_agent".to_string(),
        arguments,
    }
}

/// Contributes nothing: no tools, no prompt, no dependencies.
pub(crate) struct NoopFixture;

impl Capability for NoopFixture {
    fn id(&self) -> &str {
        "noop"
    }
    fn name(&self) -> &str {
        "No-Op"
    }
    fn description(&self) -> &str {
        "Contributes nothing."
    }
}

/// Declares one arbitrary feature to exercise core's neutral projection.
pub(crate) struct FeatureFixture;

impl Capability for FeatureFixture {
    fn id(&self) -> &str {
        "feature_fixture"
    }
    fn name(&self) -> &str {
        "Feature Fixture"
    }
    fn description(&self) -> &str {
        "Declares one test-only feature."
    }
    fn features(&self) -> Vec<&'static str> {
        vec!["fixture_feature"]
    }
}

pub(crate) struct FixtureTool(pub(crate) &'static str);

#[async_trait]
impl Tool for FixtureTool {
    fn name(&self) -> &str {
        self.0
    }
    fn description(&self) -> &str {
        "Fixture tool."
    }
    fn parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({
            "type": "object",
            "properties": {},
            "additionalProperties": false
        })
    }
    async fn execute(&self, _arguments: serde_json::Value) -> ToolExecutionResult {
        ToolExecutionResult::success(serde_json::json!({ "ok": true }))
    }
}

pub(crate) struct BackgroundFixtureTool;

#[async_trait]
impl Tool for BackgroundFixtureTool {
    fn name(&self) -> &str {
        "bash"
    }
    fn description(&self) -> &str {
        "Fixture background-capable shell tool."
    }
    fn parameters_schema(&self) -> serde_json::Value {
        serde_json::json!({"type": "object"})
    }
    async fn execute(&self, _arguments: serde_json::Value) -> ToolExecutionResult {
        ToolExecutionResult::success(serde_json::json!({"ok": true}))
    }
    fn hints(&self) -> crate::tool_types::ToolHints {
        crate::tool_types::ToolHints {
            supports_background: Some(true),
            ..Default::default()
        }
    }
}

pub(crate) struct FileSystemFixture;

impl Capability for FileSystemFixture {
    fn id(&self) -> &str {
        "session_file_system"
    }
    fn name(&self) -> &str {
        "Fixture Filesystem"
    }
    fn description(&self) -> &str {
        "Fixture filesystem capability."
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![
            Box::new(FixtureTool("read_file")),
            Box::new(FixtureTool("write_file")),
        ]
    }
    fn features(&self) -> Vec<&'static str> {
        vec!["file_system"]
    }
}

/// Stands in for the product `session_storage` capability, which moved to
/// `everruns-platform` with the other service-backed families (EVE-886).
/// Feature computation is core's mechanism, so it is exercised here against
/// a fixture rather than a product implementation.
pub(crate) struct StorageFixture;

impl Capability for StorageFixture {
    fn id(&self) -> &str {
        "session_storage"
    }
    fn name(&self) -> &str {
        "Fixture Storage"
    }
    fn description(&self) -> &str {
        "Fixture session storage capability."
    }
    fn features(&self) -> Vec<&'static str> {
        vec!["secrets", "key_value"]
    }
}

pub(crate) struct BashFixture;

impl Capability for BashFixture {
    fn id(&self) -> &str {
        "bashkit_shell"
    }
    fn aliases(&self) -> Vec<&'static str> {
        vec!["virtual_bash"]
    }
    fn name(&self) -> &str {
        "Fixture Bash"
    }
    fn description(&self) -> &str {
        "Fixture shell capability."
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![Box::new(BackgroundFixtureTool)]
    }
    fn dependencies(&self) -> Vec<&'static str> {
        vec!["session_file_system"]
    }
    fn features(&self) -> Vec<&'static str> {
        vec!["file_system"]
    }
    fn risk_level(&self) -> RiskLevel {
        RiskLevel::High
    }
}

pub(crate) struct WebFetchFixture;

impl Capability for WebFetchFixture {
    fn id(&self) -> &str {
        "web_fetch"
    }
    fn name(&self) -> &str {
        "Fixture Web Fetch"
    }
    fn description(&self) -> &str {
        "Fixture web capability."
    }
    fn risk_level(&self) -> RiskLevel {
        RiskLevel::High
    }
}

/// Portable-policy-shaped stand-ins used only to exercise neutral core
/// collection mechanics after policy implementations moved out of core.
pub(crate) struct DynamicFactFixture;

impl Capability for DynamicFactFixture {
    fn id(&self) -> &str {
        "current_time"
    }
    fn name(&self) -> &str {
        "Dynamic Fact Fixture"
    }
    fn description(&self) -> &str {
        "Fixture with one dynamic fact and one tool."
    }
    fn icon(&self) -> Option<&str> {
        Some("clock")
    }
    fn category(&self) -> Option<&str> {
        Some("Core")
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![Box::new(FixtureTool("get_current_time"))]
    }
    fn facts(&self, _config: &serde_json::Value, _ctx: &FactsContext) -> Vec<Fact> {
        vec![Fact::dynamic("current_time", "fixture-now")]
    }
}

pub(crate) struct PromptToolFixture;

impl Capability for PromptToolFixture {
    fn id(&self) -> &str {
        "prompt_tool_fixture"
    }
    fn name(&self) -> &str {
        "Prompt Tool Fixture"
    }
    fn description(&self) -> &str {
        "Fixture with a static prompt and tool."
    }
    fn system_prompt_addition(&self) -> Option<&str> {
        Some("Task Management uses the write_todos tool.")
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![Box::new(FixtureTool("write_todos"))]
    }
}

pub(crate) struct SecondPromptFixture;

impl Capability for SecondPromptFixture {
    fn id(&self) -> &str {
        "second_prompt_fixture"
    }
    fn name(&self) -> &str {
        "Second Prompt Fixture"
    }
    fn description(&self) -> &str {
        "Fixture with a second static prompt."
    }
    fn system_prompt_addition(&self) -> Option<&str> {
        Some("A second capability prompt contribution.")
    }
}

pub(crate) struct DynamicPreviewFixture;

impl Capability for DynamicPreviewFixture {
    fn id(&self) -> &str {
        "agent_instructions"
    }
    fn name(&self) -> &str {
        "Dynamic Preview Fixture"
    }
    fn description(&self) -> &str {
        "Fixture whose runtime prompt is dynamic."
    }
    fn system_prompt_preview(&self) -> Option<String> {
        Some("Reads AGENTS.md dynamically.".to_string())
    }
}

/// Contributes four plain calculator-style tools and no prompt addition.
pub(crate) struct MathFixture;

impl Capability for MathFixture {
    fn id(&self) -> &str {
        "test_math"
    }
    fn name(&self) -> &str {
        "Test Math"
    }
    fn description(&self) -> &str {
        "Fixture: calculator tools."
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![
            Box::new(FixtureTool("add")),
            Box::new(FixtureTool("subtract")),
            Box::new(FixtureTool("multiply")),
            Box::new(FixtureTool("divide")),
        ]
    }
}

/// Contributes two plain tools.
pub(crate) struct WeatherFixture;

impl Capability for WeatherFixture {
    fn id(&self) -> &str {
        "test_weather"
    }
    fn name(&self) -> &str {
        "Test Weather"
    }
    fn description(&self) -> &str {
        "Fixture: weather tools."
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        vec![
            Box::new(FixtureTool("get_weather")),
            Box::new(FixtureTool("get_forecast")),
        ]
    }
}

/// Carries a read-only mount, a prompt addition, a feature, and a
/// dependency on `session_file_system`.
pub(crate) struct SampleDataFixture;

impl Capability for SampleDataFixture {
    fn id(&self) -> &str {
        "sample_data"
    }
    fn name(&self) -> &str {
        "Sample Data"
    }
    fn description(&self) -> &str {
        "Fixture: mounted sample files."
    }
    fn system_prompt_addition(&self) -> Option<&str> {
        Some("Read-only sample files are mounted at `/samples`.")
    }
    fn mounts(&self) -> Vec<MountPoint> {
        let samples_dir = MountDirectoryBuilder::new()
            .file("users.json", "[]")
            .build();
        vec![MountPoint::readonly("/samples", samples_dir, self.id())]
    }
    fn dependencies(&self) -> Vec<&'static str> {
        vec!["session_file_system"]
    }
    fn features(&self) -> Vec<&'static str> {
        vec!["file_system"]
    }
}

/// Registry of local contribution fixtures.
pub(crate) fn fixture_registry() -> CapabilityRegistry {
    let mut registry = CapabilityRegistry::new();
    registry.register(NoopFixture);
    registry.register(FeatureFixture);
    registry.register(MathFixture);
    registry.register(WeatherFixture);
    registry.register(SampleDataFixture);
    registry.register(FileSystemFixture);
    registry.register(StorageFixture);
    registry.register(BashFixture);
    registry.register(WebFetchFixture);
    registry.register(DynamicFactFixture);
    registry.register(PromptToolFixture);
    registry.register(SecondPromptFixture);
    registry.register(DynamicPreviewFixture);
    registry
}

/// A host-defined capability carrying annotations core knows nothing about.
pub(crate) struct HostAnnotatedCapability;

#[async_trait]
impl Capability for HostAnnotatedCapability {
    fn id(&self) -> &str {
        "host_annotated"
    }
    fn name(&self) -> &str {
        "Host Annotated"
    }
    fn description(&self) -> &str {
        "Test capability with host-owned metadata."
    }
    fn metadata(&self) -> Option<serde_json::Value> {
        Some(serde_json::json!({"icon": "sparkles", "group": "host"}))
    }
}

pub(crate) fn blueprint_with_schema(config_schema: Option<serde_json::Value>) -> AgentBlueprint {
    AgentBlueprint {
        id: "test_blueprint",
        name: "Test Blueprint",
        description: "Blueprint for config validation tests",
        model: BlueprintModel::Inherit,
        system_prompt: "Test prompt",
        tools: vec![],
        max_turns: None,
        config_schema,
    }
}

/// Test capability that provides a message filter
pub(crate) struct FilterTestCapability {
    pub(crate) priority: i32,
}

impl Capability for FilterTestCapability {
    fn id(&self) -> &str {
        "filter_test"
    }
    fn name(&self) -> &str {
        "Filter Test"
    }
    fn description(&self) -> &str {
        "Test capability with message filter"
    }
    fn message_filter_provider(&self) -> Option<Arc<dyn MessageFilterProvider>> {
        Some(Arc::new(FilterTestProvider {
            priority: self.priority,
        }))
    }
}

pub(crate) struct FilterTestProvider {
    pub(crate) priority: i32,
}

impl MessageFilterProvider for FilterTestProvider {
    fn apply_filters(&self, query: &mut MessageQuery, config: &serde_json::Value) {
        // Add a search filter based on config
        if let Some(search) = config.get("search").and_then(|v| v.as_str()) {
            query
                .filters
                .push(MessageFilter::Search(search.to_string()));
        }
    }

    fn priority(&self) -> i32 {
        self.priority
    }
}

pub(crate) struct DelegatingFilterCap {
    pub(crate) id: &'static str,
    pub(crate) inner: std::sync::Arc<InnerFilterCap>,
}
pub(crate) struct InnerFilterCap;

impl Capability for InnerFilterCap {
    fn id(&self) -> &str {
        "inner_filter"
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        panic!("fast-path collection must not instantiate tools")
    }
    fn system_prompt_addition(&self) -> Option<&str> {
        panic!("fast-path collection must not collect prompts")
    }
    fn name(&self) -> &str {
        "Inner Filter"
    }
    fn description(&self) -> &str {
        "inner"
    }
    fn message_filter_provider(&self) -> Option<std::sync::Arc<dyn MessageFilterProvider>> {
        Some(std::sync::Arc::new(SentinelFilter))
    }
}
pub(crate) struct SentinelFilter;
impl MessageFilterProvider for SentinelFilter {
    fn apply_filters(&self, query: &mut MessageQuery, config: &serde_json::Value) {
        query.limit = config["limit"].as_i64();
    }
}
impl Capability for DelegatingFilterCap {
    fn id(&self) -> &str {
        self.id
    }
    fn name(&self) -> &str {
        "Delegating Filter"
    }
    fn description(&self) -> &str {
        "delegating"
    }
    fn message_filter_provider(&self) -> Option<std::sync::Arc<dyn MessageFilterProvider>> {
        None // outer provides nothing
    }
    fn resolve_for_model(&self, _model: Option<&str>) -> Option<&dyn Capability> {
        Some(&*self.inner)
    }
}

pub(crate) struct DelegatingMvpCap {
    pub(crate) id: &'static str,
    pub(crate) inner: std::sync::Arc<InnerMvpCap>,
}
pub(crate) struct InnerMvpCap;

impl Capability for InnerMvpCap {
    fn id(&self) -> &str {
        "inner_mvp"
    }
    fn tools(&self) -> Vec<Box<dyn Tool>> {
        panic!("fast-path collection must not instantiate tools")
    }
    fn system_prompt_addition(&self) -> Option<&str> {
        panic!("fast-path collection must not collect prompts")
    }
    fn name(&self) -> &str {
        "Inner MVP"
    }
    fn description(&self) -> &str {
        "inner"
    }
    fn model_view_provider(
        &self,
    ) -> Option<std::sync::Arc<dyn crate::capabilities::ModelViewProvider>> {
        // Retain the input and expose the forwarded config and context.
        struct AppendingMvp;
        impl crate::capabilities::ModelViewProvider for AppendingMvp {
            fn apply_model_view(
                &self,
                mut messages: Vec<Message>,
                config: &serde_json::Value,
                context: &ModelViewContext<'_>,
            ) -> Vec<Message> {
                messages.push(Message::user(format!(
                    "{}:{}",
                    config["suffix"].as_str().unwrap(),
                    context.session_id
                )));
                messages
            }
        }
        Some(std::sync::Arc::new(AppendingMvp))
    }
}
impl Capability for DelegatingMvpCap {
    fn id(&self) -> &str {
        self.id
    }
    fn name(&self) -> &str {
        "Delegating MVP"
    }
    fn description(&self) -> &str {
        "delegating"
    }
    fn model_view_provider(
        &self,
    ) -> Option<std::sync::Arc<dyn crate::capabilities::ModelViewProvider>> {
        None // outer provides nothing
    }
    fn resolve_for_model(&self, model: Option<&str>) -> Option<&dyn Capability> {
        (model == Some("selected-model")).then_some(&*self.inner as &dyn Capability)
    }
}

pub(crate) struct SkillContributingCapability;

impl Capability for SkillContributingCapability {
    fn id(&self) -> &str {
        "contributes_skills"
    }
    fn name(&self) -> &str {
        "Contributes Skills"
    }
    fn description(&self) -> &str {
        "Test capability that contributes skills."
    }
    fn contribute_skills(&self) -> Vec<SkillContribution> {
        vec![
            SkillContribution::new("alpha-skill", "Alpha skill desc", "# Alpha\nDo alpha.")
                .with_files(vec![(
                    "scripts/a.sh".to_string(),
                    "#!/bin/sh\necho a\n".to_string(),
                )]),
            SkillContribution::new("beta-skill", "Beta skill desc", "# Beta\nDo beta.")
                .with_user_invocable(false),
        ]
    }
}

pub(crate) fn skill_md_from_entries(entries: &HashMap<String, MountEntry>) -> &str {
    match &entries.get("SKILL.md").expect("SKILL.md missing").source {
        MountSource::InlineFile { content, .. } => content.as_str(),
        _ => panic!("Expected InlineFile for SKILL.md"),
    }
}

pub(crate) struct LocalizedCapability;

impl Capability for LocalizedCapability {
    fn id(&self) -> &str {
        "localized"
    }
    fn name(&self) -> &str {
        "Localized"
    }
    fn description(&self) -> &str {
        "English description"
    }
    fn localizations(&self) -> Vec<CapabilityLocalization> {
        vec![
            CapabilityLocalization {
                locale: "en",
                name: None,
                description: None,
                config_description: Some("Controls things."),
                config_overlay: None,
            },
            CapabilityLocalization {
                locale: "uk-UA",
                name: Some("Регіональна"),
                description: None,
                config_description: None,
                config_overlay: None,
            },
            CapabilityLocalization {
                locale: "uk",
                name: Some("Локалізована"),
                description: Some("Український опис"),
                config_description: Some("Керує налаштуваннями."),
                config_overlay: None,
            },
        ]
    }
}

pub(crate) struct DependencyFixture {
    pub(crate) id: String,
    pub(crate) deps: Vec<&'static str>,
    pub(crate) features: Vec<&'static str>,
}
impl Capability for DependencyFixture {
    fn id(&self) -> &str {
        &self.id
    }
    fn name(&self) -> &str {
        &self.id
    }
    fn description(&self) -> &str {
        "Dependency fixture"
    }
    fn dependencies(&self) -> Vec<&'static str> {
        self.deps.clone()
    }
    fn features(&self) -> Vec<&'static str> {
        self.features.clone()
    }
}