feat(orchestrator): create_skill action + wire per-project watchers (§14.3)
- domain: OrchestratorCommand::CreateSkill with optional scope field (defaults to Project, case-insensitive, UnknownScope on bad value) - application: dispatch CreateSkill through the CreateSkill use case - app-tauri: build OrchestratorService and start/stop per-project request watchers on open/create/close_project (ensure/stop_orchestrator_watch) - tests: domain validation, service dispatch, infra watcher e2e, app-tauri wiring lifecycle (idempotent, isolated, stop) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -23,6 +23,7 @@ use crate::agent::{
|
||||
ListAgentsInput, UpdateAgentContext, UpdateAgentContextInput,
|
||||
};
|
||||
use crate::error::AppError;
|
||||
use crate::skill::{CreateSkill, CreateSkillInput};
|
||||
use crate::terminal::{CloseTerminal, CloseTerminalInput, TerminalSessions};
|
||||
|
||||
/// Default terminal geometry for an orchestrator-launched agent cell. The UI
|
||||
@ -39,6 +40,7 @@ pub struct OrchestratorService {
|
||||
list_agents: Arc<ListAgents>,
|
||||
close_terminal: Arc<CloseTerminal>,
|
||||
update_context: Arc<UpdateAgentContext>,
|
||||
create_skill: Arc<CreateSkill>,
|
||||
profiles: Arc<dyn ProfileStore>,
|
||||
sessions: Arc<TerminalSessions>,
|
||||
}
|
||||
@ -61,6 +63,7 @@ impl OrchestratorService {
|
||||
list_agents: Arc<ListAgents>,
|
||||
close_terminal: Arc<CloseTerminal>,
|
||||
update_context: Arc<UpdateAgentContext>,
|
||||
create_skill: Arc<CreateSkill>,
|
||||
profiles: Arc<dyn ProfileStore>,
|
||||
sessions: Arc<TerminalSessions>,
|
||||
) -> Self {
|
||||
@ -70,6 +73,7 @@ impl OrchestratorService {
|
||||
list_agents,
|
||||
close_terminal,
|
||||
update_context,
|
||||
create_skill,
|
||||
profiles,
|
||||
sessions,
|
||||
}
|
||||
@ -96,6 +100,11 @@ impl OrchestratorService {
|
||||
OrchestratorCommand::UpdateAgentContext { name, context } => {
|
||||
self.update_agent_context(project, name, context).await
|
||||
}
|
||||
OrchestratorCommand::CreateSkill {
|
||||
name,
|
||||
content,
|
||||
scope,
|
||||
} => self.create_skill(project, name, content, scope).await,
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,6 +202,32 @@ impl OrchestratorService {
|
||||
})
|
||||
}
|
||||
|
||||
/// `create_skill`: create a reusable skill in the requested scope — the same
|
||||
/// path the UI's "New skill" action takes. For [`SkillScope::Project`] the
|
||||
/// skill lands under `<root>/.ideai/skills/`; for [`SkillScope::Global`] the
|
||||
/// project root is ignored by the store.
|
||||
async fn create_skill(
|
||||
&self,
|
||||
project: &Project,
|
||||
name: String,
|
||||
content: String,
|
||||
scope: domain::SkillScope,
|
||||
) -> Result<OrchestratorOutcome, AppError> {
|
||||
let created = self
|
||||
.create_skill
|
||||
.execute(CreateSkillInput {
|
||||
name: name.clone(),
|
||||
content,
|
||||
scope,
|
||||
project_root: project.root.clone(),
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(OrchestratorOutcome {
|
||||
detail: format!("created skill {} ({:?})", created.skill.name, scope),
|
||||
})
|
||||
}
|
||||
|
||||
/// Finds an agent id by display name (case-insensitive) in the project manifest.
|
||||
async fn find_agent_id_by_name(
|
||||
&self,
|
||||
|
||||
@ -33,8 +33,8 @@ use domain::{OrchestratorCommand, OrchestratorRequest, PtySize, SessionId};
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::{
|
||||
CloseTerminal, CreateAgentFromScratch, LaunchAgent, ListAgents, OrchestratorService,
|
||||
TerminalSessions, UpdateAgentContext,
|
||||
CloseTerminal, CreateAgentFromScratch, CreateSkill, LaunchAgent, ListAgents,
|
||||
OrchestratorService, TerminalSessions, UpdateAgentContext,
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -183,6 +183,44 @@ impl SkillStore for FakeSkills {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [`SkillStore`] that records every `save` so a `create_skill` dispatch can be
|
||||
/// asserted against the persisted skill (name + scope).
|
||||
#[derive(Clone, Default)]
|
||||
struct RecordingSkills(Arc<Mutex<Vec<Skill>>>);
|
||||
|
||||
#[async_trait]
|
||||
impl SkillStore for RecordingSkills {
|
||||
async fn list(&self, _scope: SkillScope, _root: &ProjectPath) -> Result<Vec<Skill>, StoreError> {
|
||||
Ok(self.0.lock().unwrap().clone())
|
||||
}
|
||||
async fn get(
|
||||
&self,
|
||||
_scope: SkillScope,
|
||||
_root: &ProjectPath,
|
||||
id: SkillId,
|
||||
) -> Result<Skill, StoreError> {
|
||||
self.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|s| s.id == id)
|
||||
.cloned()
|
||||
.ok_or(StoreError::NotFound)
|
||||
}
|
||||
async fn save(&self, skill: &Skill, _root: &ProjectPath) -> Result<(), StoreError> {
|
||||
self.0.lock().unwrap().push(skill.clone());
|
||||
Ok(())
|
||||
}
|
||||
async fn delete(
|
||||
&self,
|
||||
_scope: SkillScope,
|
||||
_root: &ProjectPath,
|
||||
_id: SkillId,
|
||||
) -> Result<(), StoreError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct FakeRuntime;
|
||||
impl AgentRuntime for FakeRuntime {
|
||||
fn detect(&self, _profile: &AgentProfile) -> Result<bool, RuntimeError> {
|
||||
@ -349,6 +387,7 @@ struct Fixture {
|
||||
pty: FakePty,
|
||||
bus: SpyBus,
|
||||
sessions: Arc<TerminalSessions>,
|
||||
skills: RecordingSkills,
|
||||
}
|
||||
|
||||
fn fixture(contexts: FakeContexts) -> Fixture {
|
||||
@ -378,6 +417,11 @@ fn fixture(contexts: FakeContexts) -> Fixture {
|
||||
Arc::clone(&sessions),
|
||||
));
|
||||
let update = Arc::new(UpdateAgentContext::new(Arc::new(contexts.clone())));
|
||||
let skills = RecordingSkills::default();
|
||||
let create_skill = Arc::new(CreateSkill::new(
|
||||
Arc::new(skills.clone()) as Arc<dyn SkillStore>,
|
||||
Arc::new(SeqIds::new()),
|
||||
));
|
||||
|
||||
let service = OrchestratorService::new(
|
||||
create,
|
||||
@ -385,6 +429,7 @@ fn fixture(contexts: FakeContexts) -> Fixture {
|
||||
list,
|
||||
close,
|
||||
update,
|
||||
create_skill,
|
||||
Arc::clone(&profiles) as Arc<dyn ProfileStore>,
|
||||
Arc::clone(&sessions),
|
||||
);
|
||||
@ -395,6 +440,7 @@ fn fixture(contexts: FakeContexts) -> Fixture {
|
||||
pty,
|
||||
bus,
|
||||
sessions,
|
||||
skills,
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,3 +587,43 @@ async fn spawn_with_unknown_profile_is_not_found_and_does_not_create() {
|
||||
assert!(fx.contexts.manifest().entries.is_empty());
|
||||
assert!(fx.sessions.session(&sid(777)).is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_skill_persists_a_project_scoped_skill_by_default() {
|
||||
let fx = fixture(FakeContexts::new());
|
||||
|
||||
let out = fx
|
||||
.service
|
||||
.dispatch(
|
||||
&project(),
|
||||
cmd(r##"{ "action":"create_skill", "name":"deploy", "context":"# Deploy" }"##),
|
||||
)
|
||||
.await
|
||||
.expect("create_skill ok");
|
||||
|
||||
assert!(out.detail.contains("deploy"));
|
||||
|
||||
let saved = fx.skills.0.lock().unwrap();
|
||||
assert_eq!(saved.len(), 1);
|
||||
assert_eq!(saved[0].name, "deploy");
|
||||
assert_eq!(saved[0].scope, SkillScope::Project);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_skill_honours_global_scope() {
|
||||
let fx = fixture(FakeContexts::new());
|
||||
|
||||
fx.service
|
||||
.dispatch(
|
||||
&project(),
|
||||
cmd(
|
||||
r##"{ "action":"create_skill", "name":"shared", "context":"# Shared", "scope":"global" }"##,
|
||||
),
|
||||
)
|
||||
.await
|
||||
.expect("create_skill ok");
|
||||
|
||||
let saved = fx.skills.0.lock().unwrap();
|
||||
assert_eq!(saved.len(), 1);
|
||||
assert_eq!(saved[0].scope, SkillScope::Global);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user