From 7efacbe256e0969cc5e7b638f1be7cfe81e5e29d Mon Sep 17 00:00:00 2001 From: archae0pteryx Date: Wed, 28 Oct 2026 08:44:34 -0700 Subject: [PATCH 1/2] Fail a skill entry before install when its local folder exists but no longer holds the named skill. --- README.md | 3 +- src/app/apply/source_gone.rs | 67 ++++++++++++++++++++++++++++++++---- src/app/stale.rs | 38 +++++++++++++++++++- 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a300a60..d307c74 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,8 @@ subagent of the same name (it keeps your label, refreshes the provenance, and fo entries that named the old path); the toast says `moved: N` and `sync --json` has `repointed`. If several places match it stays stale (`ambiguous`), and if the library already has the live item the stale duplicate is dropped. Repository and URL sources are never touched. Installing or applying -an entry whose directory is missing fails that entry, naming it and the path, before `npx` runs; +an entry whose directory is missing, or a skill entry whose directory no longer holds that skill, +fails that entry, naming it and the path, before `npx` runs; the other entries still install. `skillz run` environments are keyed by profile only, so a moved project reuses its own. Installing a skill again fetches it from its recorded diff --git a/src/app/apply/source_gone.rs b/src/app/apply/source_gone.rs index b077538..4d71ce0 100644 --- a/src/app/apply/source_gone.rs +++ b/src/app/apply/source_gone.rs @@ -1,9 +1,10 @@ use std::fmt; -use crate::app::stale::{Probe, missing_source}; +use crate::app::stale::{Probe, missing_source, source_without_skill}; use skillz_harness::Spec; -/// An entry cannot be installed because the local folder it names is gone, most likely moved. +/// An entry cannot be installed because the local folder it names is gone, or no longer holds +/// the skill, most likely moved. #[derive(Debug, PartialEq, Eq)] pub struct SourceGone { pub entry: String, @@ -13,10 +14,12 @@ pub struct SourceGone { impl SourceGone { /// Why `entry` cannot be installed, when its local source is gone. pub fn of(entry: &Spec, probe: &dyn Probe) -> Option { - missing_source(entry, probe).map(|path| SourceGone { - entry: entry.to_string(), - path: path.to_string(), - }) + missing_source(entry, probe) + .or_else(|| source_without_skill(entry, probe)) + .map(|path| SourceGone { + entry: entry.to_string(), + path: path.to_string(), + }) } } @@ -24,10 +27,60 @@ impl fmt::Display for SourceGone { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "{} cannot be installed: {} does not exist; if the folder moved, run `skillz sync` to follow it", + "{} cannot be installed: {} no longer holds it; if the folder moved, run `skillz sync` to follow it", self.entry, self.path ) } } impl std::error::Error for SourceGone {} + +#[cfg(test)] +mod tests { + use std::collections::HashSet; + use std::path::Path; + + use super::*; + use crate::app::stale::tests::skill; + + /// Every folder exists; each holds only the skills listed for it. + struct Holding(HashSet<(&'static str, &'static str)>); + + impl Probe for Holding { + fn exists(&self, _path: &Path) -> bool { + true + } + + fn holds_skill(&self, dir: &Path, name: &str) -> bool { + self.0 + .iter() + .any(|(d, n)| Path::new(d) == dir && *n == name) + } + } + + fn holding(skills: &[(&'static str, &'static str)]) -> Holding { + Holding(skills.iter().copied().collect()) + } + + #[test] + fn a_folder_that_no_longer_holds_the_skill_is_gone() { + let gone = SourceGone::of(&skill("/d", "x"), &holding(&[("/d", "y")])); + + assert_eq!(gone.map(|g| g.path), Some("/d".to_string()),); + } + + #[test] + fn a_folder_that_holds_the_skill_is_not_gone() { + assert_eq!( + SourceGone::of(&skill("/d", "x"), &holding(&[("/d", "x")])), + None + ); + } + + #[test] + fn git_and_url_sources_are_not_gone_whatever_the_probe_holds() { + for source in ["org/repo", "https://h/o/r.git"] { + assert_eq!(SourceGone::of(&skill(source, "x"), &holding(&[])), None); + } + } +} diff --git a/src/app/stale.rs b/src/app/stale.rs index 29a1c98..70cedea 100644 --- a/src/app/stale.rs +++ b/src/app/stale.rs @@ -4,10 +4,16 @@ use std::path::Path; use skillz_harness::Spec; +use skillz_harness::agent_skills::skill_names_under; -/// Whether a path exists; injected so the rules can be tested without a disk. +/// What is on disk; injected so the rules can be tested without a disk. pub trait Probe { fn exists(&self, path: &Path) -> bool; + + /// Whether the directory holds a skill called `name`. A probe that cannot tell says yes. + fn holds_skill(&self, _dir: &Path, _name: &str) -> bool { + true + } } pub struct Disk; @@ -16,6 +22,10 @@ impl Probe for Disk { fn exists(&self, path: &Path) -> bool { path.exists() } + + fn holds_skill(&self, dir: &Path, name: &str) -> bool { + skill_names_under(dir).map_or(true, |names| names.iter().any(|n| n == name)) + } } /// The directory a skill or subagent entry is installed from, when its source is an absolute @@ -47,6 +57,18 @@ pub fn sole_name(entry: &Spec) -> Option<&str> { } } +/// The local source of a skill entry that exists but no longer holds a skill the entry names. +pub fn source_without_skill<'a>(entry: &'a Spec, probe: &dyn Probe) -> Option<&'a str> { + let Spec::Skill { names, .. } = entry else { + return None; + }; + local_source(entry).filter(|source| { + names + .iter() + .any(|name| !probe.holds_skill(Path::new(source), name)) + }) +} + /// The same entry installed from `new_source`. pub fn with_source(mut entry: Spec, new_source: &str) -> Spec { if let Spec::Skill { source, .. } | Spec::Subagent { source, .. } = &mut entry { @@ -112,6 +134,20 @@ pub(crate) mod tests { } } + #[test] + fn the_disk_holds_the_skills_found_under_a_folder() { + let dir = tempfile::tempdir().unwrap(); + skillz_harness::test_support::skill(dir.path(), "nested/x"); + + assert!(Disk.holds_skill(dir.path(), "x")); + assert!(!Disk.holds_skill(dir.path(), "y")); + } + + #[test] + fn a_folder_that_cannot_be_read_is_not_reported_as_missing_the_skill() { + assert!(Disk.holds_skill(Path::new("/no/such/folder"), "x")); + } + #[test] fn only_entries_naming_one_thing_have_a_sole_name() { let two = Spec::Skill { From 3f295f482d9766675beb5bc4446b919ce44b8671 Mon Sep 17 00:00:00 2001 From: archae0pteryx Date: Wed, 28 Oct 2026 08:54:18 -0700 Subject: [PATCH 2/2] Give a skill-gone entry its own advice instead of promising sync, and pin the all-names and subagent cases. --- README.md | 5 ++- src/app/apply/source_gone.rs | 74 ++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d307c74..93453d9 100644 --- a/README.md +++ b/README.md @@ -256,8 +256,9 @@ subagent of the same name (it keeps your label, refreshes the provenance, and fo entries that named the old path); the toast says `moved: N` and `sync --json` has `repointed`. If several places match it stays stale (`ambiguous`), and if the library already has the live item the stale duplicate is dropped. Repository and URL sources are never touched. Installing or applying -an entry whose directory is missing, or a skill entry whose directory no longer holds that skill, -fails that entry, naming it and the path, before `npx` runs; +an entry whose directory is missing, or a skill entry whose directory exists but no longer holds +that skill, fails that entry, naming it and the path, before `npx` runs (only a missing directory +is followed by `skillz sync`); the other entries still install. `skillz run` environments are keyed by profile only, so a moved project reuses its own. Installing a skill again fetches it from its recorded diff --git a/src/app/apply/source_gone.rs b/src/app/apply/source_gone.rs index 4d71ce0..c6ee928 100644 --- a/src/app/apply/source_gone.rs +++ b/src/app/apply/source_gone.rs @@ -3,33 +3,52 @@ use std::fmt; use crate::app::stale::{Probe, missing_source, source_without_skill}; use skillz_harness::Spec; +/// Why an entry's local source cannot be installed from. +#[derive(Debug, PartialEq, Eq)] +pub enum Cause { + FolderMissing, + SkillMissing, +} + /// An entry cannot be installed because the local folder it names is gone, or no longer holds -/// the skill, most likely moved. +/// the skill. #[derive(Debug, PartialEq, Eq)] pub struct SourceGone { pub entry: String, pub path: String, + pub cause: Cause, } impl SourceGone { /// Why `entry` cannot be installed, when its local source is gone. pub fn of(entry: &Spec, probe: &dyn Probe) -> Option { + let gone = |path: &str, cause| SourceGone { + entry: entry.to_string(), + path: path.to_string(), + cause, + }; missing_source(entry, probe) - .or_else(|| source_without_skill(entry, probe)) - .map(|path| SourceGone { - entry: entry.to_string(), - path: path.to_string(), + .map(|path| gone(path, Cause::FolderMissing)) + .or_else(|| { + source_without_skill(entry, probe).map(|path| gone(path, Cause::SkillMissing)) }) } } impl fmt::Display for SourceGone { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{} cannot be installed: {} no longer holds it; if the folder moved, run `skillz sync` to follow it", - self.entry, self.path - ) + match self.cause { + Cause::FolderMissing => write!( + f, + "{} cannot be installed: {} does not exist; if the folder moved, run `skillz sync` to follow it", + self.entry, self.path + ), + Cause::SkillMissing => write!( + f, + "{} cannot be installed: {} exists but no longer holds it; restore the skill there or point the entry at the folder that has it", + self.entry, self.path + ), + } } } @@ -41,7 +60,7 @@ mod tests { use std::path::Path; use super::*; - use crate::app::stale::tests::skill; + use crate::app::stale::tests::{Existing, skill}; /// Every folder exists; each holds only the skills listed for it. struct Holding(HashSet<(&'static str, &'static str)>); @@ -66,7 +85,38 @@ mod tests { fn a_folder_that_no_longer_holds_the_skill_is_gone() { let gone = SourceGone::of(&skill("/d", "x"), &holding(&[("/d", "y")])); - assert_eq!(gone.map(|g| g.path), Some("/d".to_string()),); + assert_eq!(gone.map(|g| g.cause), Some(Cause::SkillMissing)); + } + + #[test] + fn a_missing_folder_is_gone_for_that_reason() { + let gone = SourceGone::of(&skill("/d", "x"), &Existing::of(&[])); + + assert_eq!(gone.map(|g| g.cause), Some(Cause::FolderMissing)); + } + + #[test] + fn one_named_skill_missing_from_the_folder_is_enough() { + let entry = Spec::Skill { + source: "/d".into(), + names: vec!["x".into(), "y".into()], + agents: vec![], + }; + + let gone = SourceGone::of(&entry, &holding(&[("/d", "y")])); + + assert_eq!(gone.map(|g| g.cause), Some(Cause::SkillMissing)); + } + + #[test] + fn a_subagent_entry_is_never_flagged_for_a_missing_skill() { + let entry = Spec::Subagent { + source: "/d".into(), + names: vec!["x".into()], + agents: vec![], + }; + + assert_eq!(SourceGone::of(&entry, &holding(&[])), None); } #[test]