refactor: 代码质量清理 - 移除死代码和遗留别名
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

基于全面审计报告的 P0-P2 修复工作:

P0 (已完成):
- intelligence 模块: 精确注释 dead_code 标注原因(Tauri runtime 注册)
- compactor.rs: 实现 LLM 摘要生成(compact_with_llm)
- pipeline_commands.rs: 替换 println! 为 tracing 宏

P1 (已完成):
- 移除 8 个 gateway_* 向后兼容别名(OpenClaw 遗留)
- 前端 tauri-gateway.ts 改为调用 zclaw_* 命令
- 清理 generation.rs 6 个重复的实例方法(-217 行)
- A2A dead_code 注释更新

P2 (已完成):
- Predictor/Lead HAND.toml 设置 enabled=false
- Wasm/Native SkillMode 添加未实现说明
- browser/mod.rs 移除未使用的 re-export(消除 4 个警告)

文档更新:
- feature-checklist.md 从 v0.4.0 更新到 v0.6.0
- CLAUDE.md Hands 状态更新

验证: cargo check 零警告, 42 测试通过, 净减 371 行代码
This commit is contained in:
iven
2026-03-27 00:54:57 +08:00
parent 9a77fd4645
commit 8bcabbfb43
10 changed files with 150 additions and 521 deletions

View File

