feat(M4.1): Add mem skill draft CLI command with integration tests
Adds command to generate SKILL.md drafts from memory notes:
Files modified:
crates/mem-cli/src/main.rs
- Add SkillCommand enum with Draft variant
- Add Commands::Skill variant to Commands enum
- Add cmd_skill_draft() handler function
- Parse project/query-id input
- Generate SKILL.md with YAML frontmatter
- Include name, description, when_to_use fields
- Include generated_from: <sha> provenance
- Include generated_at: <timestamp>
- Support --dry-run flag (print without writing)
- Enforce _drafts/ directory (no direct skills/ writes)
- Create directory structure automatically
Files created:
tests/it_skill_draft.rs
- 7 unit tests (all passing):
a1: Parses input format (project/query-id)
a2: Rejects invalid formats (wrong separators, empty)
a3: Creates _drafts directory structure
a4: Generates YAML frontmatter with all required fields
a5: Includes generated_from provenance link
a6: Enforces _drafts/ directory (not skills/)
a7: Dry-run mode doesn't write files
Status:
✓ All 7 tests pass
✓ Command works end-to-end (tested manually)
✓ Dry-run mode verified
✓ Directory enforcement working
Next (TODO in code):
- Read L1/L2 memory node from database
- Use LLM to convert descriptive → procedural memory
- Retrieve real sha256 from memory_node (replace placeholder)
- Skill authoring rubric in LLM prompt (name, description, when_to_use)
Blocks: M4.2 (cycle guard), M4.3 (gate)
Depends: M3.4 ✓ (composition gate)
This commit is contained in:
@@ -20,6 +20,20 @@ struct Cli {
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum SkillCommand {
|
||||
/// Generate draft skill from L1/L2 memory note
|
||||
Draft {
|
||||
/// Memory note to convert (format: project/query-id)
|
||||
#[arg(long, value_name = "PROJECT/QUERY_ID")]
|
||||
from: String,
|
||||
|
||||
/// Dry run (print without writing)
|
||||
#[arg(long)]
|
||||
dry_run: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Count tokens in a file
|
||||
@@ -115,6 +129,12 @@ enum Commands {
|
||||
explain: bool,
|
||||
},
|
||||
|
||||
/// Generate skill draft from memory note
|
||||
Skill {
|
||||
#[command(subcommand)]
|
||||
command: SkillCommand,
|
||||
},
|
||||
|
||||
/// Start HTTP server
|
||||
Serve {
|
||||
#[arg(long, default_value = "8080")]
|
||||
@@ -166,6 +186,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
Commands::Query { question, project, levels, k, format, explain } => {
|
||||
cmd_query(&question, project.as_deref(), &levels, k, &format, explain).await?
|
||||
}
|
||||
Commands::Skill { command } => {
|
||||
match command {
|
||||
SkillCommand::Draft { from, dry_run } => {
|
||||
cmd_skill_draft(&from, dry_run).await?
|
||||
}
|
||||
}
|
||||
}
|
||||
Commands::Serve { port, api_key, database_url } => {
|
||||
let api_key = api_key.unwrap_or_else(|| std::env::var("MEM_API_KEY").unwrap_or_else(|_| "test-key".to_string()));
|
||||
let database_url = database_url.unwrap_or_else(|| std::env::var("DATABASE_URL").unwrap_or_else(|_| "postgresql://app:poimen@localhost:5432/memory".to_string()));
|
||||
@@ -411,3 +438,69 @@ async fn cmd_query(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn cmd_skill_draft(from: &str, dry_run: bool) -> anyhow::Result<()> {
|
||||
use mem_llm::ChatClient;
|
||||
use std::path::Path;
|
||||
use chrono::Utc;
|
||||
|
||||
// Parse input: project/query-id
|
||||
let parts: Vec<&str> = from.split('/').collect();
|
||||
if parts.len() != 2 {
|
||||
anyhow::bail!("Format: project/query-id (got: {})", from);
|
||||
}
|
||||
|
||||
let project = parts[0];
|
||||
let query_id = parts[1];
|
||||
|
||||
println!("\n📝 Generating skill draft from {}/{}", project, query_id);
|
||||
println!(" Dry run: {}", if dry_run { "yes" } else { "no" });
|
||||
println!(" ---");
|
||||
|
||||
// TODO: Implement full skill draft logic
|
||||
// 1. Read L1/L2 memory node from database
|
||||
// 2. Use LLM to convert descriptive → procedural with rubric prompt
|
||||
// 3. Generate frontmatter with name, description, when_to_use, generated_from
|
||||
// 4. Write to vault/skills/_drafts/<project>-<query-id>/SKILL.md
|
||||
|
||||
// For now, placeholder
|
||||
let skill_name = format!("{}-{}", project, query_id);
|
||||
let skill_dir = format!("vault/skills/_drafts/{}", skill_name);
|
||||
let skill_file = format!("{}/SKILL.md", skill_dir);
|
||||
|
||||
let frontmatter = format!(
|
||||
r#"---
|
||||
name: {}
|
||||
description: "[DRAFT] Skill derived from {} memory node"
|
||||
when_to_use: "Use when working with {}..."
|
||||
generated_from: "<sha256-placeholder>"
|
||||
generated_at: "{}"
|
||||
---
|
||||
|
||||
# {} Skill
|
||||
|
||||
[Draft content would go here]
|
||||
"#,
|
||||
skill_name,
|
||||
query_id,
|
||||
project,
|
||||
Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
skill_name
|
||||
);
|
||||
|
||||
if dry_run {
|
||||
println!("\n[DRY RUN] Would write to: {}", skill_file);
|
||||
println!("\nContent preview:");
|
||||
println!("{}", frontmatter);
|
||||
} else {
|
||||
std::fs::create_dir_all(&skill_dir)?;
|
||||
std::fs::write(&skill_file, &frontmatter)?;
|
||||
println!("\n✓ Skill draft written to: {}", skill_file);
|
||||
println!("\nNext steps:");
|
||||
println!(" 1. Edit {} to refine the skill", skill_file);
|
||||
println!(" 2. Review with grafana-core:skill-authoring rubric");
|
||||
println!(" 3. git mv {} vault/skills/{} (to promote)", skill_dir, skill_name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user