@@ -188,17 +188,31 @@ export class StoreManager {
188188 // Tasks
189189 // =========================================================================
190190
191- async createTask ( data : TaskCreate ) : Promise < TaskRecord > {
192- const embedding = await this . embedFn ( `${ data . title } ${ data . description ?? '' } ` ) ;
193- const record = this . scoped . tasks . create ( data , embedding ) ;
194- mirrorTaskCreate ( `${ this . projectDir } /.tasks` , record . slug , {
191+ /**
192+ * Build the TaskAttrs object passed to mirrorTaskCreate/mirrorTaskUpdate.
193+ * Resolves the numeric `assigneeId` to a human-readable team-member slug for
194+ * the markdown frontmatter — falls back to `null` when the team_members row
195+ * has been removed (orphaned assignment).
196+ */
197+ private buildMirrorTaskAttrs ( record : TaskRecord ) {
198+ let assignee : string | null = null ;
199+ if ( record . assigneeId != null ) {
200+ assignee = this . store . team . get ( record . assigneeId ) ?. slug ?? null ;
201+ }
202+ return {
195203 title : record . title , description : record . description ,
196204 status : record . status , priority : record . priority ,
197- tags : record . tags , order : record . order , assignee : null ,
205+ tags : record . tags , order : record . order , assignee,
198206 dueDate : record . dueDate , estimate : record . estimate ,
199207 completedAt : record . completedAt ,
200208 createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
201- } , [ ] ) ;
209+ } ;
210+ }
211+
212+ async createTask ( data : TaskCreate ) : Promise < TaskRecord > {
213+ const embedding = await this . embedFn ( `${ data . title } ${ data . description ?? '' } ` ) ;
214+ const record = this . scoped . tasks . create ( data , embedding ) ;
215+ mirrorTaskCreate ( `${ this . projectDir } /.tasks` , record . slug , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
202216 this . recordTaskMirrorWrites ( record . slug ) ;
203217 this . emit ( 'task:created' , { projectId : this . projectId , taskId : record . id } ) ;
204218 return record ;
@@ -215,14 +229,7 @@ export class StoreManager {
215229 embedding = await this . embedFn ( `${ title } ${ description } ` ) ;
216230 }
217231 const record = this . scoped . tasks . update ( taskId , patch , embedding , authorId , expectedVersion ) ;
218- mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , patch , {
219- title : record . title , description : record . description ,
220- status : record . status , priority : record . priority ,
221- tags : record . tags , order : record . order , assignee : null ,
222- dueDate : record . dueDate , estimate : record . estimate ,
223- completedAt : record . completedAt ,
224- createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
225- } , [ ] ) ;
232+ mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , patch , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
226233 this . recordTaskMirrorWrites ( record . slug ) ;
227234 this . emit ( 'task:updated' , { projectId : this . projectId , taskId } ) ;
228235 return record ;
@@ -238,14 +245,7 @@ export class StoreManager {
238245
239246 moveTask ( taskId : number , status : TaskStatus , targetOrder ?: number , authorId ?: number , expectedVersion ?: number ) : TaskRecord {
240247 const record = this . scoped . tasks . move ( taskId , status , targetOrder , authorId , expectedVersion ) ;
241- mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { status } , {
242- title : record . title , description : record . description ,
243- status : record . status , priority : record . priority ,
244- tags : record . tags , order : record . order , assignee : null ,
245- dueDate : record . dueDate , estimate : record . estimate ,
246- completedAt : record . completedAt ,
247- createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
248- } , [ ] ) ;
248+ mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { status } , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
249249 this . recordTaskMirrorWrites ( record . slug ) ;
250250 this . emit ( 'task:updated' , { projectId : this . projectId , taskId } ) ;
251251 this . emit ( 'task:moved' , { projectId : this . projectId , taskId, status } ) ;
@@ -256,14 +256,7 @@ export class StoreManager {
256256 const record = this . scoped . tasks . reorder ( taskId , order , status , authorId ) ;
257257 const patch : TaskPatch = { order } ;
258258 if ( status ) patch . status = status ;
259- mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , patch , {
260- title : record . title , description : record . description ,
261- status : record . status , priority : record . priority ,
262- tags : record . tags , order : record . order , assignee : null ,
263- dueDate : record . dueDate , estimate : record . estimate ,
264- completedAt : record . completedAt ,
265- createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
266- } , [ ] ) ;
259+ mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , patch , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
267260 this . recordTaskMirrorWrites ( record . slug ) ;
268261 this . emit ( 'task:updated' , { projectId : this . projectId , taskId } ) ;
269262 this . emit ( 'task:reordered' , { projectId : this . projectId , taskId, order } ) ;
@@ -310,14 +303,7 @@ export class StoreManager {
310303 for ( const id of taskIds ) {
311304 const record = this . scoped . tasks . get ( id ) ;
312305 if ( ! record ) continue ;
313- mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { status } , {
314- title : record . title , description : record . description ,
315- status : record . status , priority : record . priority ,
316- tags : record . tags , order : record . order , assignee : null ,
317- dueDate : record . dueDate , estimate : record . estimate ,
318- completedAt : record . completedAt ,
319- createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
320- } , [ ] ) ;
306+ mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { status } , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
321307 this . recordTaskMirrorWrites ( record . slug ) ;
322308 }
323309 this . emit ( 'task:bulk_moved' , { projectId : this . projectId , taskIds, status, count } ) ;
@@ -330,14 +316,7 @@ export class StoreManager {
330316 for ( const id of taskIds ) {
331317 const record = this . scoped . tasks . get ( id ) ;
332318 if ( ! record ) continue ;
333- mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { priority } , {
334- title : record . title , description : record . description ,
335- status : record . status , priority : record . priority ,
336- tags : record . tags , order : record . order , assignee : null ,
337- dueDate : record . dueDate , estimate : record . estimate ,
338- completedAt : record . completedAt ,
339- createdAt : record . createdAt , updatedAt : record . updatedAt , version : record . version ,
340- } , [ ] ) ;
319+ mirrorTaskUpdate ( `${ this . projectDir } /.tasks` , record . slug , { priority } , this . buildMirrorTaskAttrs ( record ) , [ ] ) ;
341320 this . recordTaskMirrorWrites ( record . slug ) ;
342321 }
343322 this . emit ( 'task:bulk_priority' , { projectId : this . projectId , taskIds, priority, count } ) ;
@@ -619,6 +598,14 @@ export class StoreManager {
619598 const existing = this . scoped . tasks . getBySlug ( parsed . id ) ;
620599 const embedding = await this . embedFn ( `${ parsed . title } ${ parsed . description } ` ) ;
621600
601+ // Resolve frontmatter `assignee: <slug>` → numeric team_members.id.
602+ // Unknown slug → null (orphaned mirror file references a member that no
603+ // longer exists). Empty string from frontmatter is also treated as unset.
604+ let assigneeId : number | null = null ;
605+ if ( parsed . assignee ) {
606+ assigneeId = this . store . team . getBySlug ( parsed . assignee ) ?. id ?? null ;
607+ }
608+
622609 let record : TaskRecord ;
623610 if ( existing ) {
624611 record = this . scoped . tasks . update ( existing . id , {
@@ -630,6 +617,7 @@ export class StoreManager {
630617 dueDate : parsed . dueDate ,
631618 estimate : parsed . estimate ,
632619 completedAt : parsed . completedAt ,
620+ assigneeId,
633621 } , embedding ) ;
634622 } else {
635623 record = this . scoped . tasks . create ( {
@@ -641,6 +629,7 @@ export class StoreManager {
641629 dueDate : parsed . dueDate ,
642630 estimate : parsed . estimate ,
643631 completedAt : parsed . completedAt ,
632+ assigneeId : assigneeId ?? undefined ,
644633 slug : parsed . id ,
645634 createdAt : parsed . createdAt ?? undefined ,
646635 updatedAt : parsed . updatedAt ?? undefined ,
0 commit comments