1pub mod ai_context;
2pub mod annotations;
3pub mod discussions;
4pub mod traffic_branch;
5
6use anyhow::Result;
7use std::path::Path;
8
9pub use annotations::Annotation;
10pub use traffic_branch::{apply_update, ComponentStateManager, TrafficBranch, UpdateResult};
11
12use crate::crdt::{Anchor, Position};
13use crate::storage::Database;
14
15pub async fn create_anchor(
16 file: &Path,
17 line: usize,
18 column: usize,
19 message: Option<String>,
20) -> Result<Anchor> {
21 let db = Database::open(".dx/forge")?;
22
23 let config: serde_json::Value =
25 serde_json::from_str(&tokio::fs::read_to_string(".dx/forge/config.json").await?)?;
26 let actor_id = config["actor_id"].as_str().unwrap().to_string();
27
28 let position = Position::new(line, column, 0, actor_id, 0);
29 let anchor = Anchor::new(file.display().to_string(), position, message);
30
31 db.store_anchor(&anchor)?;
32
33 Ok(anchor)
34}
35
36pub async fn annotate(file: &Path, line: usize, message: &str, is_ai: bool) -> Result<()> {
37 let annotation = Annotation::new(file.display().to_string(), line, message.to_string(), is_ai);
38
39 let db = Database::open(".dx/forge")?;
41 annotations::store_annotation(&db, &annotation)?;
42
43 Ok(())
44}
45
46pub async fn show_context(file: &Path, line: Option<usize>) -> Result<()> {
47 use colored::*;
48
49 let db = Database::open(".dx/forge")?;
50 let annotations = annotations::get_annotations(&db, file, line)?;
51
52 println!(
53 "{}",
54 format!("Context for: {}", file.display()).cyan().bold()
55 );
56 println!("{}", "═".repeat(80).bright_black());
57
58 for ann in annotations {
59 let icon = if ann.is_ai { "🤖" } else { "👤" };
60 let author = if ann.is_ai {
61 "AI Agent".bright_magenta()
62 } else {
63 ann.author.bright_cyan()
64 };
65
66 println!(
67 "\n{} {} {} {}",
68 icon,
69 author,
70 format!("(line {})", ann.line).bright_black(),
71 ann.created_at
72 .format("%Y-%m-%d %H:%M")
73 .to_string()
74 .bright_black()
75 );
76 println!(" {}", ann.content.bright_white());
77 }
78
79 Ok(())
80}