Skip to main content

ao_core/
parity_session_strategy.rs

1//! Orchestrator session-strategy enums and helpers
2//! (ported from `packages/core/src/orchestrator-session-strategy.ts`).
3//!
4//! Parity status: mixed.
5//!
6//! The two enums (`OrchestratorSessionStrategy`, `OpencodeIssueSessionStrategy`)
7//! are re-exported from `ao_core` and used by production config
8//! (`crates/ao-core/src/config.rs`). The helper
9//! `decide_existing_session_action` is test-only — the runtime lifecycle has
10//! its own strategy logic and does not call it. See
11//! `docs/ts-core-parity-report.md` → "Parity-only modules".
12
13use serde::{Deserialize, Serialize};
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(rename_all = "kebab-case")]
17pub enum OrchestratorSessionStrategy {
18    Reuse,
19    Delete,
20    Ignore,
21    DeleteNew,
22    IgnoreNew,
23    KillPrevious,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
27#[serde(rename_all = "kebab-case")]
28pub enum OpencodeIssueSessionStrategy {
29    Reuse,
30    Delete,
31    Ignore,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum ExistingSessionAction {
36    ReuseExisting,
37    DeleteExistingAndReuseName,
38    IgnoreExistingAndSpawnNew,
39    Abort,
40}
41
42/// Minimal parity port of TS orchestrator-session-strategy behavior.
43///
44/// This is currently used only by parity tests; the ao-rs runtime has its own
45/// session lifecycle implementation.
46pub fn decide_existing_session_action(
47    strategy: OrchestratorSessionStrategy,
48    existing_found: bool,
49) -> ExistingSessionAction {
50    if !existing_found {
51        return ExistingSessionAction::IgnoreExistingAndSpawnNew;
52    }
53    match strategy {
54        OrchestratorSessionStrategy::Reuse => ExistingSessionAction::ReuseExisting,
55        OrchestratorSessionStrategy::Delete => ExistingSessionAction::DeleteExistingAndReuseName,
56        OrchestratorSessionStrategy::Ignore => ExistingSessionAction::Abort,
57        OrchestratorSessionStrategy::DeleteNew => ExistingSessionAction::Abort,
58        OrchestratorSessionStrategy::IgnoreNew => ExistingSessionAction::Abort,
59        OrchestratorSessionStrategy::KillPrevious => {
60            ExistingSessionAction::DeleteExistingAndReuseName
61        }
62    }
63}