Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion anna/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2021"
authors = ["Jessica Black <me@jessica.black>"]
license = "MPL-2.0"
public = false
publish = false

[dependencies]
clap = { version = "4.5.31", features = ["cargo", "derive", "env"] }
color-eyre = "0.6.3"
winlock = { path = "../winlock" }
2 changes: 2 additions & 0 deletions anna/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod agent;
pub mod session;
35 changes: 35 additions & 0 deletions anna/src/cmd/agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::path::PathBuf;

use clap::Parser;
use color_eyre::{eyre::Context, Result};
use winlock::Agent;

#[derive(Debug, Parser)]
pub struct AgentArgs {
/// Branch name for the agent to work on
#[arg(value_name = "BRANCH")]
branch: String,
}

pub fn main(project: PathBuf, AgentArgs { branch }: AgentArgs) -> Result<()> {
eprintln!("Creating session for branch {branch:?}...");

let agent = Agent::builder()
.project(&project)
.branch(&branch)
.build()
.context("create agent session")?;
eprintln!(
"Session {} at {} for branch {:?}",
agent.status,
agent.workspace.display(),
branch,
);

agent.run().context("run agent")?;

eprintln!();
eprintln!("Note: If you're done, you can use `anna session ...` commands to clean up.");
eprintln!(" Otherwise, you can always execute this same command to re-enter the current session.");
Ok(())
}
75 changes: 75 additions & 0 deletions anna/src/cmd/session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use color_eyre::Result;
use winlock::Sessions;

#[derive(Debug, Subcommand)]
pub enum SessionCommands {
/// List all available sessions
ListAll,

/// List sessions for for the current project
List,

/// Remove a session for the current project
Remove(SessionRemoveArgs),
}

#[derive(Debug, Parser)]
pub struct SessionRemoveArgs {
/// Branch name
#[arg(value_name = "BRANCH")]
branch: String,
}

pub fn main(project: PathBuf, command: SessionCommands) -> Result<()> {
match command {
SessionCommands::ListAll => main_list_all(),
SessionCommands::List => main_list(project),
SessionCommands::Remove(args) => main_remove(project, args),
}
}

fn main_list_all() -> Result<()> {
let sessions = Sessions::list_all()?;
if sessions.is_empty() {
eprintln!("No sessions found");
return Ok(());
}

for session in sessions {
eprintln!(
"Project: {}\n\tBranch: {}\n\tWorkspace: {}",
session.project.display(),
session.branch,
session.workspace.display()
);
}

Ok(())
}

fn main_list(project: PathBuf) -> Result<()> {
let sessions = Sessions::list(&project)?;
if sessions.is_empty() {
eprintln!("No sessions found for project: {}", project.display());
return Ok(());
}

for session in sessions {
eprintln!(
"Branch: {}\n\tWorkspace: {}",
session.branch,
session.workspace.display()
);
}

Ok(())
}

fn main_remove(project: PathBuf, args: SessionRemoveArgs) -> Result<()> {
Sessions::remove(&project, &args.branch)?;
eprintln!("Session removed successfully");
Ok(())
}
34 changes: 30 additions & 4 deletions anna/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use color_eyre::Result;
use winlock::Agent;
use clap::{Parser, Subcommand};
use cmd::{agent::AgentArgs, session::SessionCommands};
use color_eyre::{eyre::Context, Result};

mod cmd;

#[derive(Parser)]
#[command(version, about)]
struct Args {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Create an agent session and run the agent.
Agent(AgentArgs),

/// Manage agent sessions
Session {
#[command(subcommand)]
command: SessionCommands,
},
}

fn main() -> Result<()> {
color_eyre::install()?;

let _agent = Agent::new();
let cli = Args::parse();
let project = std::env::current_dir().context("get working directory")?;

Ok(())
match cli.command {
Commands::Agent(args) => cmd::agent::main(project, args),
Commands::Session { command } => cmd::session::main(project, command),
}
}
1 change: 0 additions & 1 deletion winlock/.gitignore

This file was deleted.

15 changes: 14 additions & 1 deletion winlock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ version = "0.1.0"
edition = "2021"
authors = ["Jessica Black <me@jessica.black>"]
license = "MPL-2.0"
public = false
publish = false

[dependencies]
async-fs = "2.1.2"
async-tempfile = "0.7.0"
async-walkdir = "2.1.0"
bon = "3.3.2"
color-eyre = "0.6.3"
fslock = "0.2.1"
futures-lite = "2.6.0"
homedir = "0.3.4"
pollster = "0.4.0"
rustygit = "0.5.0"
serde = { version = "1.0.218", features = ["derive"] }
serde_json = "1.0.139"
tempfile = "3.17.1"
Loading