Files
likang 678058c940
CI / Select checks (push) Has been cancelled
CI / Format and repository checks (push) Has been cancelled
CI / Compile RISC-V (manual) (push) Has been cancelled
Docker / image (push) Has been cancelled
Generated files / Regenerate and commit (push) Has been cancelled
Kernel rig / Select the rig areas (push) Has been cancelled
Lists / Design format changes merge cleanly (push) Has been cancelled
Lists / Lists are sorted one item per line (push) Has been cancelled
Packaging lint / lint (push) Has been cancelled
Pages / build (push) Has been cancelled
CI / Dependency advisories (push) Has been cancelled
CI / Quick compile (push) Has been cancelled
CI / Native Linux Clippy (push) Has been cancelled
CI / Build tests (push) Has been cancelled
CI / Native Linux tests (push) Has been cancelled
CI / GPU path tests (1/4) (push) Has been cancelled
CI / GPU path tests (2/4) (push) Has been cancelled
CI / GPU path tests (3/4) (push) Has been cancelled
CI / GPU path tests (4/4) (push) Has been cancelled
CI / Action matrix (1/16) (push) Has been cancelled
CI / Action matrix (10/16) (push) Has been cancelled
CI / Action matrix (11/16) (push) Has been cancelled
CI / Action matrix (12/16) (push) Has been cancelled
CI / Action matrix (13/16) (push) Has been cancelled
CI / Action matrix (14/16) (push) Has been cancelled
CI / Action matrix (15/16) (push) Has been cancelled
CI / Action matrix (16/16) (push) Has been cancelled
CI / Action matrix (2/16) (push) Has been cancelled
CI / Action matrix (3/16) (push) Has been cancelled
CI / Action matrix (4/16) (push) Has been cancelled
CI / Action matrix (5/16) (push) Has been cancelled
CI / Action matrix (6/16) (push) Has been cancelled
CI / Action matrix (7/16) (push) Has been cancelled
CI / Action matrix (8/16) (push) Has been cancelled
CI / Action matrix (9/16) (push) Has been cancelled
CI / Action matrix determinism (push) Has been cancelled
CI / Property tests (many cases) (push) Has been cancelled
CI / Doc tests (push) Has been cancelled
CI / Reference tests (push) Has been cancelled
CI / Windows D3D12 FXC shaders (push) Has been cancelled
CI / Windows app startup (push) Has been cancelled
CI / ci (push) Has been cancelled
CI / Compile WebAssembly (push) Has been cancelled
CI / Nightly alert (push) Has been cancelled
Kernel rig / Build the CLI (push) Has been cancelled
Kernel rig / Kernel rig (${{ matrix.shard }}) (push) Has been cancelled
Kernel rig / kernel-rig (push) Has been cancelled
Pages / deploy (push) Has been cancelled
优化skill
2026-11-16 11:32:34 +08:00

65 lines
2.6 KiB
Rust

//! Embed the complete, sorted skill library without runtime filesystem access.
use std::{
env,
error::Error,
fs,
path::{Path, PathBuf},
};
fn files(directory: &Path) -> Result<Vec<PathBuf>, Box<dyn Error>> {
let mut result = Vec::new();
for entry in fs::read_dir(directory)? {
let entry = entry?;
let kind = entry.file_type()?;
if kind.is_symlink() {
return Err(format!("Skill resources may not be symlinks: {}", entry.path().display()).into());
}
if kind.is_dir() {
result.extend(files(&entry.path())?);
} else if kind.is_file() {
result.push(entry.path());
}
}
result.sort();
Ok(result)
}
pub fn generate() -> Result<(), Box<dyn Error>> {
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("../../skills").canonicalize()?;
println!("cargo:rerun-if-changed={}", root.display());
let mut folders = fs::read_dir(&root)?.collect::<Result<Vec<_>, _>>()?;
folders.sort_by_key(|entry| entry.file_name());
let mut output = String::from("const SKILLS: &[Skill] = &[\n");
let mut catalog = Vec::new();
for entry in folders {
let folder = entry.path();
if !entry.file_type()?.is_dir() || !folder.join("SKILL.md").is_file() {
continue;
}
let name = entry.file_name().to_string_lossy().into_owned();
let text = fs::read_to_string(folder.join("SKILL.md"))?;
let description = text
.lines()
.find_map(|line| line.strip_prefix("description: "))
.ok_or_else(|| format!("Missing skill description: {name}"))?
.trim_matches('"');
output.push_str(&format!("Skill {{ name: {name:?}, description: {description:?}, files: &[\n"));
let paths = files(&folder)?;
let mut names = Vec::new();
for path in paths {
let relative = path.strip_prefix(&folder)?.to_string_lossy().replace('\\', "/");
names.push(relative.clone());
// Include only text resources. A new non-text asset must get an explicit transport.
fs::read_to_string(&path)?;
output.push_str(&format!("({relative:?}, include_str!({path:?})),\n"));
}
output.push_str("] },\n");
catalog.push(format!("- {name}: {description} Files: {}", names.join(", ")));
}
output.push_str("];\n");
let out = PathBuf::from(env::var("OUT_DIR")?);
fs::write(out.join("skills.rs"), output)?;
fs::write(out.join("skill_catalog.rs"), format!("const AGENT_SKILL_CATALOG: &str = {:?};\n", catalog.join("\n")))?;
Ok(())
}