Consume ai-title from external sessions and add end marker (#20261)

## Summary
- Support Claude Code `ai-title` / `aiTitle` records when detecting and
importing external agent sessions.
- Preserve existing `custom-title` / `customTitle` precedence; only fall
back to `aiTitle` when no custom title is present.
- Add coverage for both detection and import title selection, including
the custom-title-over-ai-title case.

## Testing
- `cargo test -p codex-external-agent-sessions`
- `just fix -p codex-external-agent-sessions`
This commit is contained in:
alexsong-oai authored and GitHub committed 2026-04-30 00:00:13 +00:00
1 parent 8774229a89
commit 7bcd4626c4
4 files changed
+222 -13

No files matched your search

@@ -151,6 +151,61 @@ mod tests {
);
}
#[test]
fn detects_ai_title_over_first_user_message() {
let root = TempDir::new().expect("tempdir");
let external_agent_home = root.path().join(".external");
let project_root = root.path().join("repo");
let session_path = write_session(
&external_agent_home,
&project_root,
"session.jsonl",
&[
record("user", "hello there", project_root.as_path()),
ai_title_record("generated by source app"),
],
);
let sessions = detect_recent_sessions(&external_agent_home, root.path()).expect("detect");
assert_eq!(
sessions,
vec![ExternalAgentSessionMigration {
path: session_path,
cwd: project_root,
title: Some("generated by source app".to_string()),
}]
);
}
#[test]
fn prefers_custom_title_over_later_ai_title() {
let root = TempDir::new().expect("tempdir");
let external_agent_home = root.path().join(".external");
let project_root = root.path().join("repo");
let session_path = write_session(
&external_agent_home,
&project_root,
"session.jsonl",
&[
record("user", "hello there", project_root.as_path()),
custom_title_record("custom title"),
ai_title_record("generated title"),
],
);
let sessions = detect_recent_sessions(&external_agent_home, root.path()).expect("detect");
assert_eq!(
sessions,
vec![ExternalAgentSessionMigration {
path: session_path,
cwd: project_root,
title: Some("custom title".to_string()),
}]
);
}
#[test]
fn ignores_old_sessions() {
let root = TempDir::new().expect("tempdir");
@@ -266,6 +321,13 @@ mod tests {
})
}
fn ai_title_record(title: &str) -> JsonValue {
serde_json::json!({
"type": "ai-title",
"aiTitle": title,
})
}
fn jsonl(records: &[JsonValue]) -> String {
records
.iter()