Skip to content

Commit f06e128

Browse files
committed
refactor(ahp): reduce function parameters using struct pattern
Replace run_lifecycle_event's 8 parameters with RunLifecycleParams struct to resolve clippy::too_many_arguments warning and improve code maintainability. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5b5a857 commit f06e128

1 file changed

Lines changed: 51 additions & 49 deletions

File tree

core/src/ahp/contract.rs

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use chrono::Utc;
44
/// Convert a runtime event into zero or more harness-facing AHP contract events.
55
///
66
/// The SDK event stream remains product/UI friendly. This mapper defines the
7-
/// durable AHP-facing contract used by supervisors, replay, and audit.
7+
/// durable AHP-facing contract used by runtimes, replay, and audit.
88
pub fn agent_event_to_ahp_events(
99
event: &AgentEvent,
1010
run_id: &str,
@@ -13,26 +13,26 @@ pub fn agent_event_to_ahp_events(
1313
depth: u32,
1414
) -> Vec<a3s_ahp::AhpEvent> {
1515
match event {
16-
AgentEvent::Start { prompt } => vec![run_lifecycle_event(
16+
AgentEvent::Start { prompt } => vec![run_lifecycle_event(RunLifecycleParams {
1717
run_id,
18-
default_session_id,
18+
session_id: default_session_id,
1919
agent_id,
2020
depth,
21-
a3s_ahp::RunStatus::Executing,
22-
Some(prompt.clone()),
23-
None,
24-
None,
25-
)],
26-
AgentEvent::PlanningStart { prompt } => vec![run_lifecycle_event(
21+
status: a3s_ahp::RunStatus::Executing,
22+
prompt: Some(prompt.clone()),
23+
result_summary: None,
24+
error: None,
25+
})],
26+
AgentEvent::PlanningStart { prompt } => vec![run_lifecycle_event(RunLifecycleParams {
2727
run_id,
28-
default_session_id,
28+
session_id: default_session_id,
2929
agent_id,
3030
depth,
31-
a3s_ahp::RunStatus::Planning,
32-
Some(prompt.clone()),
33-
None,
34-
None,
35-
)],
31+
status: a3s_ahp::RunStatus::Planning,
32+
prompt: Some(prompt.clone()),
33+
result_summary: None,
34+
error: None,
35+
})],
3636
AgentEvent::TaskUpdated { session_id, tasks } => {
3737
vec![task_list_event(run_id, session_id, agent_id, depth, tasks)]
3838
}
@@ -41,16 +41,16 @@ pub fn agent_event_to_ahp_events(
4141
verification_summary,
4242
..
4343
} => vec![
44-
run_lifecycle_event(
44+
run_lifecycle_event(RunLifecycleParams {
4545
run_id,
46-
default_session_id,
46+
session_id: default_session_id,
4747
agent_id,
4848
depth,
49-
a3s_ahp::RunStatus::Completed,
50-
None,
51-
Some(text.clone()),
52-
None,
53-
),
49+
status: a3s_ahp::RunStatus::Completed,
50+
prompt: None,
51+
result_summary: Some(text.clone()),
52+
error: None,
53+
}),
5454
verification_event(
5555
run_id,
5656
default_session_id,
@@ -59,16 +59,16 @@ pub fn agent_event_to_ahp_events(
5959
verification_summary,
6060
),
6161
],
62-
AgentEvent::Error { message } => vec![run_lifecycle_event(
62+
AgentEvent::Error { message } => vec![run_lifecycle_event(RunLifecycleParams {
6363
run_id,
64-
default_session_id,
64+
session_id: default_session_id,
6565
agent_id,
6666
depth,
67-
a3s_ahp::RunStatus::Failed,
68-
None,
69-
None,
70-
Some(message.clone()),
71-
)],
67+
status: a3s_ahp::RunStatus::Failed,
68+
prompt: None,
69+
result_summary: None,
70+
error: Some(message.clone()),
71+
})],
7272
_ => Vec::new(),
7373
}
7474
}
@@ -98,45 +98,47 @@ pub fn cancelled_run_event(
9898
depth: u32,
9999
reason: Option<&str>,
100100
) -> a3s_ahp::AhpEvent {
101-
run_lifecycle_event(
101+
run_lifecycle_event(RunLifecycleParams {
102102
run_id,
103103
session_id,
104104
agent_id,
105105
depth,
106-
a3s_ahp::RunStatus::Cancelled,
107-
None,
108-
None,
109-
reason.map(str::to_string),
110-
)
106+
status: a3s_ahp::RunStatus::Cancelled,
107+
prompt: None,
108+
result_summary: None,
109+
error: reason.map(str::to_string),
110+
})
111111
}
112112

113-
fn run_lifecycle_event(
114-
run_id: &str,
115-
session_id: &str,
116-
agent_id: &str,
113+
struct RunLifecycleParams<'a> {
114+
run_id: &'a str,
115+
session_id: &'a str,
116+
agent_id: &'a str,
117117
depth: u32,
118118
status: a3s_ahp::RunStatus,
119119
prompt: Option<String>,
120120
result_summary: Option<String>,
121121
error: Option<String>,
122-
) -> a3s_ahp::AhpEvent {
122+
}
123+
124+
fn run_lifecycle_event(params: RunLifecycleParams) -> a3s_ahp::AhpEvent {
123125
let updated_at = now();
124126
let payload = a3s_ahp::RunLifecycleEvent {
125-
run_id: run_id.to_string(),
126-
session_id: session_id.to_string(),
127-
status,
128-
prompt,
129-
result_summary,
130-
error,
127+
run_id: params.run_id.to_string(),
128+
session_id: params.session_id.to_string(),
129+
status: params.status,
130+
prompt: params.prompt,
131+
result_summary: params.result_summary,
132+
error: params.error,
131133
started_at: None,
132134
updated_at,
133135
metadata: None,
134136
};
135137
ahp_event(
136138
a3s_ahp::EventType::RunLifecycle,
137-
session_id,
138-
agent_id,
139-
depth,
139+
params.session_id,
140+
params.agent_id,
141+
params.depth,
140142
serde_json::to_value(payload).expect("run lifecycle payload serializes"),
141143
)
142144
}

0 commit comments

Comments
 (0)