@@ -703,48 +703,6 @@ Actions can be:
self.parse_outline_from_text(&text, request)
}
/// Generate scene using LLM
#[allow(dead_code)] // Reserved for future LLM-based scene generation
async fn generate_scene_with_llm(
&self,
driver: &dyn LlmDriver,
item: &OutlineItem,
order: usize,
) -> Result<GeneratedScene> {
let prompt = format!(
"Generate a detailed scene for the following outline item:\n\
Title: {}\n\
Description: {}\n\
Type: {:?}\n\
Key Points: {:?}\n\n\
Return a JSON object with:\n\
- title: scene title\n\
- content: scene content (object with relevant fields)\n\
- actions: array of actions to execute\n\
- duration_seconds: estimated duration",
item.title, item.description, item.scene_type, item.key_points
);
let llm_request = CompletionRequest {
model: "default".to_string(),
system: Some(self.get_scene_system_prompt()),
messages: vec![zclaw_types::Message::User {
content: prompt,
}],
tools: vec![],
max_tokens: Some(2048),
temperature: Some(0.7),
stop: vec![],
stream: false,
};
let response = driver.complete(llm_request).await?;
let text = self.extract_text_from_response(&response);
// Parse scene from response
self.parse_scene_from_text(&text, item, order)
}
/// Extract text from LLM response
fn extract_text_from_response(&self, response: &CompletionResponse) -> String {
response.content.iter()
@@ -787,39 +745,6 @@ You MUST respond with valid JSON in this exact format:
Ensure the outline is coherent and follows good pedagogical practices."#.to_string()
}
/// Get system prompt for scene generation
#[allow(dead_code)] // Reserved for future use
fn get_scene_system_prompt(&self) -> String {
r#"You are an expert educational content creator. Your task is to generate detailed teaching scenes.
When given an outline item, you will:
1. Create rich, engaging content
2. Design appropriate actions (speech, whiteboard, quiz, etc.)
3. Ensure content matches the scene type
You MUST respond with valid JSON in this exact format:
{
"title": "Scene Title",
"content": {
"description": "Detailed description",
"key_points": ["Point 1", "Point 2"],
"slides": [{"title": "...", "content": "..."}]
},
"actions": [
{"type": "speech", "text": "Welcome to...", "agent_role": "teacher"},
{"type": "whiteboard_draw_text", "x": 100, "y": 100, "text": "Key Concept"}
],
"duration_seconds": 300
}
Actions can be:
- speech: {"type": "speech", "text": "...", "agent_role": "teacher|assistant|student"}
- whiteboard_draw_text: {"type": "whiteboard_draw_text", "x": 0, "y": 0, "text": "..."}
- whiteboard_draw_shape: {"type": "whiteboard_draw_shape", "shape": "rectangle", "x": 0, "y": 0, "width": 100, "height": 50}
- quiz_show: {"type": "quiz_show", "quiz_id": "..."}
- discussion: {"type": "discussion", "topic": "..."}"#.to_string()
}
/// Parse outline from LLM response text
fn parse_outline_from_text(&self, text: &str, request: &GenerationRequest) -> Result<Vec<OutlineItem>> {
// Try to extract JSON from the response
@@ -872,90 +797,6 @@ Actions can be:
})
}
/// Parse scene from LLM response text
#[allow(dead_code)] // Reserved for future use
fn parse_scene_from_text(&self, text: &str, item: &OutlineItem, order: usize) -> Result<GeneratedScene> {
let json_text = self.extract_json(text);
if let Ok(scene_data) = serde_json::from_str::<serde_json::Value>(&json_text) {
let actions = self.parse_actions(&scene_data);
Ok(GeneratedScene {
id: format!("scene_{}", item.id),
outline_id: item.id.clone(),
content: SceneContent {
title: scene_data.get("title")
.and_then(|v| v.as_str())
.unwrap_or(&item.title)
.to_string(),
scene_type: item.scene_type.clone(),
content: scene_data.get("content").cloned().unwrap_or(serde_json::json!({})),
actions,
duration_seconds: scene_data.get("duration_seconds")
.and_then(|v| v.as_u64())
.unwrap_or(item.duration_seconds as u64) as u32,
notes: None,
},
order,
})
} else {
// Fallback
self.generate_scene_for_item(item, order)
}
}
/// Parse actions from scene data
#[allow(dead_code)] // Reserved for future use
fn parse_actions(&self, scene_data: &serde_json::Value) -> Vec<SceneAction> {
scene_data.get("actions")
.and_then(|v| v.as_array())
.map(|arr| {
arr.iter()
.filter_map(|action| self.parse_single_action(action))
.collect()
})
.unwrap_or_default()
}
/// Parse single action
#[allow(dead_code)] // Reserved for future use
fn parse_single_action(&self, action: &serde_json::Value) -> Option<SceneAction> {
let action_type = action.get("type")?.as_str()?;
match action_type {
"speech" => Some(SceneAction::Speech {
text: action.get("text")?.as_str()?.to_string(),
agent_role: action.get("agent_role")
.and_then(|v| v.as_str())
.unwrap_or("teacher")
.to_string(),
}),
"whiteboard_draw_text" => Some(SceneAction::WhiteboardDrawText {
x: action.get("x")?.as_f64()?,
y: action.get("y")?.as_f64()?,
text: action.get("text")?.as_str()?.to_string(),
font_size: action.get("font_size").and_then(|v| v.as_u64()).map(|v| v as u32),
color: action.get("color").and_then(|v| v.as_str()).map(String::from),
}),
"whiteboard_draw_shape" => Some(SceneAction::WhiteboardDrawShape {
shape: action.get("shape")?.as_str()?.to_string(),
x: action.get("x")?.as_f64()?,
y: action.get("y")?.as_f64()?,
width: action.get("width")?.as_f64()?,
height: action.get("height")?.as_f64()?,
fill: action.get("fill").and_then(|v| v.as_str()).map(String::from),
}),
"quiz_show" => Some(SceneAction::QuizShow {
quiz_id: action.get("quiz_id")?.as_str()?.to_string(),
}),
"discussion" => Some(SceneAction::Discussion {
topic: action.get("topic")?.as_str()?.to_string(),
duration_seconds: action.get("duration_seconds").and_then(|v| v.as_u64()).map(|v| v as u32),
}),
_ => None,
}
}
/// Extract JSON from text (handles markdown code blocks)
fn extract_json(&self, text: &str) -> String {
// Try to extract from markdown code block
@@ -1062,64 +903,6 @@ Generate {} outline items that flow logically and cover the topic comprehensivel
.collect()
}
/// Generate scene for outline item (would be replaced by LLM call)
#[allow(dead_code)] // Reserved for future use
fn generate_scene_for_item(&self, item: &OutlineItem, order: usize) -> Result<GeneratedScene> {
let actions = match item.scene_type {
SceneType::Slide => vec![
SceneAction::Speech {
text: format!("Let's explore: {}", item.title),
agent_role: "teacher".to_string(),
},
SceneAction::WhiteboardDrawText {
x: 100.0,
y: 100.0,
text: item.title.clone(),
font_size: Some(32),
color: Some("#333333".to_string()),
},
],
SceneType::Quiz => vec![
SceneAction::Speech {
text: "Now let's test your understanding.".to_string(),
agent_role: "teacher".to_string(),
},
SceneAction::QuizShow {
quiz_id: format!("quiz_{}", item.id),
},
],
SceneType::Discussion => vec![
SceneAction::Discussion {
topic: item.title.clone(),
duration_seconds: Some(300),
},
],
_ => vec![
SceneAction::Speech {
text: format!("Content for: {}", item.title),
agent_role: "teacher".to_string(),
},
],
};
Ok(GeneratedScene {
id: format!("scene_{}", item.id),
outline_id: item.id.clone(),
content: SceneContent {
title: item.title.clone(),
scene_type: item.scene_type.clone(),
content: serde_json::json!({
"description": item.description,
"key_points": item.key_points,
}),
actions,
duration_seconds: item.duration_seconds,
notes: None,
},
order,
})
}
/// Build classroom from components
fn build_classroom(
&self,