1
0

update lexicon

This commit is contained in:
2026-03-01 15:40:09 +09:00
parent 3365e7634d
commit 28eeb2be4d
8 changed files with 314 additions and 59 deletions

View File

@@ -1,16 +1,16 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use aigpt::core::{reader, writer};
use aigpt::core::{config, reader, writer};
use aigpt::mcp::MCPServer;
#[derive(Parser)]
#[command(name = "aigpt")]
#[command(about = "AI memory MCP server - read/write core.md and memory.md")]
#[command(about = "AI memory MCP server")]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Commands,
command: Option<Commands>,
}
#[derive(Subcommand)]
@@ -18,13 +18,13 @@ enum Commands {
/// Start MCP server (JSON-RPC over stdio)
Server,
/// Read core.md
/// Read core.json
ReadCore,
/// Read memory.md
/// Read latest memory record
ReadMemory,
/// Save content to memory.md
/// Create new memory record
SaveMemory {
/// Content to write
content: String,
@@ -32,29 +32,70 @@ enum Commands {
}
fn main() -> Result<()> {
config::init();
let cli = Cli::parse();
match cli.command {
Commands::Server => {
None => {
print_status();
}
Some(Commands::Server) => {
let server = MCPServer::new();
server.run()?;
}
Commands::ReadCore => {
let content = reader::read_core()?;
print!("{}", content);
Some(Commands::ReadCore) => {
let record = reader::read_core()?;
println!("{}", serde_json::to_string_pretty(&record)?);
}
Commands::ReadMemory => {
let content = reader::read_memory()?;
print!("{}", content);
Some(Commands::ReadMemory) => {
match reader::read_memory()? {
Some(record) => println!("{}", serde_json::to_string_pretty(&record)?),
None => println!("No memory records found"),
}
}
Commands::SaveMemory { content } => {
Some(Commands::SaveMemory { content }) => {
writer::save_memory(&content)?;
println!("Saved to memory.md");
println!("Saved.");
}
}
Ok(())
}
fn print_status() {
let cfg = config::load();
let did = cfg.did.clone().unwrap_or_else(|| "self".to_string());
let handle = cfg.handle.clone().unwrap_or_else(|| "self".to_string());
let base = config::base_dir(&cfg);
let id = config::identity(&cfg);
let memory_dir = config::collection_dir(&cfg, "ai.syui.gpt.memory");
let memory_count = std::fs::read_dir(&memory_dir)
.map(|entries| {
entries
.filter_map(|e| e.ok())
.filter(|e| e.path().extension().is_some_and(|ext| ext == "json"))
.count()
})
.unwrap_or(0);
let latest_version = match reader::read_memory() {
Ok(Some(record)) => record["value"]["version"].as_u64().unwrap_or(0),
_ => 0,
};
println!("aigpt - AI memory MCP server\n");
println!("config: {}", config::config_file().display());
println!("did: {}", did);
println!("handle: {}", handle);
println!();
println!("path: {}/", base.display());
println!(" {}/{}", id, "ai.syui.gpt.core/self.json");
println!(" {}/{}", id, "ai.syui.gpt.memory/*.json");
println!();
println!("memory: {} records (version: {})", memory_count, latest_version);
}