Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ This changelog is automatically generated by AI when releases are published.

## [Unreleased]

## [3.19.0] - 2026-12-05

### Added

- **Stored transcripts keep each tool call's id.** Every tool call in a transcript autter saves now carries the id the agent gave it: the `id` of a Claude Code (`toolu_...`) or Droid (`call_...`) `tool_use` block, or the `call_id` of a Codex call. These are the same ids the agents' hooks report, so the Autter PR page can point a changed line at the exact tool call that wrote it instead of guessing by time. Transcripts stored before this have no ids and still parse as before.

### Changed

- **Codex freeform `apply_patch` calls are kept.** Codex `custom_tool_call` items were dropped from stored transcripts; they now appear as tool calls, with their `call_id`.

## [3.18.0] - 2026-11-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "3"

[package]
name = "autter"
version = "3.18.0"
version = "3.19.0"
edition = "2024"
default-run = "autter"

Expand Down
214 changes: 195 additions & 19 deletions src/authorship/cas_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,35 @@ fn messages_from_event(event: &Value) -> Vec<Message> {
.map(str::to_string)
.or(outer_timestamp);

if event
.get("type")
.and_then(Value::as_str)
.is_some_and(|t| t == "function_call")
{
// Codex tool calls: `function_call` (JSON `arguments`) and
// `custom_tool_call` (freeform `input`, e.g. `apply_patch`). Both name the
// call with `call_id`, which is the `tool_use_id` Codex's hooks send.
// (`id` on these items is the response item's own id, not the call's.)
let event_type = event.get("type").and_then(Value::as_str);
if matches!(event_type, Some("function_call" | "custom_tool_call")) {
let name = event
.get("name")
.and_then(Value::as_str)
.unwrap_or("unknown")
.to_string();
let input = event
.get("arguments")
.and_then(|v| {
if let Some(raw) = v.as_str() {
serde_json::from_str(raw).ok()
} else {
Some(v.clone())
}
})
.unwrap_or(Value::Null);
let input = if event_type == Some("function_call") {
event
.get("arguments")
.and_then(|v| {
if let Some(raw) = v.as_str() {
serde_json::from_str(raw).ok()
} else {
Some(v.clone())
}
})
.unwrap_or(Value::Null)
} else {
event.get("input").cloned().unwrap_or(Value::Null)
};
return vec![Message::ToolUse {
name,
input,
id: non_empty_str(&event, "call_id"),
timestamp,
}];
}
Expand Down Expand Up @@ -514,9 +520,12 @@ fn block_to_messages(role: Role, block: &Value, timestamp: &Option<String>) -> V
.unwrap_or("unknown")
.to_string();
let input = block.get("input").cloned().unwrap_or(Value::Null);
// Claude's `toolu_…` id (Droid: `call_…`), the same id the
// agent's PostToolUse hook sends as `tool_use_id`.
vec![Message::ToolUse {
name,
input,
id: non_empty_str(block, "id"),
timestamp: timestamp.clone(),
}]
}
Expand Down Expand Up @@ -583,6 +592,16 @@ fn event_role(event: &Value) -> Role {
}
}

/// A string field as written (ids must match the hook's byte for byte), or
/// `None` when it is missing, not a string, or blank.
fn non_empty_str(value: &Value, key: &str) -> Option<String> {
value
.get(key)
.and_then(Value::as_str)
.filter(|s| !s.trim().is_empty())
.map(str::to_string)
}

/// Build a user/assistant text message, dropping empty text.
fn text_message(role: Role, text: String, timestamp: Option<String>) -> Option<Message> {
if text.trim().is_empty() {
Expand Down Expand Up @@ -664,14 +683,66 @@ mod tests {
"type": "assistant",
"message": { "content": [
{ "type": "text", "text": "I'll create it." },
{ "type": "tool_use", "name": "Write", "input": { "file_path": "hello.py" } }
{ "type": "tool_use", "id": "toolu_017eJUTKxEGKFWWtVD54v9vx", "name": "Write", "input": { "file_path": "hello.py" } }
], "model": "claude-sonnet-4" },
"timestamp": "2025-01-01T12:00:02Z"
});
let msgs = messages_from_event(&event);
assert_eq!(msgs.len(), 2);
assert!(matches!(&msgs[0], Message::Assistant { text, .. } if text == "I'll create it."));
assert!(matches!(&msgs[1], Message::ToolUse { name, .. } if name == "Write"));
assert_eq!(
msgs[1],
Message::ToolUse {
name: "Write".to_string(),
input: serde_json::json!({ "file_path": "hello.py" }),
id: Some("toolu_017eJUTKxEGKFWWtVD54v9vx".to_string()),
timestamp: Some("2025-01-01T12:00:02Z".to_string()),
}
);
}

#[test]
fn droid_tool_use_block_keeps_call_id() {
let event = serde_json::json!({
"type": "message",
"id": "3931b94d-4807-4231-a40c-854b90f1ba03",
"timestamp": "2026-01-28T16:57:15.899Z",
"message": { "role": "assistant", "content": [
{ "type": "tool_use", "id": "call_4LkL0djh4nDHl8xGUQeH4Kvh", "name": "Read",
"input": { "file_path": "/p/index.ts" } }
] }
});
let msgs = messages_from_event(&event);
assert!(matches!(
&msgs[0],
Message::ToolUse { name, id, .. }
if name == "Read" && id.as_deref() == Some("call_4LkL0djh4nDHl8xGUQeH4Kvh")
));
}

