MCPcopy Create free account
hub / github.com/WJX20/claude-code / backgroundAgentTask

Function backgroundAgentTask

src/tasks/LocalAgentTask/LocalAgentTask.tsx:621–653  ·  view source on GitHub ↗
(taskId: string, getAppState: () => AppState, setAppState: SetAppState)

Source from the content-addressed store, hash-verified

619 * @returns true if backgrounded successfully, false otherwise
620 */
621export function backgroundAgentTask(taskId: string, getAppState: () => AppState, setAppState: SetAppState): boolean {
622 const state = getAppState();
623 const task = state.tasks[taskId];
624 if (!isLocalAgentTask(task) || task.isBackgrounded) {
625 return false;
626 }
627
628 // Update state to mark as backgrounded
629 setAppState(prev => {
630 const prevTask = prev.tasks[taskId];
631 if (!isLocalAgentTask(prevTask)) {
632 return prev;
633 }
634 return {
635 ...prev,
636 tasks: {
637 ...prev.tasks,
638 [taskId]: {
639 ...prevTask,
640 isBackgrounded: true
641 }
642 }
643 };
644 });
645
646 // Resolve the background signal to interrupt the agent loop
647 const resolver = backgroundSignalResolvers.get(taskId);
648 if (resolver) {
649 resolver();
650 backgroundSignalResolvers.delete(taskId);
651 }
652 return true;
653}
654
655/**
656 * Unregister a foreground agent task when the agent completes without being backgrounded.

Callers 1

backgroundAllFunction · 0.85

Calls 4

isLocalAgentTaskFunction · 0.85
deleteMethod · 0.80
getAppStateFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected