MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / parse_event

Method parse_event

atomic-agent/src/hooks/cline.rs:231–418  ·  view source on GitHub ↗
(&self, hook_type: HookType, input: &[u8])

Source from the content-addressed store, hash-verified

229 }
230
231 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
232 if input.is_empty() {
233 return Err(AgentError::HookInputEmpty {
234 agent: self.name().to_string(),
235 hook_type: hook_type.as_str().to_string(),
236 });
237 }
238
239 // Preserve raw JSON for debugging and downstream use
240 let raw_json: serde_json::Value =
241 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
242 agent: self.name().to_string(),
243 hook_type: hook_type.as_str().to_string(),
244 reason: e.to_string(),
245 })?;
246
247 let parsed: ClineInput =
248 serde_json::from_value(raw_json.clone()).map_err(|e| AgentError::HookParseFailed {
249 agent: self.name().to_string(),
250 hook_type: hook_type.as_str().to_string(),
251 reason: e.to_string(),
252 })?;
253
254 // Extract model info from the nested model object.
255 // Store slug as the model name and provider as the vendor.
256 let model_slug = parsed
257 .model
258 .as_ref()
259 .and_then(|m| m.slug.as_deref())
260 .map(|s| s.to_string());
261 let model_provider = parsed
262 .model
263 .as_ref()
264 .and_then(|m| m.provider.as_deref())
265 .map(|s| s.to_string());
266
267 match hook_type {
268 HookType::SessionStart => {
269 // task-start or task-resume
270 let prompt = parsed
271 .task_start
272 .as_ref()
273 .and_then(|d| d.task.clone())
274 .or_else(|| parsed.task_resume.as_ref().and_then(|d| d.task.clone()));
275
276 let mut event = TurnEvent::new(Self::extract_session_id(parsed.task_id), hook_type)
277 .with_raw_json(raw_json);
278
279 if let Some(p) = prompt {
280 event = event.with_prompt(p);
281 }
282
283 // Store model info in raw_json for the orchestrator
284 if let Some(ref mut raw) = event.raw_json {
285 if let Some(obj) = raw.as_object_mut() {
286 if let Some(ref slug) = model_slug {
287 obj.insert(
288 "model_name".to_string(),

Calls 10

extract_session_idFunction · 0.85
as_refMethod · 0.80
with_raw_jsonMethod · 0.80
with_promptMethod · 0.80
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
with_tool_nameMethod · 0.45