use serde_json::{Map, Value, json};
const REVIEW_DESCRIPTION: &str = "Review code changes: specialist reviewer frames, then a verifier per finding";
const MCP_DESCRIPTION: &str = "MCP servers: status, connect or disconnect, sign in, enable or disable";
fn entry(name: &str, description: Option<&str>, source: &str, info: Option<Value>) -> Value {
let mut out = Map::new();
out.insert("name".into(), name.into());
if let Some(description) = description {
out.insert("description".into(), description.into());
}
out.insert("source".into(), source.into());
if let Some(info) = info {
out.insert("sourceInfo".into(), info);
}
Value::Object(out)
}
pub fn list_commands_with(
cwd: &str,
agent_dir: &str,
bundled: Option<&str>,
extra: &crate::session_resources::SessionResources,
) -> Vec<Value> {
let mut commands: Vec<Value> = vec![mcp_command()];
commands.push(entry("review", Some(REVIEW_DESCRIPTION), "prompt", None));
commands.push(entry(
"observer",
Some("Manage the conversation observer"),
"extension",
None,
));
for template in crate::session_resources::prompts(cwd, agent_dir, extra) {
let info = crate::session_resources::prompt_source_info(extra, &template, cwd, agent_dir);
commands.push(entry(&template.name, Some(&template.description), "prompt", Some(info)));
}
for skill in crate::session_resources::skills(cwd, agent_dir, extra, false, bundled) {
let info = crate::session_resources::skill_source_info(extra, &skill);
commands.push(entry(
&format!("skill:{}", skill.name),
Some(&skill.description),
"skill",
Some(info),
));
}
commands
}
pub fn mcp_command() -> Value {
let inline = json!({"path": "<inline:mcp>", "source": "inline", "scope": "temporary", "origin": "top-level"});
entry("mcp", Some(MCP_DESCRIPTION), "extension", Some(inline))
}
pub fn command_info(command: &Value) -> Value {
let mut out = Map::new();
out.insert("name".into(), command["name"].clone());
for key in ["description", "sourceInfo"] {
if let Some(value) = command.get(key) {
out.insert(key.into(), value.clone());
}
}
Value::Object(out)
}
pub fn session_command_infos(commands: &[Value]) -> Vec<Value> {
commands
.iter()
.map(|c| {
json!({"name": c["name"], "description": c.get("description").cloned().unwrap_or(Value::Null),
"source": c["source"], "sourceInfo": c.get("sourceInfo").cloned().unwrap_or(Value::Null)})
})
.collect()
}