From bf69c43e2fa41d0651c3c7a31133f21249ac0fb5 Mon Sep 17 00:00:00 2001 From: Azreen Jamal Date: Fri, 6 Mar 2026 15:38:04 +0800 Subject: [PATCH] fix: update task-loop section matching for Bug Intake project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SECTIONS now uses arrays of candidate names searched in priority order - Maps Bug Intake sections: New Bugs→TODO, Under Review→IN_PROGRESS, Resolved→DONE - Added findFirstSection helper for array-based section lookup --- pi-worker/src/scheduler/task-loop.ts | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/pi-worker/src/scheduler/task-loop.ts b/pi-worker/src/scheduler/task-loop.ts index f749642..6396112 100644 --- a/pi-worker/src/scheduler/task-loop.ts +++ b/pi-worker/src/scheduler/task-loop.ts @@ -5,12 +5,11 @@ import { FileLock } from "./lock.js"; import type { Config } from "../config.js"; import type { AsanaTask } from "../asana/types.js"; -// Section names in Asana board +// Section names in Asana board (searched in order, partial case-insensitive match) const SECTIONS = { - TODO: "To Do", - IN_PROGRESS: "In Progress", - DONE: "Done", - PI_WORKER: "Pi Worker", // Optional dedicated section + TODO: ["Pi Worker", "To Do", "New Bugs", "Ready for Development"], + IN_PROGRESS: ["In Progress", "Under Review"], + DONE: ["Done", "Resolved"], }; export class TaskLoop { @@ -92,11 +91,14 @@ export class TaskLoop { try { logger.info("task-loop", "Polling for Asana tasks..."); - // Try dedicated "Pi Worker" section first, then "To Do" - let tasks = await this.asana.getIncompleteTasks(this.config.asanaProjectGid, SECTIONS.PI_WORKER); - - if (tasks.length === 0) { - tasks = await this.asana.getIncompleteTasks(this.config.asanaProjectGid, SECTIONS.TODO); + // Search TODO sections in priority order + let tasks: AsanaTask[] = []; + for (const sectionName of SECTIONS.TODO) { + tasks = await this.asana.getIncompleteTasks(this.config.asanaProjectGid, sectionName); + if (tasks.length > 0) { + logger.info("task-loop", `Found ${tasks.length} task(s) in "${sectionName}"`); + break; + } } if (tasks.length === 0) { @@ -117,10 +119,18 @@ export class TaskLoop { } } + private async findFirstSection(candidates: string[]) { + for (const name of candidates) { + const section = await this.asana.findSection(this.config.asanaProjectGid, name); + if (section) return section; + } + return null; + } + private async executeTask(task: AsanaTask) { try { // Move to "In Progress" - const inProgressSection = await this.asana.findSection(this.config.asanaProjectGid, SECTIONS.IN_PROGRESS); + const inProgressSection = await this.findFirstSection(SECTIONS.IN_PROGRESS); if (inProgressSection) { await this.asana.moveTaskToSection(task.gid, inProgressSection.gid); } @@ -152,7 +162,7 @@ export class TaskLoop { if (result.success) { // Move to "Done" and mark complete - const doneSection = await this.asana.findSection(this.config.asanaProjectGid, SECTIONS.DONE); + const doneSection = await this.findFirstSection(SECTIONS.DONE); if (doneSection) { await this.asana.moveTaskToSection(task.gid, doneSection.gid); } @@ -160,7 +170,7 @@ export class TaskLoop { logger.info("task-loop", `Task completed: ${task.name}`); } else { // Move back to To Do on failure - const todoSection = await this.asana.findSection(this.config.asanaProjectGid, SECTIONS.TODO); + const todoSection = await this.findFirstSection(SECTIONS.TODO); if (todoSection) { await this.asana.moveTaskToSection(task.gid, todoSection.gid); }