aether-mcp-servers 0.1.0

Built-in MCP tool servers for the Aether AI agent framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
use super::types::{Task, TaskId, TaskStatus};
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;

/// In-memory index for fast task queries.
/// Rebuilt on startup by scanning the active directory.
#[derive(Debug, Default)]
pub struct TaskIndex {
    /// All tasks by ID
    tasks: HashMap<TaskId, Task>,

    /// Tasks grouped by assignee
    by_assignee: HashMap<String, HashSet<TaskId>>,

    /// Tasks grouped by status
    by_status: HashMap<TaskStatus, HashSet<TaskId>>,

    /// Root task ID -> file path mapping
    trees: HashMap<TaskId, PathBuf>,

    /// Next subtask index for each root task
    subtask_counters: HashMap<TaskId, usize>,
}

impl TaskIndex {
    pub fn new() -> Self {
        Self::default()
    }

    /// Add a task to the index
    pub fn insert(&mut self, task: Task, file_path: PathBuf) {
        let id = task.id.clone();
        let root_id = id.root();

        self.trees.entry(root_id.clone()).or_insert(file_path);

        if !id.is_root()
            && let Some(suffix) = id.as_str().rsplit('.').next()
            && let Ok(idx) = suffix.parse::<usize>()
        {
            let counter = self.subtask_counters.entry(root_id).or_insert(0);
            *counter = (*counter).max(idx);
        }

        if let Some(assignee) = &task.assignee {
            self.by_assignee
                .entry(assignee.clone())
                .or_default()
                .insert(id.clone());
        }

        self.by_status
            .entry(task.status)
            .or_default()
            .insert(id.clone());

        self.tasks.insert(id, task);
    }

    /// Update a task in the index (re-indexes if assignee/status changed)
    pub fn update(&mut self, task: Task) {
        let id = task.id.clone();

        if let Some(old_task) = self.tasks.get(&id) {
            if let Some(old_assignee) = &old_task.assignee
                && let Some(ids) = self.by_assignee.get_mut(old_assignee)
            {
                ids.remove(&id);
                if ids.is_empty() {
                    self.by_assignee.remove(old_assignee);
                }
            }

            if let Some(ids) = self.by_status.get_mut(&old_task.status) {
                ids.remove(&id);
                if ids.is_empty() {
                    self.by_status.remove(&old_task.status);
                }
            }
        }

        if let Some(assignee) = &task.assignee {
            self.by_assignee
                .entry(assignee.clone())
                .or_default()
                .insert(id.clone());
        }

        self.by_status
            .entry(task.status)
            .or_default()
            .insert(id.clone());

        self.tasks.insert(id, task);
    }

    /// Remove a task from the index
    pub fn remove(&mut self, id: &TaskId) -> Option<Task> {
        if let Some(task) = self.tasks.remove(id) {
            if let Some(assignee) = &task.assignee
                && let Some(ids) = self.by_assignee.get_mut(assignee)
            {
                ids.remove(id);
                if ids.is_empty() {
                    self.by_assignee.remove(assignee);
                }
            }

            if let Some(ids) = self.by_status.get_mut(&task.status) {
                ids.remove(id);
                if ids.is_empty() {
                    self.by_status.remove(&task.status);
                }
            }

            Some(task)
        } else {
            None
        }
    }

    /// Remove an entire task tree from the index
    pub fn remove_tree(&mut self, root_id: &TaskId) -> Vec<Task> {
        let mut removed = Vec::new();

        let ids_to_remove: Vec<TaskId> = self
            .tasks
            .keys()
            .filter(|id| id.root() == *root_id)
            .cloned()
            .collect();

        for id in ids_to_remove {
            if let Some(task) = self.remove(&id) {
                removed.push(task);
            }
        }

        self.trees.remove(root_id);
        self.subtask_counters.remove(root_id);

        removed
    }

    /// Get a task by ID
    pub fn get(&self, id: &TaskId) -> Option<&Task> {
        self.tasks.get(id)
    }

    /// Get all tasks in a tree
    pub fn get_tree(&self, root_id: &TaskId) -> Vec<&Task> {
        self.tasks
            .values()
            .filter(|task| task.id.root() == *root_id)
            .collect()
    }

    /// Get the file path for a task tree
    pub fn get_tree_path(&self, root_id: &TaskId) -> Option<&PathBuf> {
        self.trees.get(root_id)
    }

    /// Get all tasks for an assignee
    pub fn get_by_assignee(&self, assignee: &str) -> Vec<&Task> {
        self.by_assignee
            .get(assignee)
            .map(|ids| ids.iter().filter_map(|id| self.tasks.get(id)).collect())
            .unwrap_or_default()
    }

    /// Get all tasks with a specific status
    pub fn get_by_status(&self, status: TaskStatus) -> Vec<&Task> {
        self.by_status
            .get(&status)
            .map(|ids| ids.iter().filter_map(|id| self.tasks.get(id)).collect())
            .unwrap_or_default()
    }

    /// Get all tasks that are ready to start (pending with all deps completed)
    pub fn get_ready(&self) -> Vec<&Task> {
        let completed_ids: Vec<&TaskId> = self
            .by_status
            .get(&TaskStatus::Completed)
            .map(|ids| ids.iter().collect())
            .unwrap_or_default();

        self.by_status
            .get(&TaskStatus::Pending)
            .map(|ids| {
                ids.iter()
                    .filter_map(|id| self.tasks.get(id))
                    .filter(|task| task.is_ready(&completed_ids))
                    .collect()
            })
            .unwrap_or_default()
    }

    /// Get the next subtask index for a root task
    pub fn next_subtask_index(&mut self, root_id: &TaskId) -> usize {
        let counter = self.subtask_counters.entry(root_id.clone()).or_insert(0);
        *counter += 1;
        *counter
    }

