Skip to content
13 changes: 11 additions & 2 deletions src/core/controller/ui/updateTaskStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export async function updateTaskStatus(
}

// Parse task ID to extract PRD ID, User Story ID, and Task ID
// Expected format: PRD1-US1-TASK1 or 1-US1-TASK1
const taskIdMatch = taskId.match(/^(?:PRD)?(\d+)-US(\d+)-TASK(\d+)$/)
// Expected format: PRD1-US1-TASK1 or 1-US1-TASK1 or US1-TASK1 (if PRD ID is missing)
const taskIdMatch = taskId.match(/^(?:(?:PRD)?(\d+)-)?US(\d+)-TASK(\d+)$/)

if (!taskIdMatch) {
return UpdateTaskStatusResponse.create({
Expand All @@ -86,6 +86,15 @@ export async function updateTaskStatus(
}

const [, prdId, usId, taskIdNum] = taskIdMatch

// If prdId is missing from the task ID, we need to find it from the user story ID
if (!prdId) {
return UpdateTaskStatusResponse.create({
success: false,
message: `PRD ID is missing from task ID: ${taskId}. Cannot determine which PRD file to update.`,
})
}

const prdFeatureFilePath = path.join(folderPath, "PRD", `PRD${prdId}-feature.json`)

try {
Expand Down
20 changes: 17 additions & 3 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ const ChatView = ({
// TAG:HAI - Track last successfully executed task ID
const [lastSuccessfullyExecutedTaskId, setLastSuccessfullyExecutedTaskId] = useState<string | undefined>(undefined)

// TAG:HAI - Reset lastSuccessfullyExecutedTaskId when task changes (new task started or task cleared)
useEffect(() => {
setLastSuccessfullyExecutedTaskId(undefined)
}, [task?.ts])

// TAG:HAI - Set input value when task is selected
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
Expand Down Expand Up @@ -466,14 +471,20 @@ const ChatView = ({
appearance="primary"
onClick={async () => {
try {
setLastSuccessfullyExecutedTaskId(undefined)

const request: UpdateTaskStatusRequest = {
metadata: {},
folderPath: haiConfigFolder,
taskId: selectedHaiTask?.id,
status: "Completed",
}
await UiServiceClient.updateTaskStatus(request)
setLastSuccessfullyExecutedTaskId(undefined)
const response = await UiServiceClient.updateTaskStatus(request)
if (response.success) {
onTaskSelect(null)
} else {
console.error("Failed to mark task as completed:", response.message)
}
} catch (error) {
console.error("Failed to mark task as completed:", error)
}
Expand All @@ -486,7 +497,10 @@ const ChatView = ({
</VSCodeButton>
<VSCodeButton
appearance="secondary"
onClick={() => setLastSuccessfullyExecutedTaskId(undefined)}
onClick={() => {
setLastSuccessfullyExecutedTaskId(undefined)
onTaskSelect(null)
}}
style={{
flexGrow: 1,
}}>
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/components/hai/DetailedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
onTaskSelect({
context: `${story?.name}: ${story?.description}`,
...task.original,
id: `${story?.id}-${task.original.id}`,
id: `PRD${story?.prdId}-${story?.id}-${task.original.id}`,
})
}}
title="Execute Task">
Expand Down Expand Up @@ -270,7 +270,7 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
onTaskSelect({
context: `${story?.name}: ${story?.description}`,
...selectedTask,
id: `${story?.id}-${selectedTask.id}`,
id: `PRD${story?.prdId}-${story?.id}-${selectedTask.id}`,
})
}}>
Execute Task
Expand Down
Loading