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:
@ -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