    /// Get all root task IDs
    pub fn root_ids(&self) -> Vec<&TaskId> {
        self.trees.keys().collect()
    }

    /// Get all tasks (for iteration)
    pub fn all_tasks(&self) -> impl Iterator<Item = &Task> {
        self.tasks.values()
    }

    /// Check if a task exists
    pub fn contains(&self, id: &TaskId) -> bool {
        self.tasks.contains_key(id)
    }

    /// Get the total number of tasks
    pub fn len(&self) -> usize {
        self.tasks.len()
    }

    /// Check if the index is empty
    pub fn is_empty(&self) -> bool {
        self.tasks.is_empty()
    }

    /// Clear the index
    pub fn clear(&mut self) {
        self.tasks.clear();
        self.by_assignee.clear();
        self.by_status.clear();
        self.trees.clear();
        self.subtask_counters.clear();
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use chrono::Utc;

    fn make_task(id: &str, status: TaskStatus, assignee: Option<&str>) -> Task {
        let now = Utc::now();
        Task {
            id: TaskId::from(id),
            title: format!("Task {id}"),
            description: None,
            status,
            assignee: assignee.map(String::from),
            parent: None,
            deps: Vec::new(),
            summary: None,
            decisions: Vec::new(),
            facts: Vec::new(),
            next_steps: Vec::new(),
            blockers: Vec::new(),
            files_read: Vec::new(),
            resources: Vec::new(),
            created_at: now,
            updated_at: now,
        }
    }

    #[test]
    fn test_insert_and_get() {
        let mut index = TaskIndex::new();
        let task = make_task("at-abc123", TaskStatus::Pending, Some("worker-1"));
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(task.clone(), path.clone());

        assert!(index.contains(&TaskId::from("at-abc123")));
        assert_eq!(index.len(), 1);

        let retrieved = index.get(&TaskId::from("at-abc123")).unwrap();
        assert_eq!(retrieved.title, "Task at-abc123");
    }

    #[test]
    fn test_index_by_assignee() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, Some("worker-1")),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.1", TaskStatus::InProgress, Some("worker-1")),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.2", TaskStatus::Pending, Some("worker-2")),
            path,
        );

        let worker1_tasks = index.get_by_assignee("worker-1");
        assert_eq!(worker1_tasks.len(), 2);

        let worker2_tasks = index.get_by_assignee("worker-2");
        assert_eq!(worker2_tasks.len(), 1);
    }

    #[test]
    fn test_index_by_status() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.1", TaskStatus::InProgress, None),
            path.clone(),
        );
        index.insert(make_task("at-abc123.2", TaskStatus::Completed, None), path);

        assert_eq!(index.get_by_status(TaskStatus::Pending).len(), 1);
        assert_eq!(index.get_by_status(TaskStatus::InProgress).len(), 1);
        assert_eq!(index.get_by_status(TaskStatus::Completed).len(), 1);
        assert_eq!(index.get_by_status(TaskStatus::Blocked).len(), 0);
    }

    #[test]
    fn test_update_reindexes() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        let mut task = make_task("at-abc123", TaskStatus::Pending, Some("worker-1"));
        index.insert(task.clone(), path);

        task.status = TaskStatus::InProgress;
        task.assignee = Some("worker-2".to_string());
        index.update(task);

        assert!(index.get_by_assignee("worker-1").is_empty());
        assert!(index.get_by_status(TaskStatus::Pending).is_empty());

        assert_eq!(index.get_by_assignee("worker-2").len(), 1);
        assert_eq!(index.get_by_status(TaskStatus::InProgress).len(), 1);
    }

    #[test]
    fn test_get_tree() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.1", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(make_task("at-abc123.2", TaskStatus::Pending, None), path);

        let tree = index.get_tree(&TaskId::from("at-abc123"));
        assert_eq!(tree.len(), 3);
    }

    #[test]
    fn test_remove_tree() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.1", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(make_task("at-abc123.2", TaskStatus::Pending, None), path);

        let removed = index.remove_tree(&TaskId::from("at-abc123"));
        assert_eq!(removed.len(), 3);
        assert!(index.is_empty());
    }

    #[test]
    fn test_get_ready() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, None),
            path.clone(),
        );

        let mut task2 = make_task("at-abc123.2", TaskStatus::Pending, None);
        task2.deps = vec![TaskId::from("at-abc123.1")];
        index.insert(task2, path.clone());

        index.insert(make_task("at-abc123.1", TaskStatus::Completed, None), path);

        let ready = index.get_ready();
        assert_eq!(ready.len(), 2);

        let ready_ids: Vec<&str> = ready.iter().map(|t| t.id.as_str()).collect();
        assert!(ready_ids.contains(&"at-abc123"));
        assert!(ready_ids.contains(&"at-abc123.2"));
    }

    #[test]
    fn test_subtask_counter() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");
        let root_id = TaskId::from("at-abc123");

        index.insert(make_task("at-abc123", TaskStatus::Pending, None), path);

        assert_eq!(index.next_subtask_index(&root_id), 1);
        assert_eq!(index.next_subtask_index(&root_id), 2);
        assert_eq!(index.next_subtask_index(&root_id), 3);
    }

    #[test]
    fn test_subtask_counter_from_existing() {
        let mut index = TaskIndex::new();
        let path = PathBuf::from(".aether-tasks/active/at-abc123.jsonl");
        let root_id = TaskId::from("at-abc123");

        index.insert(
            make_task("at-abc123", TaskStatus::Pending, None),
            path.clone(),
        );
        index.insert(
            make_task("at-abc123.5", TaskStatus::Pending, None),
            path.clone(),
        );

        assert_eq!(index.next_subtask_index(&root_id), 6);
    }
}