Skip to content

Commit aa0c928

Browse files
tibo-openaiHolovkat
authored andcommitted
feat: include cwd in notify payload (#5415)
Expose the session cwd in the notify payload and update docs so scripts and extensions receive the real project path; users get accurate project-aware notifications in CLI and VS Code. Fixes #5387
1 parent df675b1 commit aa0c928

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

codex-rs/core/src/codex.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
2-
use std::collections::{HashMap, HashSet};
2+
use std::collections::HashMap;
3+
use std::collections::HashSet;
34
use std::fmt::Debug;
45
use std::path::PathBuf;
56
use std::sync::Arc;
@@ -23,6 +24,7 @@ use codex_protocol::items::TurnItem;
2324
use codex_protocol::items::UserMessageItem;
2425
use codex_protocol::protocol::ConversationPathResponseEvent;
2526
use codex_protocol::protocol::ExitedReviewModeEvent;
27+
#[cfg(test)]
2628
use codex_protocol::protocol::McpAuthStatus;
2729
use codex_protocol::protocol::MemoryPreviewEntry;
2830
use codex_protocol::protocol::MemoryPreviewEvent;
@@ -1893,6 +1895,7 @@ pub(crate) async fn run_task(
18931895
.notify(&UserNotification::AgentTurnComplete {
18941896
thread_id: sess.conversation_id.to_string(),
18951897
turn_id: sub_id.clone(),
1898+
cwd: turn_context.cwd.display().to_string(),
18961899
input_messages: turn_input_messages,
18971900
last_assistant_message: last_agent_message.clone(),
18981901
});

codex-rs/core/src/user_notification.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub(crate) enum UserNotification {
5151
AgentTurnComplete {
5252
thread_id: String,
5353
turn_id: String,
54+
cwd: String,
5455

5556
/// Messages that the user sent to the agent to initiate the turn.
5657
input_messages: Vec<String>,
@@ -70,6 +71,7 @@ mod tests {
7071
let notification = UserNotification::AgentTurnComplete {
7172
thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(),
7273
turn_id: "12345".to_string(),
74+
cwd: "/Users/example/project".to_string(),
7375
input_messages: vec!["Rename `foo` to `bar` and update the callsites.".to_string()],
7476
last_assistant_message: Some(
7577
"Rename complete and verified `cargo build` succeeds.".to_string(),
@@ -78,7 +80,7 @@ mod tests {
7880
let serialized = serde_json::to_string(&notification)?;
7981
assert_eq!(
8082
serialized,
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."}"#
83+
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."}"#
8284
);
8385
Ok(())
8486
}

codex-rs/tui/src/history_cell.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::version::CODEX_CLI_VERSION;
2020
use crate::wrapping::RtOptions;
2121
use crate::wrapping::word_wrap_line;
2222
use crate::wrapping::word_wrap_lines;
23-
use codex_common::format_env_display::format_env_display;
2423
use base64::Engine;
2524
use codex_agentic_core::index::query::QueryHit;
25+
use codex_common::format_env_display::format_env_display;
2626
use codex_core::config::Config;
2727
use codex_core::config_types::McpServerTransportConfig;
2828
use codex_core::config_types::ReasoningSummaryFormat;
@@ -37,7 +37,9 @@ use codex_protocol::plan_tool::UpdatePlanArgs;
3737
use image::DynamicImage;
3838
use image::ImageReader;
3939
use mcp_types::EmbeddedResourceResource;
40+
use mcp_types::Resource;
4041
use mcp_types::ResourceLink;
42+
use mcp_types::ResourceTemplate;
4143
use ratatui::prelude::*;
4244
use ratatui::style::Modifier;
4345
use ratatui::style::Style;
@@ -46,8 +48,6 @@ use ratatui::style::Stylize;
4648
use ratatui::widgets::Paragraph;
4749
use ratatui::widgets::WidgetRef;
4850
use ratatui::widgets::Wrap;
49-
use mcp_types::Resource;
50-
use mcp_types::ResourceTemplate;
5151
use std::any::Any;
5252
use std::collections::HashMap;
5353
use std::io::Cursor;

codex-rs/tui/src/updates.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,26 @@ fn version_filepath(config: &Config) -> PathBuf {
7676

7777
fn resolve_latest_url(update_config: &UpdateConfig) -> Option<String> {
7878
if let Some(url) = &update_config.latest_url
79-
&& !url.trim().is_empty() {
80-
return Some(url.clone());
81-
}
79+
&& !url.trim().is_empty()
80+
{
81+
return Some(url.clone());
82+
}
8283
if let Some(repo) = &update_config.repo
83-
&& !repo.trim().is_empty() {
84-
return Some(format!(
85-
"https://api.github.com/repos/{repo}/releases/latest"
86-
));
87-
}
84+
&& !repo.trim().is_empty()
85+
{
86+
return Some(format!(
87+
"https://api.github.com/repos/{repo}/releases/latest"
88+
));
89+
}
8890
Some(LATEST_RELEASE_URL.to_string())
8991
}
9092

9193
fn release_url(update_config: &UpdateConfig) -> Option<String> {
9294
if let Some(repo) = &update_config.repo
93-
&& !repo.trim().is_empty() {
94-
return Some(format!("https://github.com/{repo}/releases/latest"));
95-
}
95+
&& !repo.trim().is_empty()
96+
{
97+
return Some(format!("https://github.com/{repo}/releases/latest"));
98+
}
9699
update_config
97100
.latest_url
98101
.as_ref()

docs/config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ Specify a program that will be executed to get notified about events generated b
626626
"type": "agent-turn-complete",
627627
"thread-id": "b5f6c1c2-1111-2222-3333-444455556666",
628628
"turn-id": "12345",
629+
"cwd": "/Users/alice/projects/example",
629630
"input-messages": ["Rename `foo` to `bar` and update the callsites."],
630631
"last-assistant-message": "Rename complete and verified `cargo build` succeeds."
631632
}
@@ -635,6 +636,8 @@ The `"type"` property will always be set. Currently, `"agent-turn-complete"` is
635636

636637
`"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.
637638

639+
`"cwd"` reports the absolute working directory for the session so scripts can disambiguate which project triggered the notification.
640+
638641
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:
639642

640643
```python

0 commit comments

Comments
 (0)