Skip to main content

hm_plugin_protocol/
host_abi.rs

1//! Wire types used as host-function arguments and return values.
2//! Plugins import these to talk to the hm host fns; the host imports
3//! them to expose those fns.
4
5use std::collections::BTreeMap;
6
7use schemars::JsonSchema as DeriveJsonSchema;
8use serde::{Deserialize, Serialize};
9
10use crate::executor::ArchiveId;
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
13#[serde(rename_all = "snake_case")]
14pub enum Level {
15    Trace,
16    Debug,
17    Info,
18    Warn,
19    Error,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
23#[serde(rename_all = "snake_case")]
24pub enum KvScope {
25    /// Per-plugin, persistent across builds. Stored in
26    /// `~/.config/harmont/state/<plugin-name>.kv`.
27    Plugin,
28    /// Per-build, in memory. Lost when the build ends.
29    Build,
30    /// Per-step, in memory. Lost when the step ends.
31    Step,
32}
33
34/// Opaque socket handle returned by `hm_unix_socket_connect`. Bound
35/// to the plugin instance that opened it.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)]
37#[serde(transparent)]
38pub struct SocketHandle(pub u64);
39
40/// Opaque handle returned by `hm_spawn_loopback`. Bound to the plugin
41/// instance.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)]
43#[serde(transparent)]
44pub struct LoopbackHandle(pub u64);
45
46/// Host-fn argument struct for the corresponding `hm_archive_read` host function.
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48pub struct ArchiveReadArgs {
49    pub id: ArchiveId,
50    pub offset: u64,
51    pub max: u64,
52}
53
54/// Host-fn argument struct for the corresponding `hm_loopback_recv` host function.
55#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct CallbackData {
57    pub path: String,
58    pub query: BTreeMap<String, String>,
59}
60
61/// Host-fn argument struct for the corresponding `hm_keyring_get` / `hm_keyring_delete` host function.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct KeyringArgs {
64    pub service: String,
65    pub account: String,
66}
67
68/// Host-fn argument struct for the corresponding `hm_keyring_set` host function.
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70pub struct KeyringSetArgs {
71    pub service: String,
72    pub account: String,
73    pub secret: String,
74}
75
76/// Host-fn argument struct for the corresponding `hm_loopback_recv` host function.
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
78pub struct LoopbackRecvArgs {
79    pub h: LoopbackHandle,
80    pub timeout_ms: u32,
81}
82
83/// Host-fn argument struct for the corresponding `hm_socket_read` host function.
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85pub struct SocketReadArgs {
86    pub h: SocketHandle,
87    pub max: u64,
88}
89
90/// Host-fn argument struct for the corresponding `hm_socket_write` host function.
91#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
92pub struct SocketWriteArgs {
93    pub h: SocketHandle,
94    pub bytes: Vec<u8>,
95}
96
97/// Host-fn argument struct for the corresponding `hm_tty_confirm` host function.
98#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
99pub struct TtyConfirmArgs {
100    pub msg: String,
101    pub default: bool,
102}
103
104/// Host-fn argument struct for the corresponding `hm_tty_prompt` host function.
105#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
106pub struct TtyPromptArgs {
107    pub msg: String,
108    pub mask: bool,
109}
110
111/// Host-fn argument struct for `hm_docker_start_container`.
112#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
113pub struct DockerStartArgs {
114    pub image: String,
115    pub env: std::collections::BTreeMap<String, String>,
116    pub workdir: String,
117    pub name_hint: String,
118}
119
120/// Host-fn argument struct for `hm_docker_exec`.
121#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
122pub struct DockerExecArgs {
123    pub container_id: String,
124    pub cmd: Vec<String>,
125    pub env: std::collections::BTreeMap<String, String>,
126    pub workdir: String,
127    /// When `Some`, piped into the exec'd process's stdin (closed after
128    /// the write so the process sees EOF). Used for tar-extract.
129    pub stdin_archive_id: Option<crate::ArchiveId>,
130}
131
132/// Host-fn argument struct for `hm_docker_commit`.
133#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
134pub struct DockerCommitArgs {
135    pub container_id: String,
136    pub tag: String,
137}
138
139/// Host-fn argument struct for `hm_docker_extract_workspace`.
140#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
141pub struct DockerExtractArgs {
142    pub container_id: String,
143    pub archive_id: crate::ArchiveId,
144    pub workdir: String,
145}