#[test]
fn cursor_tool_use_block_without_id_has_none() {
// Cursor's agent transcripts carry no tool-call id.
let event = serde_json::json!({
"role": "assistant",
"message": { "content": [
{ "type": "tool_use", "name": "Read", "input": { "path": "/p/a.txt" } }
] }
});
let msgs = messages_from_event(&event);
assert!(matches!(&msgs[0], Message::ToolUse { id: None, .. }));
}

#[test]
fn blank_tool_use_id_is_dropped() {
let event = serde_json::json!({
"type": "assistant",
"message": { "content": [
{ "type": "tool_use", "id": " ", "name": "Write", "input": {} }
] }
});
let msgs = messages_from_event(&event);
assert!(matches!(&msgs[0], Message::ToolUse { id: None, .. }));
}

#[test]
Expand Down Expand Up @@ -740,11 +811,116 @@ mod tests {
"payload": {
"type": "function_call",
"name": "apply_patch",
"arguments": "{\"patch\":\"*** Begin Patch\"}"
"arguments": "{\"patch\":\"*** Begin Patch\"}",
"call_id": "call_abc123"
}
});
let msgs = messages_from_event(&event);
assert!(matches!(&msgs[0], Message::ToolUse { name, .. } if name == "apply_patch"));
assert_eq!(
msgs,
vec![Message::ToolUse {
name: "apply_patch".to_string(),
input: serde_json::json!({ "patch": "*** Begin Patch" }),
id: Some("call_abc123".to_string()),
timestamp: Some("2026-02-11T05:53:33.420Z".to_string()),
}]
);
}

#[test]
fn codex_function_call_uses_call_id_not_item_id() {
let event = serde_json::json!({
"type": "response_item",
"payload": {
"type": "function_call",
"id": "fc_68a1b2c3",
"name": "shell",
"arguments": "{\"command\":[\"ls\"]}",
"call_id": "call_def456"
}
});
let msgs = messages_from_event(&event);
assert!(matches!(
&msgs[0],
Message::ToolUse { id, .. } if id.as_deref() == Some("call_def456")
));
}

#[test]
fn codex_custom_tool_call_maps_to_tool_use_with_call_id() {
let event = serde_json::json!({
"timestamp": "2026-02-11T05:53:34.000Z",
"type": "response_item",
"payload": {
"type": "custom_tool_call",
"status": "completed",
"call_id": "call_patch789",
"name": "apply_patch",
"input": "*** Begin Patch\n*** Update File: src/main.rs\n*** End Patch"
}
});
let msgs = messages_from_event(&event);
assert_eq!(
msgs,
vec![Message::ToolUse {
name: "apply_patch".to_string(),
input: Value::String(
"*** Begin Patch\n*** Update File: src/main.rs\n*** End Patch".to_string()
),
id: Some("call_patch789".to_string()),
timestamp: Some("2026-02-11T05:53:34.000Z".to_string()),
}]
);
}

#[test]
fn transcript_file_keeps_tool_use_ids_through_redaction() {
// The path both the upload queue and the local cache take: parse,
// serialize, redact, parse again. `id` is on the redaction denylist,
// so even a secret-looking id must come out unchanged.
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("session.jsonl");
let secret_looking_id = "toolu_sk_test_4eC39HqLyjWDarjtT1zdp7dc";
let lines = [
serde_json::json!({
"type": "user",
"message": { "content": "Write hello.py" },
"timestamp": "2025-01-01T12:00:00Z"
}),
serde_json::json!({
"type": "assistant",
"message": { "content": [
{ "type": "tool_use", "id": secret_looking_id, "name": "Write",
"input": { "file_path": "hello.py" } }
] },
"timestamp": "2025-01-01T12:00:02Z"
}),
serde_json::json!({
"timestamp": "2026-02-11T05:53:33.420Z",
"type": "response_item",
"payload": { "type": "function_call", "name": "shell",
"arguments": "{}", "call_id": "call_abc123" }
}),
];
let raw: Vec<String> = lines.iter().map(|l| l.to_string()).collect();
std::fs::write(&path, raw.join("\n")).unwrap();

let messages = messages_from_transcript_file(path.to_str().unwrap())
.unwrap()
.unwrap();
let ids: Vec<Option<&str>> = messages
.iter()
.filter_map(|m| match m {
Message::ToolUse { id, .. } => Some(id.as_deref()),
_ => None,
})
.collect();
assert_eq!(ids, vec![Some(secret_looking_id), Some("call_abc123")]);

// The CAS object the daemon uploads as-is carries `id`.
let payload = serde_json::to_value(CasMessagesObject { messages }).unwrap();
assert_eq!(payload["messages"][1]["id"], secret_looking_id);
assert_eq!(payload["messages"][2]["id"], "call_abc123");
}

#[test]
Expand Down
Loading
Loading