agent-ecosystem/src/shared/utils/taskHistory.ts
iliya 5686d60d99 feat: implement startReview functionality and enhance review state management
- Added startReview function to initiate the review process for tasks, allowing transition to the review column without requiring completed status.
- Updated getCurrentReviewState and getEffectiveReviewState functions to include 'review_started' event type for accurate review state tracking.
- Enhanced task history management by introducing a new TaskReviewStartedEvent type.
- Updated documentation and user instructions to reflect the new review process, emphasizing the importance of calling review_start before review actions.
- Improved test coverage for the new startReview functionality and its integration with existing review processes.
2026-03-16 19:08:12 +02:00

51 lines
1.8 KiB
TypeScript

import type { TaskHistoryEvent, TeamReviewState, TeamTask, TeamTaskStatus } from '@shared/types';
/** Extract historyEvents from a task, defaulting to empty array. */
export function getTaskHistoryEvents(task: Pick<TeamTask, 'historyEvents'>): TaskHistoryEvent[] {
return Array.isArray(task.historyEvents) ? task.historyEvents : [];
}
/** Derive the current task status from historyEvents. Falls back to task.status if no events. */
export function getDerivedTaskStatus(
task: Pick<TeamTask, 'historyEvents' | 'status'>
): TeamTaskStatus {
const events = getTaskHistoryEvents(task);
for (let i = events.length - 1; i >= 0; i--) {
const event = events[i];
if (event.type === 'task_created') return event.status;
if (event.type === 'status_changed') return event.to;
}
return task.status;
}
/** Derive the current review state from historyEvents. */
export function getDerivedReviewState(task: Pick<TeamTask, 'historyEvents'>): TeamReviewState {
const events = getTaskHistoryEvents(task);
for (let i = events.length - 1; i >= 0; i--) {
const event = events[i];
if (
event.type === 'review_requested' ||
event.type === 'review_changes_requested' ||
event.type === 'review_approved' ||
event.type === 'review_started'
) {
return event.to;
}
// A status_changed to in_progress after a review event resets review state
if (event.type === 'status_changed' && event.to === 'in_progress') {
return 'none';
}
}
return 'none';
}
/** Get a full workflow snapshot from historyEvents. */
export function getTaskWorkflowSnapshot(task: Pick<TeamTask, 'historyEvents' | 'status'>): {
status: TeamTaskStatus;
reviewState: TeamReviewState;
} {
return {
status: getDerivedTaskStatus(task),
reviewState: getDerivedReviewState(task),
};
}