Skip to content

Commit f2fc3d1

Browse files
author
kiran-garre
committed
chore: Change variable names, add comments, add file extension to todo states
Updates: - Todo list state files now have ".json" extensions
1 parent 4b684f9 commit f2fc3d1

File tree

8 files changed

+181
-151
lines changed

8 files changed

+181
-151
lines changed

crates/chat-cli/src/cli/agent/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ impl Agents {
728728
"use_aws" => "trust read-only commands".dark_grey(),
729729
"report_issue" => "trusted".dark_green().bold(),
730730
"thinking" => "trusted (prerelease)".dark_green().bold(),
731+
"todo_list" => "trusted".dark_green().bold(),
731732
_ if self.trust_all_tools => "trusted".dark_grey().bold(),
732733
_ => "not trusted".dark_grey(),
733734
};

crates/chat-cli/src/cli/chat/cli/todos.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ use crossterm::style::{
77
use dialoguer::FuzzySelect;
88
use eyre::Result;
99

10-
use crate::cli::chat::tools::todo::TodoState;
10+
use crate::cli::chat::tools::todo::{
11+
TodoListState,
12+
delete_todo,
13+
get_all_todos,
14+
};
1115
use crate::cli::chat::{
1216
ChatError,
1317
ChatSession,
1418
ChatState,
1519
};
1620
use crate::os::Os;
1721

22+
/// Defines subcommands that allow users to view and manage todo lists
1823
#[derive(Debug, PartialEq, Subcommand)]
1924
pub enum TodoSubcommand {
2025
/// Delete all completed to-do lists
@@ -62,15 +67,15 @@ impl TodoSubcommand {
6267
pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
6368
match self {
6469
Self::ClearFinished => {
65-
let (todos, errors) = match TodoState::get_all_todos(os).await {
70+
let (todos, errors) = match get_all_todos(os).await {
6671
Ok(res) => res,
6772
Err(e) => return Err(ChatError::Custom(format!("Could not get to-do lists: {e}").into())),
6873
};
6974
let mut cleared_one = false;
7075

7176
for todo_status in todos.iter() {
7277
if todo_status.completed.iter().all(|b| *b) {
73-
match TodoState::delete_todo(os, &todo_status.id).await {
78+
match delete_todo(os, &todo_status.id).await {
7479
Ok(_) => cleared_one = true,
7580
Err(e) => {
7681
return Err(ChatError::Custom(format!("Could not delete to-do list: {e}").into()));
@@ -119,7 +124,7 @@ impl TodoSubcommand {
119124
execute!(session.stderr, style::Print("No to-do lists to view!\n"))?;
120125
} else if let Some(index) = fuzzy_select_todos(&entries, "Select a to-do list to view:") {
121126
if index < entries.len() {
122-
let list = TodoState::load(os, &entries[index].id).await.map_err(|e| {
127+
let list = TodoListState::load(os, &entries[index].id).await.map_err(|e| {
123128
ChatError::Custom(format!("Could not load current to-do list: {e}").into())
124129
})?;
125130
execute!(
@@ -145,14 +150,14 @@ impl TodoSubcommand {
145150
execute!(session.stderr, style::Print("No to-do lists to delete!\n"))?;
146151
} else if all {
147152
for entry in entries {
148-
TodoState::delete_todo(os, &entry.id)
153+
delete_todo(os, &entry.id)
149154
.await
150155
.map_err(|_e| ChatError::Custom("Could not delete all to-do lists".into()))?;
151156
}
152157
execute!(session.stderr, style::Print("✔ Deleted all to-do lists!\n".green()),)?;
153158
} else if let Some(index) = fuzzy_select_todos(&entries, "Select a to-do list to delete:") {
154159
if index < entries.len() {
155-
TodoState::delete_todo(os, &entries[index].id).await.map_err(|e| {
160+
delete_todo(os, &entries[index].id).await.map_err(|e| {
156161
ChatError::Custom(format!("Could not delete the selected to-do list: {e}").into())
157162
})?;
158163
execute!(
@@ -174,7 +179,7 @@ impl TodoSubcommand {
174179
/// Convert all to-do list state entries to displayable entries
175180
async fn get_descriptions_and_statuses(os: &Os) -> Result<Vec<TodoDisplayEntry>> {
176181
let mut out = Vec::new();
177-
let (todos, _) = TodoState::get_all_todos(os).await?;
182+
let (todos, _) = get_all_todos(os).await?;
178183
for todo in todos.iter() {
179184
out.push(TodoDisplayEntry {
180185
num_completed: todo.completed.iter().filter(|b| **b).count(),

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ use crate::api_client::{
131131
};
132132
use crate::auth::AuthError;
133133
use crate::auth::builder_id::is_idc_user;
134-
use crate::cli::TodoState;
134+
use crate::cli::TodoListState;
135135
use crate::cli::agent::Agents;
136136
use crate::cli::chat::cli::SlashCommand;
137137
use crate::cli::chat::cli::prompts::{
@@ -655,7 +655,7 @@ impl ChatSession {
655655
// Create for cleaner error handling for todo lists
656656
// This is more of a convenience thing but is not required, so the Result
657657
// is ignored
658-
let _ = TodoState::init_dir(os).await;
658+
let _ = TodoListState::init_dir(os).await;
659659

660660
Ok(Self {
661661
stdout,
@@ -2802,7 +2802,7 @@ impl ChatSession {
28022802
pub async fn resume_todo_request(&mut self, os: &mut Os, id: &str) -> Result<ChatState, ChatError> {
28032803
// Have to unpack each value separately since Reports can't be converted to
28042804
// ChatError
2805-
let todo_list = match TodoState::load(os, id).await {
2805+
let todo_list = match TodoListState::load(os, id).await {
28062806
Ok(todo) => todo,
28072807
Err(e) => {
28082808
return Err(ChatError::Custom(format!("Error getting todo list: {e}").into()));

crates/chat-cli/src/cli/chat/prompt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ pub const COMMANDS: &[&str] = &[
8383
"/save",
8484
"/load",
8585
"/subscribe",
86+
"/todos",
87+
"/todos resume",
88+
"/todos clear-finished",
89+
"/todos view",
90+
"/todos delete",
8691
];
8792

8893
/// Complete commands that start with a slash

crates/chat-cli/src/cli/chat/tool_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::cli::chat::tools::fs_write::FsWrite;
7979
use crate::cli::chat::tools::gh_issue::GhIssue;
8080
use crate::cli::chat::tools::knowledge::Knowledge;
8181
use crate::cli::chat::tools::thinking::Thinking;
82-
use crate::cli::chat::tools::todo::TodoInput;
82+
use crate::cli::chat::tools::todo::TodoList;
8383
use crate::cli::chat::tools::use_aws::UseAws;
8484
use crate::cli::chat::tools::{
8585
Tool,
@@ -1067,7 +1067,7 @@ impl ToolManager {
10671067
"report_issue" => Tool::GhIssue(serde_json::from_value::<GhIssue>(value.args).map_err(map_err)?),
10681068
"thinking" => Tool::Thinking(serde_json::from_value::<Thinking>(value.args).map_err(map_err)?),
10691069
"knowledge" => Tool::Knowledge(serde_json::from_value::<Knowledge>(value.args).map_err(map_err)?),
1070-
"todo_list" => Tool::Todo(serde_json::from_value::<TodoInput>(value.args).map_err(map_err)?),
1070+
"todo_list" => Tool::Todo(serde_json::from_value::<TodoList>(value.args).map_err(map_err)?),
10711071
// Note that this name is namespaced with server_name{DELIMITER}tool_name
10721072
name => {
10731073
// Note: tn_map also has tools that underwent no transformation. In otherwords, if

crates/chat-cli/src/cli/chat/tools/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use serde::{
3636
Serialize,
3737
};
3838
use thinking::Thinking;
39-
use todo::TodoInput;
39+
use todo::TodoList;
4040
use tracing::error;
4141
use use_aws::UseAws;
4242

@@ -81,7 +81,7 @@ pub enum Tool {
8181
GhIssue(GhIssue),
8282
Knowledge(Knowledge),
8383
Thinking(Thinking),
84-
Todo(TodoInput),
84+
Todo(TodoList),
8585
}
8686

8787
impl Tool {

0 commit comments

Comments
 (0)