mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
## What changed - Add `currentAccountOnly` to `thread/list` and `thread/search`, defaulting to `false`, and enable it for TUI history discovery, resume pickers, and task mentions. - Mark newly created threads as account-scoped and require each recorded creator user or account ID to match the current login. Older threads and threads without creator IDs remain shared; API-key logins continue to see all local history. - Preserve account scope through resume and revert, including fallback to original rollout metadata when an older binary drops the marker. Forks receive new-thread scope. - Skip unreadable rollout headers in scoped discovery and filter search candidates before reading snippets. Direct access by thread ID remains available. ## Testing Add coverage for account matching, shared legacy history, list page refilling, search pagination, API-key visibility, and scope preservation across reverts. Extend rollout lookup coverage to compressed active and archived files. GitOrigin-RevId: aa374f5e69165be5a71c0716ded1b105f5fb51e0
68 lines
2.4 KiB
Rust
68 lines
2.4 KiB
Rust
//! Account matching for local discovery. Pre-enforcement threads remain shared.
|
|
|
|
use std::collections::HashMap;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
use codex_protocol::ThreadId;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
/// The current ChatGPT identity for account-scoped local history discovery.
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct LocalHistoryAccount {
|
|
pub user_id: Option<String>,
|
|
pub account_id: Option<String>,
|
|
}
|
|
|
|
impl LocalHistoryAccount {
|
|
/// Newly scoped threads must match each creator ID; older history stays shared.
|
|
/// Reuse `original_paths` only within the page identified by `page_thread_ids`.
|
|
pub async fn includes(
|
|
&self,
|
|
codex_home: &Path,
|
|
thread_id: ThreadId,
|
|
rollout_path: Option<&Path>,
|
|
page_thread_ids: &[ThreadId],
|
|
original_paths: &mut Option<HashMap<ThreadId, PathBuf>>,
|
|
) -> bool {
|
|
let Some(path) = rollout_path else {
|
|
return false;
|
|
};
|
|
let Ok(header) = codex_rollout::read_session_meta_line(path).await else {
|
|
return false;
|
|
};
|
|
let mut meta = header.meta;
|
|
if meta.id != thread_id {
|
|
return false;
|
|
}
|
|
if !meta.account_scoped
|
|
&& codex_rollout::rollout_id_from_path(path).is_some_and(|id| id != thread_id)
|
|
{
|
|
// An older binary can drop the marker on revert; consult the original rollout.
|
|
// Resolve the page together so each reverted thread does not rescan all history.
|
|
if original_paths.is_none() {
|
|
*original_paths = Some(
|
|
codex_rollout::find_rollout_paths_by_rollout_ids(codex_home, page_thread_ids)
|
|
.await,
|
|
);
|
|
}
|
|
let Some(original) = original_paths
|
|
.as_ref()
|
|
.and_then(|paths| paths.get(&thread_id))
|
|
else {
|
|
return false;
|
|
};
|
|
let Ok(header) = codex_rollout::read_session_meta_line(original).await else {
|
|
return false;
|
|
};
|
|
meta = header.meta;
|
|
}
|
|
meta.id == thread_id
|
|
&& (!meta.account_scoped
|
|
|| ((meta.creator_user_id.is_none() || meta.creator_user_id == self.user_id)
|
|
&& (meta.creator_account_id.is_none()
|
|
|| meta.creator_account_id == self.account_id)))
|
|
}
|
|
}
|