Skip to main content

supercode_interchange/orchestration/
worker.rs

1//! The worker: which harness runs a profile's conversations, and how (§2.2).
2
3use std::collections::BTreeMap;
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8use crate::ontology::{HarnessId, SecretRef};
9
10/// A worker environment value: a literal, or a secret by reference.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
12#[serde(untagged)]
13pub enum EnvValue {
14    /// A plain, non-secret value.
15    Literal(String),
16    /// A secret, named and never held.
17    Secret(SecretRef),
18}
19
20/// What happens to a worker's permission prompt when no human answers.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
22#[serde(rename_all = "snake_case")]
23pub enum PermissionDefault {
24    /// Refuse after the timeout.
25    #[default]
26    Deny,
27    /// Allow after the timeout.
28    Allow,
29}
30
31/// How prompts are answered when no human is reachable (§4.6).
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
33pub struct PermissionPolicy {
34    /// Seconds a relayed prompt waits for an answer.
35    #[serde(default = "default_permission_timeout")]
36    pub timeout_seconds: u32,
37    /// The answer given when nobody replies in time.
38    #[serde(default)]
39    pub default: PermissionDefault,
40}
41
42fn default_permission_timeout() -> u32 {
43    300
44}
45
46impl Default for PermissionPolicy {
47    fn default() -> Self {
48        Self {
49            timeout_seconds: 300,
50            default: PermissionDefault::Deny,
51        }
52    }
53}
54
55/// The worker specification (O-record; Hermes has no worker choice).
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
57pub struct WorkerSpec {
58    /// Any registry id whose runtime can start a session.
59    pub harness: HarnessId,
60    /// Model, where the harness's door accepts one.
61    #[serde(default)]
62    pub model: Option<String>,
63    /// supercode preset name.
64    #[serde(default)]
65    pub preset: Option<String>,
66    /// Relative to the profile dir; `.` by default.
67    #[serde(default = "default_cwd")]
68    pub cwd: String,
69    /// Extra environment for the worker process; secrets by reference.
70    #[serde(default)]
71    pub env: BTreeMap<String, EnvValue>,
72    /// Permission prompt policy.
73    #[serde(default)]
74    pub permission: PermissionPolicy,
75}
76
77fn default_cwd() -> String {
78    ".".to_string()
79}