mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
## Why Once the repo-local lint exists, `codex-rs` needs to follow the checked-in convention and CI needs to keep it from drifting. This commit applies the fallback `/*param*/` style consistently across existing positional literal call sites without changing those APIs. The longer-term preference is still to avoid APIs that require comments by choosing clearer parameter types and call shapes. This PR is intentionally the mechanical follow-through for the places where the existing signatures stay in place. After rebasing onto newer `main`, the rollout also had to cover newly introduced `tui_app_server` call sites. That made it clear the first cut of the CI job was too expensive for the common path: it was spending almost as much time installing `cargo-dylint` and re-testing the lint crate as a representative test job spends running product tests. The CI update keeps the full workspace enforcement but trims that extra overhead from ordinary `codex-rs` PRs. ## What changed - keep a dedicated `argument_comment_lint` job in `rust-ci` - mechanically annotate remaining opaque positional literals across `codex-rs` with exact `/*param*/` comments, including the rebased `tui_app_server` call sites that now fall under the lint - keep the checked-in style aligned with the lint policy by using `/*param*/` and leaving string and char literals uncommented - cache `cargo-dylint`, `dylint-link`, and the relevant Cargo registry/git metadata in the lint job - split changed-path detection so the lint crate's own `cargo test` step runs only when `tools/argument-comment-lint/*` or `rust-ci.yml` changes - continue to run the repo wrapper over the `codex-rs` workspace, so product-code enforcement is unchanged Most of the code changes in this commit are intentionally mechanical comment rewrites or insertions driven by the lint itself. ## Verification - `./tools/argument-comment-lint/run.sh --workspace` - `cargo test -p codex-tui-app-server -p codex-tui` - parsed `.github/workflows/rust-ci.yml` locally with PyYAML --- * -> #14652 * #14651
132 lines
4.1 KiB
Rust
132 lines
4.1 KiB
Rust
use std::sync::Arc;
|
|
|
|
use crate::codex::TurnContext;
|
|
use crate::protocol::EventMsg;
|
|
use crate::protocol::UndoCompletedEvent;
|
|
use crate::protocol::UndoStartedEvent;
|
|
use crate::state::TaskKind;
|
|
use crate::tasks::SessionTask;
|
|
use crate::tasks::SessionTaskContext;
|
|
use async_trait::async_trait;
|
|
use codex_git::RestoreGhostCommitOptions;
|
|
use codex_git::restore_ghost_commit_with_options;
|
|
use codex_protocol::models::ResponseItem;
|
|
use codex_protocol::user_input::UserInput;
|
|
use tokio_util::sync::CancellationToken;
|
|
use tracing::error;
|
|
use tracing::info;
|
|
use tracing::warn;
|
|
|
|
pub(crate) struct UndoTask;
|
|
|
|
impl UndoTask {
|
|
pub(crate) fn new() -> Self {
|
|
Self
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl SessionTask for UndoTask {
|
|
fn kind(&self) -> TaskKind {
|
|
TaskKind::Regular
|
|
}
|
|
|
|
fn span_name(&self) -> &'static str {
|
|
"session_task.undo"
|
|
}
|
|
|
|
async fn run(
|
|
self: Arc<Self>,
|
|
session: Arc<SessionTaskContext>,
|
|
ctx: Arc<TurnContext>,
|
|
_input: Vec<UserInput>,
|
|
cancellation_token: CancellationToken,
|
|
) -> Option<String> {
|
|
let _ = session.session.services.session_telemetry.counter(
|
|
"codex.task.undo",
|
|
/*inc*/ 1,
|
|
&[],
|
|
);
|
|
let sess = session.clone_session();
|
|
sess.send_event(
|
|
ctx.as_ref(),
|
|
EventMsg::UndoStarted(UndoStartedEvent {
|
|
message: Some("Undo in progress...".to_string()),
|
|
}),
|
|
)
|
|
.await;
|
|
|
|
if cancellation_token.is_cancelled() {
|
|
sess.send_event(
|
|
ctx.as_ref(),
|
|
EventMsg::UndoCompleted(UndoCompletedEvent {
|
|
success: false,
|
|
message: Some("Undo cancelled.".to_string()),
|
|
}),
|
|
)
|
|
.await;
|
|
return None;
|
|
}
|
|
|
|
let history = sess.clone_history().await;
|
|
let mut items = history.raw_items().to_vec();
|
|
let mut completed = UndoCompletedEvent {
|
|
success: false,
|
|
message: None,
|
|
};
|
|
|
|
let Some((idx, ghost_commit)) =
|
|
items
|
|
.iter()
|
|
.enumerate()
|
|
.rev()
|
|
.find_map(|(idx, item)| match item {
|
|
ResponseItem::GhostSnapshot { ghost_commit } => {
|
|
Some((idx, ghost_commit.clone()))
|
|
}
|
|
_ => None,
|
|
})
|
|
else {
|
|
completed.message = Some("No ghost snapshot available to undo.".to_string());
|
|
sess.send_event(ctx.as_ref(), EventMsg::UndoCompleted(completed))
|
|
.await;
|
|
return None;
|
|
};
|
|
|
|
let commit_id = ghost_commit.id().to_string();
|
|
let repo_path = ctx.cwd.clone();
|
|
let ghost_snapshot = ctx.ghost_snapshot.clone();
|
|
let restore_result = tokio::task::spawn_blocking(move || {
|
|
let options = RestoreGhostCommitOptions::new(&repo_path).ghost_snapshot(ghost_snapshot);
|
|
restore_ghost_commit_with_options(&options, &ghost_commit)
|
|
})
|
|
.await;
|
|
|
|
match restore_result {
|
|
Ok(Ok(())) => {
|
|
items.remove(idx);
|
|
let reference_context_item = sess.reference_context_item().await;
|
|
sess.replace_history(items, reference_context_item).await;
|
|
let short_id: String = commit_id.chars().take(7).collect();
|
|
info!(commit_id = commit_id, "Undo restored ghost snapshot");
|
|
completed.success = true;
|
|
completed.message = Some(format!("Undo restored snapshot {short_id}."));
|
|
}
|
|
Ok(Err(err)) => {
|
|
let message = format!("Failed to restore snapshot {commit_id}: {err}");
|
|
warn!("{message}");
|
|
completed.message = Some(message);
|
|
}
|
|
Err(err) => {
|
|
let message = format!("Failed to restore snapshot {commit_id}: {err}");
|
|
error!("{message}");
|
|
completed.message = Some(message);
|
|
}
|
|
}
|
|
|
|
sess.send_event(ctx.as_ref(), EventMsg::UndoCompleted(completed))
|
|
.await;
|
|
None
|
|
}
|
|
}
|