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 /// Explicit inputs required in the role's own conversation context.
47 pub fn context_requirement(self) -> AgentContextRequirement {
48 match self {
49 Self::Planner => AgentContextRequirement::UserRequest,
50 Self::Implementer => AgentContextRequirement::UserRequestAndAcceptedPlan,
51 }
52 }
53
54 /// Expected answer content, using the existing response protocol.
55 pub fn output_kind(self) -> AgentOutputKind {
56 match self {
57 Self::Planner => AgentOutputKind::Plan,
58 Self::Implementer => AgentOutputKind::ImplementationReport,
59 }
60 }
61
62 /// Restricts session permissions for this role without granting new access.
63 ///
64 /// Callers must pass this mode through worker/runtime permission
65 /// enforcement; resolving a value alone does not sandbox a run. Worker
66 /// execution policy remains an independent restriction. Implementers
67 /// retain read-only sessions and the session's existing
68 /// auto-address-comments behavior unchanged.
69 pub fn permission_mode(self, session_permission_mode: PermissionMode) -> PermissionMode {
70 match self {
71 Self::Planner => PermissionMode::ReadOnly,
72 Self::Implementer => session_permission_mode,
73 }
74 }
75}
76
77/// Inputs a workflow must explicitly supply, in addition to workspace access.
78///
79/// Each role requires its own conversation; another role's provider
80/// conversation must not be implicitly reused. These requirements describe the
81/// contract, not a context builder. They neither copy the session transcript
82/// nor grant access.
83#[derive(Clone, Copy, Debug, Eq, PartialEq)]
84pub enum AgentContextRequirement {
85 /// The original user request and any clarification addressed to this role.
86 UserRequest,
87 /// The original request, explicitly accepted plan, and relevant
88 /// clarification. A workflow must retain which planner attempt produced
89 /// the accepted plan; a successful attempt by itself does not establish
90 /// acceptance.
91 UserRequestAndAcceptedPlan,
92}
93
94/// Semantic answer content; does not replace the protocol's response schema.
95///
96/// Clarification uses the existing questions field and leaves the task open.
97/// Producing either output does not automatically accept or complete a task.
98#[derive(Clone, Copy, Debug, Eq, PartialEq)]
99pub enum AgentOutputKind {
100 /// Proposed steps, scope, assumptions, and validation for user input.
101 Plan,
102 /// Observed changes, verification results, and remaining work or blockers.
103 ImplementationReport,
104}
105
106#[cfg(test)]
107#[path = "task_role_test.rs"]
108mod tests;