配置: - rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化 - Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则 - .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI - Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features - web: eslint flat config + prettier 配置 + package.json 脚本与依赖 - src/main.rs: loop→while 修复 clippy::never_loop 对抗性审查发现并修复: - eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error - 前端 lint 未接入 CI,现已补上 Lint 步骤 - Makefile 与 CI 的 clippy flags 不一致,已对齐
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
use crate::command::Command;
|
|
use crate::command::context::CommandContext;
|
|
use crate::command::handler::{CommandHandler, CommandMetadata};
|
|
use crate::command::response::{CommandError, CommandResponse};
|
|
use crate::storage::SessionStore;
|
|
use async_trait::async_trait;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::sync::Arc;
|
|
|
|
/// Memory 摘要信息(发送给前端)
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct MemorySummary {
|
|
pub id: String,
|
|
pub namespace: String,
|
|
pub memory_key: String,
|
|
pub content: String,
|
|
pub created_at: i64,
|
|
pub updated_at: i64,
|
|
}
|
|
|
|
pub struct ListMemoriesCommandHandler {
|
|
store: Arc<SessionStore>,
|
|
}
|
|
|
|
impl ListMemoriesCommandHandler {
|
|
pub fn new(store: Arc<SessionStore>) -> Self {
|
|
Self { store }
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl CommandHandler for ListMemoriesCommandHandler {
|
|
fn can_handle(&self, cmd: &Command) -> bool {
|
|
matches!(cmd, Command::ListMemories)
|
|
}
|
|
|
|
fn metadata(&self) -> Option<CommandMetadata> {
|
|
Some(CommandMetadata {
|
|
name: "list_memories",
|
|
description: "列出所有记忆",
|
|
usage: "/list_memories",
|
|
})
|
|
}
|
|
|
|
async fn handle(
|
|
&self,
|
|
_cmd: Command,
|
|
ctx: CommandContext,
|
|
) -> Result<CommandResponse, CommandError> {
|
|
let records = self
|
|
.store
|
|
.list_memories_for_scope("user", crate::storage::GLOBAL_SCOPE_KEY)
|
|
.map_err(|e| CommandError::new("LIST_MEMORIES_ERROR", e.to_string()))?;
|
|
|
|
let summaries: Vec<MemorySummary> = records
|
|
.into_iter()
|
|
.filter(|m| m.namespace != "_meta")
|
|
.map(|m| MemorySummary {
|
|
id: m.id,
|
|
namespace: m.namespace,
|
|
memory_key: m.memory_key,
|
|
content: m.content,
|
|
created_at: m.created_at,
|
|
updated_at: m.updated_at,
|
|
})
|
|
.collect();
|
|
|
|
let memories_json = serde_json::to_string(&summaries)
|
|
.map_err(|e| CommandError::new("SERIALIZE_ERROR", e.to_string()))?;
|
|
|
|
Ok(CommandResponse::success(ctx.request_id).with_metadata("memories", &memories_json))
|
|
}
|
|
}
|