1818from typing import Any , Dict , List , Optional
1919
2020from brainfile import (
21- Task ,
2221 Subtask ,
2322 addTaskFile ,
2423 completeTaskFile ,
2524 deleteTaskFile ,
2625 ensureV2Dirs ,
2726 findV2Task ,
28- generateNextFileTaskId ,
2927 getV2Dirs ,
30- listTasks ,
31- moveTaskFile ,
32- readTaskFile ,
3328 readTasksDir ,
3429 writeTaskFile ,
3530)
3631from brainfile .workspace import V2Dirs
3732
38-
3933# ---------------------------------------------------------------------------
4034# Constants
4135# ---------------------------------------------------------------------------
@@ -137,20 +131,23 @@ def list_tasks(self, scope: str = "board") -> List[Dict[str, Any]]:
137131 subtasks = t .subtasks or []
138132 total = len (subtasks )
139133 done = sum (1 for s in subtasks if s .completed )
140- tasks .append ({
141- "id" : t .id ,
142- "title" : t .title ,
143- "column" : t .column or ("logs" if location == "logs" else "in-progress" ),
144- "location" : location ,
145- "subtasks_total" : total ,
146- "subtasks_done" : done ,
147- "relpath" : self .relpath (
148- os .path .join (
149- dirs .boardDir if location == "board" else dirs .logsDir ,
150- f"{ t .id } .md" ,
151- )
152- ),
153- })
134+ tasks .append (
135+ {
136+ "id" : t .id ,
137+ "title" : t .title ,
138+ "column" : t .column
139+ or ("logs" if location == "logs" else "in-progress" ),
140+ "location" : location ,
141+ "subtasks_total" : total ,
142+ "subtasks_done" : done ,
143+ "relpath" : self .relpath (
144+ os .path .join (
145+ dirs .boardDir if location == "board" else dirs .logsDir ,
146+ f"{ t .id } .md" ,
147+ )
148+ ),
149+ }
150+ )
154151 return tasks
155152
156153 def find_task (self , task_id : str ) -> Optional [Dict [str , Any ]]:
@@ -178,7 +175,6 @@ def create_task(
178175 self ,
179176 title : str ,
180177 column : str = "in-progress" ,
181- task_type : str = "task" ,
182178 description : Optional [str ] = None ,
183179 subtasks : Optional [List [str ]] = None ,
184180 ) -> Dict [str , Any ]:
@@ -188,7 +184,7 @@ def create_task(
188184 {
189185 "title" : title ,
190186 "column" : column ,
191- "type" : task_type ,
187+ "type" : "task" ,
192188 "description" : description or "" ,
193189 "subtasks" : subtasks or [],
194190 },
@@ -202,10 +198,10 @@ def create_task(
202198 "id" : task .id ,
203199 "title" : task .title ,
204200 "column" : task .column ,
205- "type" : task .type or "task" ,
206201 "location" : "board" ,
207202 "path" : Path (result ["filePath" ]),
208203 "relpath" : self .relpath (result ["filePath" ]),
204+ "task" : task ,
209205 }
210206
211207 def update_task (
@@ -233,6 +229,7 @@ def update_task(
233229
234230 if changed :
235231 from datetime import datetime
232+
236233 updates ["updated_at" ] = datetime .now ().isoformat ()
237234 updated_task = task .model_copy (update = updates )
238235 writeTaskFile (str (found ["path" ]), updated_task , found ["body" ])
@@ -351,13 +348,10 @@ def get_or_create_session_task(self, coder) -> dict:
351348 task_id = best ["id" ]
352349 else :
353350 # Create a new task
354- from datetime import date
355-
356- title = f"Session { date .today ().isoformat ()} "
351+ title = self .auto_title (None )
357352 created = self .create_task (title = title , column = "in-progress" )
358353 task_id = created ["id" ]
359- found = self .find_task (task_id )
360- task = found ["task" ]
354+ task = created ["task" ]
361355
362356 # Set active_task_id + update TUI — but do NOT add the file to
363357 # coder context so the agent never sees raw YAML.
@@ -433,11 +427,13 @@ def update_task_subtasks(
433427 title = str (item .get ("task" , "" )).strip ()
434428 if not title :
435429 continue
436- parsed .append ({
437- "title" : title ,
438- "completed" : bool (item .get ("done" , False )),
439- "current" : bool (item .get ("current" , False )),
440- })
430+ parsed .append (
431+ {
432+ "title" : title ,
433+ "completed" : bool (item .get ("done" , False )),
434+ "current" : bool (item .get ("current" , False )),
435+ }
436+ )
441437
442438 if not append :
443439 # Reorder: current first, then remaining, then done
@@ -462,20 +458,25 @@ def update_task_subtasks(
462458
463459 for sub in ordered :
464460 max_idx += 1
465- new_subtasks .append (Subtask (
466- id = f"{ task .id } -{ max_idx } " ,
467- title = sub ["title" ],
468- completed = sub ["completed" ],
469- ))
461+ new_subtasks .append (
462+ Subtask (
463+ id = f"{ task .id } -{ max_idx } " ,
464+ title = sub ["title" ],
465+ completed = sub ["completed" ],
466+ )
467+ )
470468
471469 new_column = "in-progress"
472470
473471 from datetime import datetime
474- updated_task = task .model_copy (update = {
475- "subtasks" : new_subtasks ,
476- "column" : new_column ,
477- "updated_at" : datetime .now ().isoformat (),
478- })
472+
473+ updated_task = task .model_copy (
474+ update = {
475+ "subtasks" : new_subtasks ,
476+ "column" : new_column ,
477+ "updated_at" : datetime .now ().isoformat (),
478+ }
479+ )
479480
480481 path = found ["path" ]
481482 writeTaskFile (str (path ), updated_task , found ["body" ])
@@ -514,7 +515,9 @@ def open_task_in_context(
514515 coder .abs_fnames .add (abs_path )
515516 coder .check_added_files ()
516517 if explicit :
517- coder .io .tool_output (f"Opened task '{ found ['id' ]} ' as editable: { relpath } " )
518+ coder .io .tool_output (
519+ f"Opened task '{ found ['id' ]} ' as editable: { relpath } "
520+ )
518521 else :
519522 if abs_path in coder .abs_fnames :
520523 coder .abs_fnames .remove (abs_path )
@@ -524,7 +527,9 @@ def open_task_in_context(
524527 raise ValueError (f"Unable to read task file: { relpath } " )
525528 coder .abs_read_only_fnames .add (abs_path )
526529 if explicit :
527- coder .io .tool_output (f"Opened task '{ found ['id' ]} ' as read-only: { relpath } " )
530+ coder .io .tool_output (
531+ f"Opened task '{ found ['id' ]} ' as read-only: { relpath } "
532+ )
528533
529534 if hasattr (coder , "use_enhanced_context" ) and coder .use_enhanced_context :
530535 if hasattr (coder , "_calculate_context_block_tokens" ):
@@ -569,9 +574,13 @@ def clear_active_task(self, coder) -> None:
569574 set_active_task = getattr (io , "set_active_task" , None )
570575 if callable (set_active_task ):
571576 set_active_task (
572- task_id = "" , title = "" , column = "" ,
573- subtasks_done = 0 , subtasks_total = 0 ,
574- mode = "" , location = "" ,
577+ task_id = "" ,
578+ title = "" ,
579+ column = "" ,
580+ subtasks_done = 0 ,
581+ subtasks_total = 0 ,
582+ mode = "" ,
583+ location = "" ,
575584 )
576585
577586 def drop_task_from_context (
@@ -580,7 +589,9 @@ def drop_task_from_context(
580589 task_id : Optional [str ] = None ,
581590 clear_active : bool = True ,
582591 ) -> Dict [str , Any ]:
583- target = _normalize_task_id (task_id or getattr (coder , "active_task_id" , "" ) or "" )
592+ target = _normalize_task_id (
593+ task_id or getattr (coder , "active_task_id" , "" ) or ""
594+ )
584595 if not target :
585596 raise ValueError ("No active task to drop. Use /task drop <task-id>." )
586597
@@ -662,6 +673,6 @@ def render_task_todo_block(self, task_id: str) -> Optional[str]:
662673
663674 total = len (done_tasks ) + len (remaining_tasks )
664675 done = len (done_tasks )
665- result += f"\n Active: { task .title } | { task .column or 'todo ' } | { done } /{ total } \n "
676+ result += f"\n Active: { task .title } | { task .column or 'in-progress ' } | { done } /{ total } \n "
666677 result += "</context>"
667678 return result
0 commit comments