Skip to main content

ag_session/
task_role.rs

1//! Host-enforced stages of the plan-and-implement workflow.
2
3use crate::PermissionMode;
4
5/// Built-in role contracts for a planner-to-implementer workflow.
6///
7/// These definitions do not dispatch work, select a model, or change ordinary
8/// session turns. A workflow may use the same session Smart
9/// [`crate::AgentSelection`] for both roles. Assignments, isolated
10/// conversations, and result handoff must be supplied by the workflow before
11/// these contracts can govern execution.
12#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
13pub enum TaskAgentRole {
14    /// Inspects the workspace and proposes a plan without making changes.
15    Planner,
16    /// Implements an explicitly accepted plan within session permissions.
17    Implementer,
18}
19
20impl TaskAgentRole {
21    /// Stable role identity, separate from provider kind or agent ID.
22    pub fn id(self) -> &'static str {
23        match self {
24            Self::Planner => "planner",
25            Self::Implementer => "implementer",
26        }
27    }
28
29    /// Resolves a stable role identity produced by [`Self::id`].
30    pub fn from_id(id: &str) -> Option<Self> {
31        match id {
32            "planner" => Some(Self::Planner),
33            "implementer" => Some(Self::Implementer),
34            _ => None,
35        }
36    }
37
38    /// Human-readable role name for transcripts and status displays.
39    pub fn display_name(self) -> &'static str {
40        match self {
41            Self::Planner => "Planner",
42            Self::Implementer => "Implementer",
43        }
44    }
45
46    /// Restricts session permissions for this role without granting new access.
47    ///
48    /// Callers must pass this mode through worker/runtime permission
49    /// enforcement; resolving a value alone does not sandbox a run. Worker
50    /// execution policy remains an independent restriction. Implementers
51    /// retain the host permission ceiling unchanged.
52    pub fn permission_mode(self, session_permission_mode: PermissionMode) -> PermissionMode {
53        match self {
54            Self::Planner => PermissionMode::ReadOnly,
55            Self::Implementer => session_permission_mode,
56        }
57    }
58}
59
60#[cfg(test)]
61#[path = "task_role_test.rs"]
62mod tests;