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
//! The hook runtime: the Lua file every hook command runs through.
//!
//! # Responsibilities
//!
//! - [`RUNTIME_FILE`]: the runtime's file name under the extension root.
//! - [`RUNTIME_LUA`]: the runtime's text, compiled into the library.
/// The runtime's file name under the extension root.
pub const RUNTIME_FILE: &str = "runtime.lua";
/// The text of the hook runtime, as written to `<root>/runtime.lua`.
///
/// The runtime loads the extension's `translate` module and reads the hook module's name, the
/// `may_block` flag and the hook's kind from the command line's first three arguments; the rest are
/// the hook's own, which every event the hook runs on carries as `args`. For a neutral hook the
/// translator's `event` turns the payload the tool sends into one neutral event or a list of them;
/// when it returns nothing the runtime exits without running the hook or printing anything. For a
/// native hook the event is the raw payload, with `args` added. The hook module runs once per event. A `block`
/// from a hook not declared `may_block` is dropped, with one line on standard error, in either kind
/// and for each event of a list. A list of events runs in order until one event's result carries a
/// `block`, which is kept and ends the run; the `context` strings of the events run so far, that
/// one's included, are joined with a newline. The translator's `result` is then called with the
/// hook's result and the raw payload, for neutral and native hooks alike, and whatever text it
/// returns is printed.
///
/// # Examples
///
/// ```
/// use agentstacks::types::protocol::RUNTIME_LUA;
///
/// assert!(RUNTIME_LUA.starts_with("-- agentstacks hook runtime"));
/// ```
pub const RUNTIME_LUA: &str = include_str!;