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

Method parse_event

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

Source from the content-addressed store, hash-verified

169 }
170
171 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
172 let raw_json = self.parse_json(hook_type, input)?;
173 let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
174 let parsed = self.parse_common(hook_type, raw_json.clone())?;
175
176 let mut raw_json = with_xai_provider(raw_json);
177 if hook_type == HookType::TurnEnd {
178 raw_json = normalize_stop_raw(raw_json, parsed.reason.as_deref());
179 }
180 if hook_type == HookType::PostToolUse {
181 raw_json = normalize_tool_raw(raw_json, parsed.tool_result.as_ref());
182 }
183
184 // Promote model/provider into raw_json when present (orchestrator reads them).
185 if let Some(model) = parsed.model.as_ref() {
186 insert_if_missing(&mut raw_json, "model", Value::String(model.clone()));
187 }
188 if let Some(provider) = parsed.provider.as_ref() {
189 insert_if_missing(&mut raw_json, "provider", Value::String(provider.clone()));
190 }
191
192 let mut event = TurnEvent::new(Self::extract_session_id(parsed.session_id), hook_type)
193 .with_raw_json(raw_json);
194
195 if let Some(path) = parsed.transcript_path.filter(|p| !p.is_empty()) {
196 event = event.with_transcript_path(path);
197 }
198
199 match hook_type {
200 HookType::TurnStart => {
201 if let Some(prompt) = parsed.prompt.filter(|p| !p.is_empty()) {
202 // Grok's UserPromptSubmit often wraps the human text in
203 // `<user_query>…</user_query>` (harness envelope). That
204 // raw string would otherwise become the Atomic change
205 // message (`atomic log` shows the tags). Strip it so
206 // provenance and the commit message carry the real text.
207 let prompt = normalize_user_prompt(&prompt);
208 if !prompt.is_empty() {
209 event = event.with_prompt(prompt);
210 }
211 }
212 }
213 HookType::PreToolUse | HookType::PostToolUse => {
214 if let Some(name) = parsed.tool_name.filter(|n| !n.is_empty()) {
215 event = event.with_tool_name(name);
216 }
217 if let Some(id) = parsed.tool_use_id.filter(|id| !id.is_empty()) {
218 event = event.with_tool_use_id(id);
219 }
220 }
221 HookType::SessionStart | HookType::SessionEnd | HookType::TurnEnd => {}
222 }
223
224 Ok(event.with_timestamp(timestamp))
225 }
226
227 fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
228 // Installation is handled by the atomic-grok package via the

Calls 15

with_xai_providerFunction · 0.85
extract_session_idFunction · 0.85
normalize_user_promptFunction · 0.85
parse_commonMethod · 0.80
as_refMethod · 0.80
with_raw_jsonMethod · 0.80
with_transcript_pathMethod · 0.80
with_promptMethod · 0.80
with_tool_use_idMethod · 0.80
with_timestampMethod · 0.80
normalize_stop_rawFunction · 0.70
normalize_tool_rawFunction · 0.70