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

Method parse_event

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

Source from the content-addressed store, hash-verified

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

Calls 12

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