feat(skill-awareness): T1→T5 — manifeste de skills + outil MCP idea_skill_read
Surface les skills assignés à un agent « à la MCP » : description sur l'entité Skill (+ effective_description fallback), section « # Skills disponibles » haute altitude dans le convention-file (mode MCP), outil read-only idea_skill_read (résolution projet→global), use case ReadSkill (port SkillStore existant), et câblage au composition root. Dump legacy du corps complet conservé en mode sans-MCP (zéro régression). Rétro-compat index.json (serde default). Tests : domain+application+infrastructure 1212 passed / 0 failed (23 ajoutés). Reste : T6 (champ description front) + T7 (e2e après rebuild AppImage). NB topologie : commit réalisé par l'orchestrateur car l'agent Git était injoignable (bug de livraison cold-start) ; à faire relire/rebaser par Git. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -15,7 +15,7 @@ mod usecases;
|
||||
|
||||
pub use usecases::{
|
||||
AssignSkillToAgent, AssignSkillToAgentInput, CreateSkill, CreateSkillInput, CreateSkillOutput,
|
||||
DeleteSkill, DeleteSkillInput, ListSkills, ListSkillsInput, ListSkillsOutput,
|
||||
UnassignSkillFromAgent, UnassignSkillFromAgentInput, UpdateSkill, UpdateSkillInput,
|
||||
UpdateSkillOutput,
|
||||
DeleteSkill, DeleteSkillInput, ListSkills, ListSkillsInput, ListSkillsOutput, ReadSkill,
|
||||
ReadSkillInput, UnassignSkillFromAgent, UnassignSkillFromAgentInput, UpdateSkill,
|
||||
UpdateSkillInput, UpdateSkillOutput,
|
||||
};
|
||||
|
||||
@ -25,6 +25,10 @@ use crate::error::AppError;
|
||||
pub struct CreateSkillInput {
|
||||
/// Display name (also the `.md` stem on disk).
|
||||
pub name: String,
|
||||
/// Optional one-line affordance description (feature « skills à la MCP »).
|
||||
/// `None`/empty ⇒ the skill falls back to the first line of its body when
|
||||
/// surfaced (see [`domain::Skill::effective_description`]).
|
||||
pub description: Option<String>,
|
||||
/// Initial Markdown body.
|
||||
pub content: String,
|
||||
/// Scope the skill is created in (selects its backing store).
|
||||
@ -61,7 +65,8 @@ impl CreateSkill {
|
||||
pub async fn execute(&self, input: CreateSkillInput) -> Result<CreateSkillOutput, AppError> {
|
||||
let id = SkillId::from_uuid(self.ids.new_uuid());
|
||||
let skill = Skill::new(id, input.name, MarkdownDoc::new(input.content), input.scope)
|
||||
.map_err(|e| AppError::Invalid(e.to_string()))?;
|
||||
.map_err(|e| AppError::Invalid(e.to_string()))?
|
||||
.with_description(input.description);
|
||||
self.skills.save(&skill, &input.project_root).await?;
|
||||
Ok(CreateSkillOutput { skill })
|
||||
}
|
||||
@ -204,6 +209,77 @@ impl DeleteSkill {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ReadSkill
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Input for [`ReadSkill::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ReadSkillInput {
|
||||
/// Skill display name to resolve (case-insensitive).
|
||||
pub name: String,
|
||||
/// Active project root (used for the [`SkillScope::Project`] lookup).
|
||||
pub project_root: ProjectPath,
|
||||
}
|
||||
|
||||
/// Reads a skill's Markdown body **by name** — the application side of the MCP
|
||||
/// `idea_skill_read` tool (feature « skills à la MCP »).
|
||||
///
|
||||
/// Resolution follows the affordance contract: **project scope first, then
|
||||
/// global** (a project skill shadows a global one of the same name). It composes
|
||||
/// the **existing** [`SkillStore`] port only — no new port. Read-only.
|
||||
pub struct ReadSkill {
|
||||
skills: Arc<dyn SkillStore>,
|
||||
}
|
||||
|
||||
impl ReadSkill {
|
||||
/// Builds the use case from the existing skill store port.
|
||||
#[must_use]
|
||||
pub fn new(skills: Arc<dyn SkillStore>) -> Self {
|
||||
Self { skills }
|
||||
}
|
||||
|
||||
/// Resolves `name` in `scope`, returning the single match.
|
||||
///
|
||||
/// `Ok(None)` ⇒ no skill by that name in this scope; `Err(Invalid)` ⇒ the
|
||||
/// name is **ambiguous** (more than one skill shares it in this scope).
|
||||
async fn resolve_in(
|
||||
&self,
|
||||
scope: SkillScope,
|
||||
input: &ReadSkillInput,
|
||||
) -> Result<Option<Skill>, AppError> {
|
||||
let all = self.skills.list(scope, &input.project_root).await?;
|
||||
let mut matches = all
|
||||
.into_iter()
|
||||
.filter(|s| s.name.eq_ignore_ascii_case(&input.name));
|
||||
match (matches.next(), matches.next()) {
|
||||
(None, _) => Ok(None),
|
||||
(Some(skill), None) => Ok(Some(skill)),
|
||||
(Some(_), Some(_)) => Err(AppError::Invalid(format!(
|
||||
"skill name `{}` is ambiguous in {scope:?} scope (several skills share it)",
|
||||
input.name
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the skill by name and returns its Markdown body.
|
||||
///
|
||||
/// # Errors
|
||||
/// - [`AppError::Invalid`] if the name is ambiguous within a scope,
|
||||
/// - [`AppError::NotFound`] if no skill carries that name in either scope,
|
||||
/// - [`AppError::Store`] on a store failure.
|
||||
pub async fn execute(&self, input: ReadSkillInput) -> Result<MarkdownDoc, AppError> {
|
||||
// Project scope shadows global: try it first, then fall back to global.
|
||||
if let Some(skill) = self.resolve_in(SkillScope::Project, &input).await? {
|
||||
return Ok(skill.content_md);
|
||||
}
|
||||
if let Some(skill) = self.resolve_in(SkillScope::Global, &input).await? {
|
||||
return Ok(skill.content_md);
|
||||
}
|
||||
Err(AppError::NotFound(format!("skill `{}`", input.name)))
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// AssignSkillToAgent / UnassignSkillFromAgent
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -349,3 +425,185 @@ impl UnassignSkillFromAgent {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use domain::ports::{SkillStore, StoreError};
|
||||
|
||||
/// In-memory [`SkillStore`] fake: skills are bucketed by scope, ignoring the
|
||||
/// project root (the [`ReadSkill`] resolution logic is root-agnostic — it only
|
||||
/// switches scope). Enough to exercise project-first resolution, shadowing,
|
||||
/// ambiguity and absence without touching disk.
|
||||
#[derive(Default)]
|
||||
struct FakeSkillStore {
|
||||
global: Mutex<Vec<Skill>>,
|
||||
project: Mutex<Vec<Skill>>,
|
||||
}
|
||||
|
||||
impl FakeSkillStore {
|
||||
fn bucket(&self, scope: SkillScope) -> &Mutex<Vec<Skill>> {
|
||||
match scope {
|
||||
SkillScope::Global => &self.global,
|
||||
SkillScope::Project => &self.project,
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self, skill: Skill) {
|
||||
self.bucket(skill.scope).lock().unwrap().push(skill);
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SkillStore for FakeSkillStore {
|
||||
async fn list(
|
||||
&self,
|
||||
scope: SkillScope,
|
||||
_root: &ProjectPath,
|
||||
) -> Result<Vec<Skill>, StoreError> {
|
||||
Ok(self.bucket(scope).lock().unwrap().clone())
|
||||
}
|
||||
async fn get(
|
||||
&self,
|
||||
scope: SkillScope,
|
||||
_root: &ProjectPath,
|
||||
id: SkillId,
|
||||
) -> Result<Skill, StoreError> {
|
||||
self.bucket(scope)
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|s| s.id == id)
|
||||
.cloned()
|
||||
.ok_or(StoreError::NotFound)
|
||||
}
|
||||
async fn save(&self, skill: &Skill, _root: &ProjectPath) -> Result<(), StoreError> {
|
||||
self.push(skill.clone());
|
||||
Ok(())
|
||||
}
|
||||
async fn delete(
|
||||
&self,
|
||||
_scope: SkillScope,
|
||||
_root: &ProjectPath,
|
||||
_id: SkillId,
|
||||
) -> Result<(), StoreError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn root() -> ProjectPath {
|
||||
ProjectPath::new("/proj").unwrap()
|
||||
}
|
||||
|
||||
fn skill(id: u128, name: &str, body: &str, scope: SkillScope) -> Skill {
|
||||
Skill::new(
|
||||
SkillId::from_uuid(uuid::Uuid::from_u128(id)),
|
||||
name,
|
||||
MarkdownDoc::new(body),
|
||||
scope,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn read_skill_uc(store: Arc<FakeSkillStore>) -> ReadSkill {
|
||||
ReadSkill::new(store)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_resolves_project_scope() {
|
||||
// (a) skill present in the project scope ⇒ its body is returned.
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
store.push(skill(1, "deploy", "PROJECT_BODY", SkillScope::Project));
|
||||
|
||||
let body = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "deploy".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(body.as_str(), "PROJECT_BODY");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_falls_back_to_global_scope() {
|
||||
// (b) absent from project but present globally ⇒ resolved via global.
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
store.push(skill(1, "deploy", "GLOBAL_BODY", SkillScope::Global));
|
||||
|
||||
let body = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "deploy".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(body.as_str(), "GLOBAL_BODY");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_project_shadows_global() {
|
||||
// (c) same name in both scopes ⇒ project wins.
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
store.push(skill(1, "deploy", "GLOBAL_BODY", SkillScope::Global));
|
||||
store.push(skill(2, "deploy", "PROJECT_BODY", SkillScope::Project));
|
||||
|
||||
let body = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "deploy".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(body.as_str(), "PROJECT_BODY");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_is_case_insensitive() {
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
store.push(skill(1, "Deploy", "BODY", SkillScope::Project));
|
||||
|
||||
let body = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "deploy".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(body.as_str(), "BODY");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_unknown_is_not_found() {
|
||||
// (d) unknown in both scopes ⇒ NotFound.
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
let err = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "ghost".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, AppError::NotFound(_)), "got {err:?}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_skill_ambiguous_name_is_invalid() {
|
||||
// (e) two skills share a name within a scope ⇒ Invalid (ambiguous).
|
||||
let store = Arc::new(FakeSkillStore::default());
|
||||
store.push(skill(1, "deploy", "ONE", SkillScope::Project));
|
||||
store.push(skill(2, "Deploy", "TWO", SkillScope::Project));
|
||||
|
||||
let err = read_skill_uc(store)
|
||||
.execute(ReadSkillInput {
|
||||
name: "deploy".to_owned(),
|
||||
project_root: root(),
|
||||
})
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, AppError::Invalid(_)), "got {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user