docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment guidelines: delete redundant restatements, decorative banners, change narration, and end-of-line comments; keep and tighten the crucial ones (invariants, bug rationale, SAFETY blocks, ported-source attribution). No functional code changed. Every edit is proven comment-only against the prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a separate doctest-fence check. Where removing a comment made rustfmt or clippy want to re-lay-out adjacent code, the minimal triggering comment is restored so code tokens stay byte-identical. Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy --workspace --all-targets (0 warnings). Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for these guidelines (flags banners, end-of-line comments, change narration, and commented-out code).
This commit is contained in:
@@ -78,7 +78,8 @@ mod acp_send_failure_tests {
|
||||
#[tokio::test]
|
||||
async fn send_failed_when_receiver_dropped_before_send() {
|
||||
let (tx, rx) = mpsc::unbounded_channel::<AcpAgentMessage>();
|
||||
drop(rx); // no peer listening -> enqueue fails
|
||||
// no peer listening -> enqueue fails
|
||||
drop(rx);
|
||||
let err = acp_send(ext_request(), &tx).await.unwrap_err();
|
||||
assert_eq!(
|
||||
acp_channel_failure(&err),
|
||||
|
||||
@@ -20,24 +20,24 @@ pub fn acp_internal_error(message: impl Into<String>) -> acp::Error {
|
||||
|
||||
/// The two distinct ways an [`acp_send`](crate::acp_send) round-trip can fail
|
||||
/// when the underlying channel is closed. Both surface as a JSON-RPC
|
||||
/// `INTERNAL_ERROR` (so existing callers and the wire format are unaffected);
|
||||
/// this typed discriminant — carried in the error's `data` — lets callers tell
|
||||
/// them apart WITHOUT substring-matching the human-readable `message`.
|
||||
/// `INTERNAL_ERROR`; this typed discriminant — carried in the error's `data` —
|
||||
/// lets callers tell them apart without substring-matching the human-readable
|
||||
/// `message`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AcpChannelFailure {
|
||||
/// The request could not be ENQUEUED: the receiver half (the peer's
|
||||
/// The request could not be enqueued: the receiver half (the peer's
|
||||
/// connection task) is already gone, so no peer is listening — e.g. a
|
||||
/// headless run with no client wired.
|
||||
SendFailed,
|
||||
/// The request was enqueued but the RESPONSE channel was dropped before a
|
||||
/// The request was enqueued but the response channel was dropped before a
|
||||
/// reply arrived: a peer received the request, then went away (disconnect /
|
||||
/// process exit) without answering.
|
||||
RecvFailed,
|
||||
}
|
||||
|
||||
impl AcpChannelFailure {
|
||||
/// `data` object key under which [`acp_send`](crate::acp_send) records the
|
||||
/// kind. Namespaced so it can never collide with other `with_data` payloads.
|
||||
/// `data` object key under which the kind is recorded. Namespaced so it can
|
||||
/// never collide with other `with_data` payloads.
|
||||
const DATA_KEY: &'static str = "xaiAcpChannelFailure";
|
||||
|
||||
const fn tag(self) -> &'static str {
|
||||
@@ -58,8 +58,8 @@ impl AcpChannelFailure {
|
||||
|
||||
/// Build the channel-closed error for [`acp_send`](crate::acp_send), tagging it
|
||||
/// with a typed [`AcpChannelFailure`] discriminant in `data`. The error `code`
|
||||
/// stays `INTERNAL_ERROR`, so this is purely additive for callers that just
|
||||
/// propagate the error.
|
||||
/// stays `INTERNAL_ERROR` so callers that merely propagate the error are
|
||||
/// unaffected.
|
||||
pub(crate) fn acp_channel_failure_error(
|
||||
message: impl Into<String>,
|
||||
kind: AcpChannelFailure,
|
||||
@@ -68,8 +68,8 @@ pub(crate) fn acp_channel_failure_error(
|
||||
}
|
||||
|
||||
/// Recover the [`AcpChannelFailure`] kind from an error, or `None` if the error
|
||||
/// did not originate from [`acp_send`](crate::acp_send)'s channel-closed paths
|
||||
/// (or predates the tag). Consumers use this instead of inspecting `message`.
|
||||
/// did not originate from [`acp_send`](crate::acp_send)'s channel-closed paths.
|
||||
/// Consumers use this instead of inspecting `message`.
|
||||
pub fn acp_channel_failure(err: &acp::Error) -> Option<AcpChannelFailure> {
|
||||
err.data
|
||||
.as_ref()
|
||||
@@ -78,10 +78,9 @@ pub fn acp_channel_failure(err: &acp::Error) -> Option<AcpChannelFailure> {
|
||||
.and_then(AcpChannelFailure::from_tag)
|
||||
}
|
||||
|
||||
/// Compact single-line JSON for gateway debug traces. Plain (uncolored)
|
||||
/// output: this feeds `tracing::debug!`, which typically lands in log files
|
||||
/// where ANSI colors are noise. Replaces the former `colored_json`-backed
|
||||
/// `color_json` (dropped to shrink the shipped dependency tree).
|
||||
/// Compact single-line JSON for gateway debug traces. Output is uncolored: it
|
||||
/// feeds `tracing::debug!`, which typically lands in log files where ANSI
|
||||
/// escapes are noise.
|
||||
#[doc(hidden)]
|
||||
pub fn compact_json<T: serde::Serialize>(value: &T) -> String {
|
||||
serde_json::to_string(value).unwrap_or_default()
|
||||
|
||||
@@ -613,7 +613,8 @@ mod tests {
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Gate-open point; then concurrent producer emits live updates.
|
||||
// Phase 2: a concurrent producer emits live updates while the
|
||||
// replay completions are still draining.
|
||||
let live_sender = sender.clone();
|
||||
let producer = tokio::task::spawn_local(async move {
|
||||
for i in 0..LIVE {
|
||||
@@ -624,15 +625,14 @@ mod tests {
|
||||
}
|
||||
});
|
||||
|
||||
// Drain replay completions while producer runs.
|
||||
for rx in completions {
|
||||
let _ = rx.await;
|
||||
}
|
||||
|
||||
// Mark response boundary.
|
||||
log.borrow_mut().push("RESPONSE".into());
|
||||
|
||||
// Let producer and gateway finish remaining live updates.
|
||||
// Give the producer and the gateway loop room to flush the
|
||||
// remaining live updates before inspecting the log.
|
||||
let _ = producer.await;
|
||||
for _ in 0..LIVE + 5 {
|
||||
tokio::task::yield_now().await;
|
||||
@@ -644,7 +644,6 @@ mod tests {
|
||||
.position(|s| s == "RESPONSE")
|
||||
.expect("RESPONSE marker must be in the log");
|
||||
|
||||
// (1) Delta notifications are all present and before RESPONSE.
|
||||
for i in 0..DELTA {
|
||||
let tag = format!("delta-{i}");
|
||||
let pos = log
|
||||
@@ -657,7 +656,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// (2) Delta notifications preserve enqueue order.
|
||||
let delta_positions: Vec<usize> = (0..DELTA)
|
||||
.map(|i| log.iter().position(|s| s == &format!("delta-{i}")).unwrap())
|
||||
.collect();
|
||||
@@ -670,7 +668,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// (3) No live updates are lost.
|
||||
for i in 0..LIVE {
|
||||
let tag = format!("live-{i}");
|
||||
assert!(
|
||||
@@ -679,7 +676,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// (4) Live updates do not precede replay delta.
|
||||
let last_delta = *delta_positions.last().unwrap();
|
||||
for i in 0..LIVE {
|
||||
let tag = format!("live-{i}");
|
||||
|
||||
@@ -126,7 +126,7 @@ impl AsyncRead for LineBufferedRead {
|
||||
Poll::Ready(Ok(n))
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => Poll::Ready(Err(e)),
|
||||
Poll::Ready(None) => Poll::Ready(Ok(0)), // EOF
|
||||
Poll::Ready(None) => Poll::Ready(Ok(0)),
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ async fn read_line_capped(
|
||||
let (consumed, done) = {
|
||||
let available = reader.fill_buf().await?;
|
||||
if available.is_empty() {
|
||||
return Ok(buf.len()); // EOF
|
||||
return Ok(buf.len());
|
||||
}
|
||||
match available.iter().position(|&b| b == b'\n') {
|
||||
Some(pos) => {
|
||||
@@ -283,15 +283,12 @@ mod tests {
|
||||
let mut reader = LineBufferedRead::spawn_local(source);
|
||||
let mut small_buf = [0u8; 3];
|
||||
|
||||
// First read: "abc"
|
||||
let n = reader.read(&mut small_buf).await.unwrap();
|
||||
assert_eq!(&small_buf[..n], b"abc");
|
||||
|
||||
// Second read: "def"
|
||||
let n = reader.read(&mut small_buf).await.unwrap();
|
||||
assert_eq!(&small_buf[..n], b"def");
|
||||
|
||||
// Third read: "\n"
|
||||
let n = reader.read(&mut small_buf).await.unwrap();
|
||||
assert_eq!(&small_buf[..n], b"\n");
|
||||
|
||||
|
||||
@@ -26,16 +26,20 @@ pub trait AcpSide {
|
||||
|
||||
/// Marker type representing the agent's view of the ACP connection (as one side of that connection).
|
||||
impl AcpSide for acp::AgentSide {
|
||||
type InMessage = AcpAgentMessage; // inbound messages = messages meant *for* the agent
|
||||
type OutMessage = AcpClientMessage; // outbound messages = messages meant *for* the client
|
||||
// inbound messages = messages meant *for* the agent
|
||||
type InMessage = AcpAgentMessage;
|
||||
// outbound messages = messages meant *for* the client
|
||||
type OutMessage = AcpClientMessage;
|
||||
type OtherSide = acp::ClientSide;
|
||||
const NAME: &'static str = "agent";
|
||||
}
|
||||
|
||||
/// Marker type representing the agent's view of the ACP connection (as one side of that connection).
|
||||
impl AcpSide for acp::ClientSide {
|
||||
type InMessage = AcpClientMessage; // inbound messages = messages meant *for* the client
|
||||
type OutMessage = AcpAgentMessage; // outbound messages = messages meant *for* the agent
|
||||
// inbound messages = messages meant *for* the client
|
||||
type InMessage = AcpClientMessage;
|
||||
// outbound messages = messages meant *for* the agent
|
||||
type OutMessage = AcpAgentMessage;
|
||||
type OtherSide = acp::AgentSide;
|
||||
const NAME: &'static str = "client";
|
||||
}
|
||||
@@ -241,7 +245,8 @@ mod client {
|
||||
|
||||
pub fn route_to_client(
|
||||
self,
|
||||
client: impl acp::Client + 'static, // note: acp::Client is auto-implemented for Rc/Arc
|
||||
// note: acp::Client is auto-implemented for Rc/Arc
|
||||
client: impl acp::Client + 'static,
|
||||
spawn: impl Fn(LocalBoxFuture<'static, ()>) + 'static,
|
||||
) {
|
||||
match self {
|
||||
@@ -540,7 +545,8 @@ mod agent {
|
||||
|
||||
pub fn route_to_agent(
|
||||
self,
|
||||
agent: impl acp::Agent + 'static, // note: acp::Agent is auto-implemented for Rc/Arc
|
||||
// note: acp::Agent is auto-implemented for Rc/Arc
|
||||
agent: impl acp::Agent + 'static,
|
||||
spawn: impl Fn(LocalBoxFuture<'static, ()>) + 'static,
|
||||
) {
|
||||
match self {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
/// `\u2028` and surrogate pairs in text).
|
||||
///
|
||||
/// Any line that fails both parses passes through byte-identical —
|
||||
/// deliberately: the acp crate keeps ownership of garbage handling.
|
||||
/// Deliberately: the acp crate keeps ownership of garbage handling.
|
||||
pub(crate) fn normalize_json_line(line: Vec<u8>) -> Vec<u8> {
|
||||
if !line.windows(2).any(|w| w == br"\/") {
|
||||
return line;
|
||||
|
||||
@@ -138,7 +138,8 @@ fn isolate_process_stdin() -> Option<std::fs::File> {
|
||||
use std::os::windows::io::FromRawHandle as _;
|
||||
|
||||
// Win32 constants (inlined to avoid a dependency).
|
||||
const STD_INPUT_HANDLE: u32 = 0xFFFF_FFF6; // (DWORD)-10
|
||||
// (DWORD)-10
|
||||
const STD_INPUT_HANDLE: u32 = 0xFFFF_FFF6;
|
||||
const DUPLICATE_SAME_ACCESS: u32 = 0x0000_0002;
|
||||
const GENERIC_READ: u32 = 0x8000_0000;
|
||||
const FILE_SHARE_READ: u32 = 0x0000_0001;
|
||||
@@ -186,7 +187,8 @@ fn isolate_process_stdin() -> Option<std::fs::File> {
|
||||
process,
|
||||
&mut duplicate,
|
||||
0,
|
||||
0, // not inheritable
|
||||
// not inheritable
|
||||
0,
|
||||
DUPLICATE_SAME_ACCESS,
|
||||
) == 0
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user