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

Function backgroundAgentTask

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

Source from the content-addressed store, hash-verified

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

Callers 1

backgroundAllFunction · 0.85

Calls 4

isLocalAgentTaskFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
getAppStateFunction · 0.50

Tested by

no test coverage detected