diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 6f0f967f..af1d9ef0 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1715,6 +1715,7 @@ pub(crate) async fn run_task( .notify(&UserNotification::AgentTurnComplete { thread_id: sess.conversation_id.to_string(), turn_id: sub_id.clone(), + cwd: turn_context.cwd.display().to_string(), input_messages: turn_input_messages, last_assistant_message: last_agent_message.clone(), }); diff --git a/codex-rs/core/src/user_notification.rs b/codex-rs/core/src/user_notification.rs index be96d562..7bbd1d95 100644 --- a/codex-rs/core/src/user_notification.rs +++ b/codex-rs/core/src/user_notification.rs @@ -51,6 +51,7 @@ pub(crate) enum UserNotification { AgentTurnComplete { thread_id: String, turn_id: String, + cwd: String, /// Messages that the user sent to the agent to initiate the turn. input_messages: Vec, @@ -70,6 +71,7 @@ mod tests { let notification = UserNotification::AgentTurnComplete { thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(), turn_id: "12345".to_string(), + cwd: "/Users/example/project".to_string(), input_messages: vec!["Rename `foo` to `bar` and update the callsites.".to_string()], last_assistant_message: Some( "Rename complete and verified `cargo build` succeeds.".to_string(), @@ -78,7 +80,7 @@ mod tests { let serialized = serde_json::to_string(¬ification)?; assert_eq!( serialized, - 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."}"# + r#"{"type":"agent-turn-complete","thread-id":"b5f6c1c2-1111-2222-3333-444455556666","turn-id":"12345","cwd":"/Users/example/project","input-messages":["Rename `foo` to `bar` and update the callsites."],"last-assistant-message":"Rename complete and verified `cargo build` succeeds."}"# ); Ok(()) } diff --git a/docs/config.md b/docs/config.md index b92342b2..b5699021 100644 --- a/docs/config.md +++ b/docs/config.md @@ -626,6 +626,7 @@ Specify a program that will be executed to get notified about events generated b "type": "agent-turn-complete", "thread-id": "b5f6c1c2-1111-2222-3333-444455556666", "turn-id": "12345", + "cwd": "/Users/alice/projects/example", "input-messages": ["Rename `foo` to `bar` and update the callsites."], "last-assistant-message": "Rename complete and verified `cargo build` succeeds." } @@ -635,6 +636,8 @@ The `"type"` property will always be set. Currently, `"agent-turn-complete"` is `"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. +`"cwd"` reports the absolute working directory for the session so scripts can disambiguate which project triggered the notification. + 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: ```python