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

Method parse_event

atomic-agent/src/hooks/agy.rs:232–324  ·  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 let raw_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 timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
248
249 match hook_type {
250 HookType::TurnStart => {
251 // Antigravity: PreInvocation → TurnStart
252 let parsed: PreInvocationInput =
253 serde_json::from_value(raw_json.clone()).map_err(|e| {
254 AgentError::HookParseFailed {
255 agent: self.name().to_string(),
256 hook_type: hook_type.as_str().to_string(),
257 reason: e.to_string(),
258 }
259 })?;
260
261 Ok(self
262 .base_event(hook_type, parsed.conversation_id, parsed.transcript_path)
263 .with_raw_json(raw_json))
264 }
265
266 HookType::TurnEnd => {
267 // Antigravity: Stop → TurnEnd
268 let parsed: StopInput = serde_json::from_value(raw_json.clone()).map_err(|e| {
269 AgentError::HookParseFailed {
270 agent: self.name().to_string(),
271 hook_type: hook_type.as_str().to_string(),
272 reason: e.to_string(),
273 }
274 })?;
275
276 // Normalize the termination reason into the `finish_reason`
277 // field the record pipeline understands (mirrors the Codex
278 // adapter's stop normalization).
279 let raw_json = normalize_stop_raw(raw_json);
280
281 Ok(self
282 .base_event(hook_type, parsed.conversation_id, parsed.transcript_path)
283 .with_raw_json(raw_json))
284 }
285
286 HookType::PostToolUse => {
287 let parsed: PostToolUseInput =
288 serde_json::from_value(raw_json.clone()).map_err(|e| {
289 AgentError::HookParseFailed {

Calls 11

with_raw_jsonMethod · 0.80
base_eventMethod · 0.80
with_tool_use_idMethod · 0.80
with_timestampMethod · 0.80
normalize_stop_rawFunction · 0.70
normalize_tool_rawFunction · 0.70
is_emptyMethod · 0.45
nameMethod · 0.45
as_strMethod · 0.45
parseMethod · 0.45
cloneMethod · 0.45