Skip to content

Commit 1303556

Browse files
authored
feat: pass codex thread ID in notifier metadata (openai#4582)
1 parent 9be704a commit 1303556

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

codex-rs/core/src/codex.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,7 @@ pub(crate) async fn run_task(
18581858
);
18591859
sess.notifier()
18601860
.notify(&UserNotification::AgentTurnComplete {
1861+
thread_id: sess.conversation_id.to_string(),
18611862
turn_id: sub_id.clone(),
18621863
input_messages: turn_input_messages,
18631864
last_assistant_message: last_agent_message.clone(),

codex-rs/core/src/user_notification.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl UserNotifier {
4949
pub(crate) enum UserNotification {
5050
#[serde(rename_all = "kebab-case")]
5151
AgentTurnComplete {
52+
thread_id: String,
5253
turn_id: String,
5354

5455
/// Messages that the user sent to the agent to initiate the turn.
@@ -67,6 +68,7 @@ mod tests {
6768
#[test]
6869
fn test_user_notification() -> Result<()> {
6970
let notification = UserNotification::AgentTurnComplete {
71+
thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(),
7072
turn_id: "12345".to_string(),
7173
input_messages: vec!["Rename `foo` to `bar` and update the callsites.".to_string()],
7274
last_assistant_message: Some(
@@ -76,7 +78,7 @@ mod tests {
7678
let serialized = serde_json::to_string(&notification)?;
7779
assert_eq!(
7880
serialized,
79-
r#"{"type":"agent-turn-complete","turn-id":"12345","input-messages":["Rename `foo` to `bar` and update the callsites."],"last-assistant-message":"Rename complete and verified `cargo build` succeeds."}"#
81+
r#"{"type":"agent-turn-complete","thread-id":"b5f6c1c2-1111-2222-3333-444455556666","turn-id":"12345","input-messages":["Rename `foo` to `bar` and update the callsites."],"last-assistant-message":"Rename complete and verified `cargo build` succeeds."}"#
8082
);
8183
Ok(())
8284
}

docs/config.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ Specify a program that will be executed to get notified about events generated b
602602
```json
603603
{
604604
"type": "agent-turn-complete",
605+
"thread-id": "b5f6c1c2-1111-2222-3333-444455556666",
605606
"turn-id": "12345",
606607
"input-messages": ["Rename `foo` to `bar` and update the callsites."],
607608
"last-assistant-message": "Rename complete and verified `cargo build` succeeds."
@@ -610,6 +611,8 @@ Specify a program that will be executed to get notified about events generated b
610611

611612
The `"type"` property will always be set. Currently, `"agent-turn-complete"` is the only notification type that is supported.
612613

614+
`"thread-id"` contains a string that identifies the Codex session that produced the notification; you can use it to correlate multiple turns that belong to the same task.
615+
613616
As an example, here is a Python script that parses the JSON and decides whether to show a desktop push notification using [terminal-notifier](https://github.com/julienXX/terminal-notifier) on macOS:
614617

615618
```python
@@ -644,6 +647,8 @@ def main() -> int:
644647
print(f"not sending a push notification for: {notification_type}")
645648
return 0
646649

650+
thread_id = notification.get("thread-id", "")
651+
647652
subprocess.check_output(
648653
[
649654
"terminal-notifier",
@@ -652,7 +657,7 @@ def main() -> int:
652657
"-message",
653658
message,
654659
"-group",
655-
"codex",
660+
"codex-" + thread_id,
656661
"-ignoreDnD",
657662
"-activate",
658663
"com.googlecode.iterm2",

0 commit comments

Comments
 (0)