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).
34 lines
1.2 KiB
Rust
34 lines
1.2 KiB
Rust
use async_trait::async_trait;
|
|
|
|
/// A slash command a contributor advertises; the host maps it onto its own advertising protocol.
|
|
pub struct CommandSpec {
|
|
pub name: String,
|
|
pub description: String,
|
|
pub arg_hint: String,
|
|
}
|
|
|
|
/// A parsed `/name args` invocation. The host owns parsing and routes it to the command's one owner.
|
|
pub struct CommandInvocation<'a> {
|
|
pub name: &'a str,
|
|
// Whitespace-trimmed; empty for a bare `/name`.
|
|
pub args: &'a str,
|
|
}
|
|
|
|
/// What a handled command does to the turn; rejections travel as the `Err` reason.
|
|
pub enum CommandAction {
|
|
/// Replace the model-visible copy of the message with `model_text`.
|
|
Rewrite { model_text: String },
|
|
/// Side effect performed, nothing to say; the state change surfaces through the host's own rendering.
|
|
Acted,
|
|
}
|
|
|
|
/// Handles the slash commands the extension advertises. Only invoked for commands this contributor
|
|
/// owns; the `Err` reason is the only channel for "why not", so hosts must surface it.
|
|
#[async_trait]
|
|
pub trait CommandContributor: Send + Sync {
|
|
fn advertised_commands(&self) -> Vec<CommandSpec>;
|
|
|
|
async fn handle_command(&self, _input: &CommandInvocation<'_>)
|
|
-> Result<CommandAction, String>;
|
|
}
|