Files
Kigi-CLI/crates/codegen/kigi-shell/src/extensions/prompt_meta.rs
T
ZacharyZhang-NY a02b555e66 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).
2026-07-23 16:55:39 -04:00

70 lines
2.2 KiB
Rust

use serde::{Deserialize, Serialize};
/// Typed metadata for a prompt `TextContent._meta` field.
///
/// Replaces ad-hoc `serde_json::json!()` construction on the sender side
/// and manual `.get()` parsing on the receiver side.
///
/// Wire-compatible with the existing format: `{"bash_command": "ls -la"}`
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptBlockMeta {
/// Direct bash command to execute (bypasses agent loop).
#[serde(skip_serializing_if = "Option::is_none")]
pub bash_command: Option<String>,
}
impl PromptBlockMeta {
pub fn bash(command: impl Into<String>) -> Self {
Self {
bash_command: Some(command.into()),
}
}
pub fn from_value(value: &agent_client_protocol::Meta) -> Option<Self> {
serde_json::from_value(serde_json::Value::Object(value.clone())).ok()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bash_roundtrip_serde() {
let meta = PromptBlockMeta::bash("ls -la");
let json = serde_json::to_value(&meta).unwrap();
let parsed: PromptBlockMeta = serde_json::from_value(json).unwrap();
assert_eq!(parsed.bash_command, Some("ls -la".to_string()));
}
#[test]
fn from_value_legacy_compat() {
let val = serde_json::json!({"bash_command": "ls"});
let meta = PromptBlockMeta::from_value(val.as_object().unwrap()).unwrap();
assert_eq!(meta.bash_command, Some("ls".to_string()));
}
#[test]
fn from_value_unrelated_meta() {
let val = serde_json::json!({"other": 1});
let meta = PromptBlockMeta::from_value(val.as_object().unwrap());
assert!(meta.is_some());
assert_eq!(meta.unwrap().bash_command, None);
}
#[test]
fn from_value_empty_object() {
let val = serde_json::json!({});
let meta = PromptBlockMeta::from_value(val.as_object().unwrap());
assert!(meta.is_some());
assert_eq!(meta.unwrap().bash_command, None);
}
#[test]
fn skip_serializing_none() {
let meta = PromptBlockMeta { bash_command: None };
let json = serde_json::to_value(&meta).unwrap();
assert!(!json.as_object().unwrap().contains_key("bash_command"));
}
}