MCPcopy
hub / github.com/codeaashu/claude-code / tryClaimNextTask

Function tryClaimNextTask

src/utils/swarm/inProcessRunner.ts:624–657  ·  view source on GitHub ↗

* Try to claim an available task from the team's task list. * Returns the formatted prompt if a task was claimed, or undefined if none available.

(
  taskListId: string,
  agentName: string,
)

Source from the content-addressed store, hash-verified

622 * Returns the formatted prompt if a task was claimed, or undefined if none available.
623 */
624async function tryClaimNextTask(
625 taskListId: string,
626 agentName: string,
627): Promise<string | undefined> {
628 try {
629 const tasks = await listTasks(taskListId)
630 const availableTask = findAvailableTask(tasks)
631
632 if (!availableTask) {
633 return undefined
634 }
635
636 const result = await claimTask(taskListId, availableTask.id, agentName)
637
638 if (!result.success) {
639 logForDebugging(
640 `[inProcessRunner] Failed to claim task #${availableTask.id}: ${result.reason}`,
641 )
642 return undefined
643 }
644
645 // Also set status to in_progress so the UI reflects it immediately
646 await updateTask(taskListId, availableTask.id, { status: 'in_progress' })
647
648 logForDebugging(
649 `[inProcessRunner] Claimed task #${availableTask.id}: ${availableTask.subject}`,
650 )
651
652 return formatTaskAsPrompt(availableTask)
653 } catch (err) {
654 logForDebugging(`[inProcessRunner] Error checking task list: ${err}`)
655 return undefined
656 }
657}
658
659/**
660 * Result of waiting for messages.

Callers 2

runInProcessTeammateFunction · 0.85

Calls 6

listTasksFunction · 0.85
claimTaskFunction · 0.85
logForDebuggingFunction · 0.85
updateTaskFunction · 0.85
findAvailableTaskFunction · 0.70
formatTaskAsPromptFunction · 0.70

Tested by

no test coverage detected