algocline_core/execution/spec.rs
1//! Session specification types for the `ExecutionService` layer.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value as JsonValue;
5use std::path::PathBuf;
6
7/// Complete specification required to spawn a new execution session.
8///
9/// `SessionSpec` is a pure value type passed to [`crate::execution::ExecutionService::spawn`].
10/// It carries no runtime handles and is safe to clone and serialize.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct SessionSpec {
13 /// The kind of execution to perform.
14 pub kind: SpecKind,
15 /// Optional project root directory. When `None`, the engine chooses a default.
16 pub project_root: Option<PathBuf>,
17 /// Arbitrary JSON context forwarded to the execution environment.
18 pub ctx: Option<JsonValue>,
19}
20
21/// Discriminant for the execution kind carried by [`SessionSpec`].
22///
23/// Each variant corresponds to one of the primary operations the engine can perform.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(tag = "kind", rename_all = "snake_case")]
26pub enum SpecKind {
27 /// Execute a Lua code snippet directly.
28 Run {
29 /// Lua source code to execute.
30 code: String,
31 },
32 /// Apply an advice package strategy to an optional task.
33 Advice {
34 /// Name of the strategy package to apply.
35 strategy: String,
36 /// Optional task description passed as context.
37 task: Option<String>,
38 /// Additional JSON options for the strategy.
39 opts: Option<JsonValue>,
40 },
41 /// Evaluate a scenario against a strategy.
42 Eval {
43 /// Reference to the scenario to evaluate.
44 scenario: ScenarioRef,
45 /// Name of the strategy to evaluate.
46 strategy: String,
47 /// Optional JSON options for the evaluation.
48 opts: Option<JsonValue>,
49 /// Whether to automatically create a card from the evaluation result.
50 auto_card: bool,
51 },
52}
53
54/// Reference to a scenario used in [`SpecKind::Eval`].
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(tag = "ref_kind", rename_all = "snake_case")]
57pub enum ScenarioRef {
58 /// Inline scenario content as a string.
59 Inline(String),
60 /// Name of an installed scenario (looked up from `~/.algocline/scenarios/`).
61 Name(String),
62 /// Path to a scenario file on the local file system.
63 File(PathBuf),
64}