rightcommit 1.3.0

Self-hosted, Rust-built orchestration for Claude Code, Codex and Pi Agent. Parallel workflows, full control over every commit, and FinOps that shows exactly what each agent and model costs.
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

pub fn id() -> String {
    uuid::Uuid::new_v4().to_string()
}
pub fn now() -> i64 {
    std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap_or_default()
        .as_secs() as i64
}
pub fn default_runtime() -> String {
    "codex".into()
}

pub const NODE_KINDS: &[&str] = &[
    "Source",
    "Agent",
    "Task",
    "Fork",
    "Join",
    "Review",
    "Gate",
    "Memory",
    "Connection",
    "Workflow",
    "MCP",
    "RAG",
    "Comment",
    "A2A",
];

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct Node {
    pub id: String,
    pub kind: String,
    pub text: String,
    pub width: f64,
    pub height: f64,
    pub markdown: bool,
    pub title: String,
    pub x: f64,
    pub y: f64,
    pub phase: String,
    pub prompt: String,
    pub command: String,
    pub skip: bool,
    pub agent: String,
    pub runtime: String,
    pub model: String,
    pub pi_provider: String,
    pub pi_base_url: String,
    pub mode: String,
    pub location: String,
    pub source_type: String,
    pub source_mode: String,
    pub target: String,
    pub workflow_id: String,
    pub rag_index: String,
    pub rag_mode: String,
    pub rag_top_k: usize,
    pub a2a_id: String,
    pub mcp_id: String,
    pub mcp_tools: Vec<String>,
    pub provider: String,
    pub organization: String,
    pub project: String,
    pub repository: String,
    pub operation: String,
    pub api_endpoint: String,
    pub api_method: String,
    pub api_path: String,
    pub api_parameters: String,
    pub api_query: String,
    pub api_headers: String,
    pub api_body: String,
    pub api_encoding: String,
    pub outcomes: Vec<String>,
    pub require_tests: bool,
    pub require_tasks_closed: bool,
    pub max_rework: u32,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Edge {
    pub from: String,
    pub to: String,
    pub kind: String,
    #[serde(default)]
    pub outcome: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ExecutionMode {
    #[default]
    Interactive,
    Assisted,
    Unattended,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct ExecutionPolicy {
    pub mode: ExecutionMode,
    pub runtime: String,
    pub model: String,
    pub instructions: String,
    pub max_decisions: u32,
    pub max_per_node: u32,
    pub allow_external_writes: bool,
}
impl Default for ExecutionPolicy {
    fn default() -> Self {
        Self {
            mode: ExecutionMode::Interactive,
            runtime: String::new(),
            model: String::new(),
            instructions: String::new(),
            max_decisions: 50,
            max_per_node: 5,
            allow_external_writes: false,
        }
    }
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SupervisorProposal {
    pub action: String,
    pub answer: String,
    pub rationale: String,
    pub session: String,
    pub turn: u32,
    pub created: i64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Workflow {
    #[serde(default)]
    pub execution: ExecutionPolicy,
    #[serde(default)]
    pub created: i64,
    pub id: String,
    pub name: String,
    pub description: String,
    pub entry: String,
    pub nodes: Vec<Node>,
    pub edges: Vec<Edge>,
}
impl Workflow {
    pub fn node(&self, id: &str) -> anyhow::Result<&Node> {
        self.nodes
            .iter()
            .find(|n| n.id == id)
            .ok_or_else(|| anyhow::anyhow!("Nodo inesistente: {id}"))
    }
    pub fn next(&self, id: &str, outcome: &str) -> Option<&Edge> {
        self.edges.iter().find(|e| {
            e.from == id && (e.kind == "control" || e.kind == "rework") && e.outcome == outcome
        })
    }
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct AgentConfig {
    pub multi_provider: bool,
    pub base_url: String,
    pub model: String,
    pub effort: String,
    pub api_key: String,
    pub provider: String,
    /// Pi only: declare the built-in `codemode` tool in Task turns.
    pub codemode: bool,
}
impl Default for AgentConfig {
    fn default() -> Self {
        Self {
            multi_provider: false,
            base_url: String::new(),
            model: String::new(),
            effort: "low".into(),
            api_key: String::new(),
            provider: "anthropic".into(),
            codemode: false,
        }
    }
}
/// Zero uses the native model/provider default, except Pi's explicit token budgets.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct CompactionConfig {
    pub context_window_tokens: u64,
    pub threshold_tokens: u64,
    pub trigger_percent: u8,
    pub reserve_tokens: u64,
    pub keep_recent_tokens: u64,
}
impl Default for CompactionConfig {
    fn default() -> Self {
        Self {
            context_window_tokens: 0,
            threshold_tokens: 0,
            trigger_percent: 0,
            reserve_tokens: 16384,
            keep_recent_tokens: 20000,
        }
    }
}
impl CompactionConfig {
    pub fn for_runtime(runtime: &str) -> Self {
        if runtime == "claude" {
            Self {
                trigger_percent: 80,
                ..Self::default()
            }
        } else {
            Self::default()
        }
    }
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
    pub manager_write_enabled: bool,
    pub default_runtime: String,
    pub agents: BTreeMap<String, AgentConfig>,
    pub connections: BTreeMap<String, ConnectionConfig>,
    pub mcp_servers: BTreeMap<String, McpConfig>,
    pub task_timeout_secs: u64,
    pub source_copy_limit_mib: u64,
    pub file_preview_limit_mb: u64,
    pub workflow_parallelism: usize,
    pub activity_log_verbosity: String,
    pub activity_log_page_size: usize,
    pub compaction: BTreeMap<String, CompactionConfig>,
}
impl Default for Settings {
    fn default() -> Self {
        Self {
            manager_write_enabled: true,
            default_runtime: default_runtime(),
            agents: ["codex", "claude", "pi"]
                .into_iter()
                .map(|x| (x.into(), AgentConfig::default()))
                .collect(),
            connections: BTreeMap::new(),
            mcp_servers: BTreeMap::new(),
            task_timeout_secs: 7200,
            source_copy_limit_mib: 10,
            file_preview_limit_mb: 5,
            workflow_parallelism: 5,
            activity_log_verbosity: "preview".into(),
            activity_log_page_size: 10,
            compaction: ["claude", "codex", "pi"]
                .into_iter()
                .map(|rt| (rt.into(), CompactionConfig::for_runtime(rt)))
                .collect(),
        }
    }
}
impl Settings {
    pub fn file_preview_limit_bytes(&self) -> anyhow::Result<u64> {
        anyhow::ensure!((1..=100).contains(&self.file_preview_limit_mb), "Limite anteprima file: inserisci un valore da 1 a 100 MB");
        Ok(self.file_preview_limit_mb * 1_000_000)
    }
    pub fn source_copy_limit_bytes(&self) -> anyhow::Result<u64> {
        anyhow::ensure!(
            self.source_copy_limit_mib > 0,
            "Il limite copia sorgenti deve essere almeno 1 MiB"
        );
        self.source_copy_limit_mib
            .checked_mul(1024 * 1024)
            .ok_or_else(|| anyhow::anyhow!("Limite copia sorgenti troppo grande"))
    }
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct ConnectionConfig {
    pub authentication: String,
    pub client_id: String,
    pub client_secret: String,
    pub oauth_scope: String,
    pub username: String,
    pub password: String,
    pub catalog_item: String,
    pub catalog_variables: String,
    pub base_url: String,
    pub token: String,
    pub project: String,
    pub repository: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct NativeSession {
    #[serde(default)]
    pub provider: String,
    #[serde(default)]
    pub base_url: String,
    pub runtime: String,
    pub native_id: String,
    pub turns: u32,
    pub model: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Pending {
    #[serde(default)]
    pub id: String,
    #[serde(default)]
    pub proposal: Option<SupervisorProposal>,
    pub kind: String,
    pub node: String,
    pub questions: Vec<String>,
    pub resume_task: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct AgentResult {
    pub status: String,
    pub summary: String,
    pub questions: Vec<String>,
    pub artifacts: Vec<String>,
    pub decision: String,
    pub details: String,
    #[serde(skip_serializing_if = "std::ops::Not::not")]
    pub details_truncated: bool,
}
impl AgentResult {
    pub fn report(&self) -> String {
        if self.details.is_empty() {
            self.summary.clone()
        } else {
            format!("{}\n\n{}", self.summary, self.details)
        }
    }
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Run {
    #[serde(default)]
    pub execution: ExecutionPolicy,
    #[serde(default)]
    pub parent: Option<ParentRun>,
    #[serde(default)]
    pub children: Vec<ChildRun>,
    pub id: String,
    pub workflow: Workflow,
    pub status: String,
    pub current: String,
    pub created: i64,
    pub updated: i64,
    pub workspace: String,
    pub states: BTreeMap<String, String>,
    pub sessions: BTreeMap<String, NativeSession>,
    pub outputs: BTreeMap<String, AgentResult>,
    pub pending: Option<Pending>,
    pub active_edge: Option<Edge>,
    pub pause_requested: bool,
    pub attempts: BTreeMap<String, u32>,
    pub reworks: BTreeMap<String, u32>,
    pub context: BTreeMap<String, String>,
    pub last_task: Option<String>,
    pub last_node: Option<String>,
    pub error: Option<String>,
    pub input: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ParentRun {
    pub run: String,
    pub node: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChildRun {
    pub run: String,
    pub node: String,
    pub attempt: u32,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Artifact {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file: Option<ArtifactFile>,
    pub id: String,
    pub run: String,
    pub node: String,
    pub path: String,
    pub version: u32,
    pub hash: String,
    pub content: String,
    pub session: String,
    pub turn: u32,
    pub created: i64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ArtifactFile {
    #[serde(default)]
    pub modified: u64,
    pub root: String,
    pub location: String,
    pub change: String,
    pub size: u64,
    pub preview: bool,
    pub blob: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Decision {
    #[serde(default)]
    pub actor: String,
    #[serde(default)]
    pub supervisor: Option<SupervisorProposal>,
    pub id: String,
    pub run: String,
    pub node: String,
    pub decision: String,
    pub answer: String,
    pub user: String,
    pub created: i64,
    pub artifacts: Vec<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Event {
    pub seq: i64,
    pub run: String,
    pub kind: String,
    pub node: String,
    pub text: String,
    pub created: i64,
}
#[derive(Clone, Debug)]
pub struct User {
    pub id: i64,
    pub email: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct McpConfig {
    pub name: String,
    pub transport: String,
    pub url: String,
    pub command: String,
    pub args: Vec<String>,
    pub env: BTreeMap<String, String>,
    pub headers: BTreeMap<String, String>,
    pub timeout_secs: u64,
    pub auth: McpAuth,
}
impl Default for McpConfig {
    fn default() -> Self {
        Self {
            name: String::new(),
            transport: "http".into(),
            url: String::new(),
            command: String::new(),
            args: vec![],
            env: BTreeMap::new(),
            headers: BTreeMap::new(),
            timeout_secs: 60,
            auth: McpAuth::default(),
        }
    }
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct McpAuth {
    pub mode: String,
    pub token: String,
    pub header: String,
    pub username: String,
    pub password: String,
    pub issuer: String,
    pub authorization_url: String,
    pub token_url: String,
    pub client_id: String,
    pub client_secret: String,
    pub token_auth: String,
    pub scope: String,
    pub access_token: String,
    pub refresh_token: String,
    pub expires: i64,
}
impl Default for McpAuth {
    fn default() -> Self {
        Self {
            mode: "none".into(),
            token: String::new(),
            header: "X-API-Key".into(),
            username: String::new(),
            password: String::new(),
            issuer: String::new(),
            authorization_url: String::new(),
            token_url: String::new(),
            client_id: String::new(),
            client_secret: String::new(),
            token_auth: "none".into(),
            scope: String::new(),
            access_token: String::new(),
            refresh_token: String::new(),
            expires: 0,
        }
    }
}