Something went wrong. Try again.
source dump of claude code forked from oppi.li/claude-code
Something went wrong. Try again.
3.0 kB · 102 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103/** * In-Process Teammate Helpers * * Helper functions for in-process teammate integration. * Provides utilities to: * - Find task ID by agent name * - Handle plan approval responses * - Update awaitingPlanApproval state * - Detect permission-related messages */
import type { AppState } from '../state/AppState.js'import { type InProcessTeammateTaskState, isInProcessTeammateTask,} from '../tasks/InProcessTeammateTask/types.js'import { updateTaskState } from './task/framework.js'import { isPermissionResponse, isSandboxPermissionResponse, type PlanApprovalResponseMessage,} from './teammateMailbox.js'
type SetAppState = (updater: (prev: AppState) => AppState) => void
/** * Find the task ID for an in-process teammate by agent name. * * @param agentName - The agent name (e.g., "researcher") * @param appState - Current AppState * @returns Task ID if found, undefined otherwise */export function findInProcessTeammateTaskId( agentName: string, appState: AppState,): string | undefined { for (const task of Object.values(appState.tasks)) { if ( isInProcessTeammateTask(task) && task.identity.agentName === agentName ) { return task.id } } return undefined}
/** * Set awaitingPlanApproval state for an in-process teammate. * * @param taskId - Task ID of the in-process teammate * @param setAppState - AppState setter * @param awaiting - Whether teammate is awaiting plan approval */export function setAwaitingPlanApproval( taskId: string, setAppState: SetAppState, awaiting: boolean,): void { updateTaskState<InProcessTeammateTaskState>(taskId, setAppState, task => ({ ...task, awaitingPlanApproval: awaiting, }))}
/** * Handle plan approval response for an in-process teammate. * Called by the message callback when a plan_approval_response arrives. * * This resets awaitingPlanApproval to false. The permissionMode from the * response is handled separately by the agent loop (Task #11). * * @param taskId - Task ID of the in-process teammate * @param _response - The plan approval response message (for future use) * @param setAppState - AppState setter */export function handlePlanApprovalResponse( taskId: string, _response: PlanApprovalResponseMessage, setAppState: SetAppState,): void { setAwaitingPlanApproval(taskId, setAppState, false)}
// ============ Permission Delegation Helpers ============
/** * Check if a message is a permission-related response. * Used by in-process teammate message handlers to detect and process * permission responses from the team leader. * * Handles both tool permissions and sandbox (network host) permissions. * * @param messageText - The raw message text to check * @returns true if the message is a permission response */export function isPermissionRelatedResponse(messageText: string): boolean { return ( !!isPermissionResponse(messageText) || !!isSandboxPermissionResponse(messageText) )}