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

Method parse_event

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

Source from the content-addressed store, hash-verified

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