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
//! The `Runtime` trait and its surrounding value types.
//!
//! Every backend (toy Lisp today, wasmtime-hosted interpreters
//! tomorrow) implements [`Runtime`]. The trait is *deliberately tiny* —
//! a single `execute(source, ctx) -> result` — so that we can swap
//! implementations later without dragging UI code along.
use PathBuf;
use Duration;
use Error;
/// A language backend.
///
/// The contract is intentionally Unix-y: take a `source` string, return
/// stdout / stderr / exit-status / duration. Errors bubble up through
/// [`ExecError`].
///
/// Implementations **must** honour `ctx.timeout`. If your runtime can't
/// be cancelled cooperatively, wrap the work in
/// [`crate::sandbox::with_timeout`] which spawns the work on a separate
/// thread and drops the channel on overrun.
/// Context passed to every execution.
///
/// We deliberately keep this small. Anything runtime-specific (env vars,
/// preopened directories, sandbox tweaks) lives inside the runtime
/// itself.
/// What an execution produced.
/// How a run terminated.
/// How the orchestrator should render [`ExecOutput`] into a result
/// subblock.
///
/// `Text` (the default) feeds `stdout` through
/// [`render_result_body`](crate::result_block::render_result_body),
/// producing the classic `> **result:** …` single child.
///
/// `Embeds` tells the orchestrator to split `stdout` into one embed
/// reference per line and render each as a child bullet, so the result
/// block becomes a **live view** of the referenced blocks. Used by
/// the `query` runtime: results are `!((blk-XXXXXX))` references, not
/// copies, so toggling a TODO on the original block is reflected
/// everywhere it appears.
/// Infrastructure-level errors.
///
/// User-script errors (a Lisp `(error ...)` form, a Python exception)
/// surface as `Ok(ExecOutput { exit: NonZero | Trap, .. })`. This enum
/// is reserved for "your sandbox didn't even get to run the code".