Skip to content

Commit 814a96a

Browse files
author
kiran-garre
committed
fix: Add feedback after calling todo_list commands
Updates: - The model now sees the updated todo list after invoking the todo_list tool - Todo lists shouldn't get stuck on marking a task as complete (in theory)
1 parent a9501e7 commit 814a96a

File tree

1 file changed

+25
-19
lines changed
  • crates/chat-cli/src/cli/chat/tools

1 file changed

+25
-19
lines changed

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

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::io::Write;
21
use std::collections::HashSet;
2+
use std::io::Write;
33
use std::time::{
44
SystemTime,
55
UNIX_EPOCH,
@@ -21,13 +21,6 @@ use serde::{
2121
use super::InvokeOutput;
2222
use crate::os::Os;
2323

24-
// Demo prompts:
25-
// Create a Python package layout with a blank main file and a blank utilities file. Start by making
26-
// a todo list. Design your own super simple programming task with 4 steps. Make a todo list for the
27-
// task, and begin executing those steps. Implement a basic input to Python type converter where the
28-
// user can input either a string or integer and it gets converted to the corresponding Python
29-
// object.
30-
3124
#[derive(Debug, Clone, Deserialize)]
3225
#[serde(tag = "command")]
3326
pub enum TodoInput {
@@ -58,7 +51,7 @@ pub enum TodoInput {
5851
Remove {
5952
remove_indices: Vec<usize>,
6053
new_description: Option<String>,
61-
}
54+
},
6255
}
6356

6457
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
@@ -188,7 +181,11 @@ impl TodoInput {
188181
TodoState::set_current_todo_id(os, id)?;
189182
TodoState::load(os, id)?
190183
},
191-
TodoInput::Add { new_tasks, insert_indices, new_description } => {
184+
TodoInput::Add {
185+
new_tasks,
186+
insert_indices,
187+
new_description,
188+
} => {
192189
let current_id = match TodoState::get_current_todo_id(os)? {
193190
Some(id) => id,
194191
None => bail!("No to-do list currently loaded"),
@@ -204,7 +201,10 @@ impl TodoInput {
204201
state.save(os, &current_id)?;
205202
state
206203
},
207-
TodoInput::Remove { remove_indices, new_description } => {
204+
TodoInput::Remove {
205+
remove_indices,
206+
new_description,
207+
} => {
208208
let current_id = match TodoState::get_current_todo_id(os)? {
209209
Some(id) => id,
210210
None => bail!("No to-do list currently loaded"),
@@ -219,12 +219,12 @@ impl TodoInput {
219219
}
220220
state.save(os, &current_id)?;
221221
state
222-
}
222+
},
223223
};
224224
state.display_list(output)?;
225225
output.flush()?;
226226

227-
Ok(Default::default())
227+
Ok(InvokeOutput { output: super::OutputKind::Json(serde_json::to_value(state)?) })
228228
}
229229

230230
pub fn queue_description(&self, _os: &Os, _output: &mut impl Write) -> Result<()> {
@@ -267,7 +267,11 @@ impl TodoInput {
267267
bail!("Loaded todo list is empty");
268268
}
269269
},
270-
TodoInput::Add { new_tasks, insert_indices, new_description } => {
270+
TodoInput::Add {
271+
new_tasks,
272+
insert_indices,
273+
new_description,
274+
} => {
271275
let current_id = match TodoState::get_current_todo_id(os)? {
272276
Some(id) => id,
273277
None => bail!("No todo list is currently loaded"),
@@ -285,7 +289,10 @@ impl TodoInput {
285289
bail!("New description cannot be empty");
286290
}
287291
},
288-
TodoInput::Remove { remove_indices, new_description } => {
292+
TodoInput::Remove {
293+
remove_indices,
294+
new_description,
295+
} => {
289296
let current_id = match TodoState::get_current_todo_id(os)? {
290297
Some(id) => id,
291298
None => bail!("No todo list is currently loaded"),
@@ -298,18 +305,17 @@ impl TodoInput {
298305
} else if new_description.is_some() && new_description.as_ref().unwrap().trim().is_empty() {
299306
bail!("New description cannot be empty");
300307
}
301-
}
308+
},
302309
}
303310
Ok(())
304311
}
305312
}
306313

307-
308314
/// Generated by Q
309-
fn has_duplicates<T>(vec: &[T]) -> bool
315+
fn has_duplicates<T>(vec: &[T]) -> bool
310316
where
311317
T: std::hash::Hash + Eq,
312318
{
313319
let mut seen = HashSet::with_capacity(vec.len());
314320
vec.iter().any(|item| !seen.insert(item))
315-
}
321+
}

0 commit comments

Comments
 (0)