| 155 | } |
| 156 | |
| 157 | fn merge_codex_subagent_output(output: Option<String>, digest: Option<String>) -> Option<String> { |
| 158 | let Some(digest) = digest else { |
| 159 | return output; |
| 160 | }; |
| 161 | let Some(output) = output else { |
| 162 | return Some(codex_additional_context_json("SubagentStart", &digest)); |
| 163 | }; |
| 164 | let Ok(mut parsed) = serde_json::from_str::<Value>(&output) else { |
| 165 | return Some(output); |
| 166 | }; |
| 167 | let Some(context) = parsed |
| 168 | .pointer_mut("/hookSpecificOutput/additionalContext") |
| 169 | .and_then(|value| value.as_str().map(str::to_string)) |
| 170 | else { |
| 171 | return Some(output); |
| 172 | }; |
| 173 | let mut merged = context; |
| 174 | append_context_block(&mut merged, &digest); |
| 175 | parsed["hookSpecificOutput"]["additionalContext"] = Value::String(merged); |
| 176 | Some(parsed.to_string()) |
| 177 | } |
| 178 | |
| 179 | /// Codex `PostToolUse` hook handler used to keep the graph fresh. |
| 180 | pub async fn hook_codex_post_tool_use() -> i32 { |