MCPcopy Index your code
hub / github.com/Noumena-Network/code / tryClaimNextTask

Function tryClaimNextTask

src/utils/swarm/inProcessRunner.ts:625–658  ·  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

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

Callers 2

runInProcessTeammateFunction · 0.85

Calls 6

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

Tested by

no test coverage detected