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
This commit is contained in:
committed by
GitHub
parent
df15a2f6ef
commit
7fc01c6e9b
@@ -1715,6 +1715,7 @@ pub(crate) async fn run_task(
|
|||||||
.notify(&UserNotification::AgentTurnComplete {
|
.notify(&UserNotification::AgentTurnComplete {
|
||||||
thread_id: sess.conversation_id.to_string(),
|
thread_id: sess.conversation_id.to_string(),
|
||||||
turn_id: sub_id.clone(),
|
turn_id: sub_id.clone(),
|
||||||
|
cwd: turn_context.cwd.display().to_string(),
|
||||||
input_messages: turn_input_messages,
|
input_messages: turn_input_messages,
|
||||||
last_assistant_message: last_agent_message.clone(),
|
last_assistant_message: last_agent_message.clone(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ pub(crate) enum UserNotification {
|
|||||||
AgentTurnComplete {
|
AgentTurnComplete {
|
||||||
thread_id: String,
|
thread_id: String,
|
||||||
turn_id: String,
|
turn_id: String,
|
||||||
|
cwd: String,
|
||||||
|
|
||||||
/// Messages that the user sent to the agent to initiate the turn.
|
/// Messages that the user sent to the agent to initiate the turn.
|
||||||
input_messages: Vec<String>,
|
input_messages: Vec<String>,
|
||||||
@@ -70,6 +71,7 @@ mod tests {
|
|||||||
let notification = UserNotification::AgentTurnComplete {
|
let notification = UserNotification::AgentTurnComplete {
|
||||||
thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(),
|
thread_id: "b5f6c1c2-1111-2222-3333-444455556666".to_string(),
|
||||||
turn_id: "12345".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()],
|
input_messages: vec!["Rename `foo` to `bar` and update the callsites.".to_string()],
|
||||||
last_assistant_message: Some(
|
last_assistant_message: Some(
|
||||||
"Rename complete and verified `cargo build` succeeds.".to_string(),
|
"Rename complete and verified `cargo build` succeeds.".to_string(),
|
||||||
@@ -78,7 +80,7 @@ mod tests {
|
|||||||
let serialized = serde_json::to_string(¬ification)?;
|
let serialized = serde_json::to_string(¬ification)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serialized,
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -626,6 +626,7 @@ Specify a program that will be executed to get notified about events generated b
|
|||||||
"type": "agent-turn-complete",
|
"type": "agent-turn-complete",
|
||||||
"thread-id": "b5f6c1c2-1111-2222-3333-444455556666",
|
"thread-id": "b5f6c1c2-1111-2222-3333-444455556666",
|
||||||
"turn-id": "12345",
|
"turn-id": "12345",
|
||||||
|
"cwd": "/Users/alice/projects/example",
|
||||||
"input-messages": ["Rename `foo` to `bar` and update the callsites."],
|
"input-messages": ["Rename `foo` to `bar` and update the callsites."],
|
||||||
"last-assistant-message": "Rename complete and verified `cargo build` succeeds."
|
"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.
|
`"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:
|
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
|
```python
|
||||||
|
|||||||
Reference in New Issue
Block a user