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

Function prepareForkedCommandContext

src/utils/forkedAgent.ts:191–232  ·  view source on GitHub ↗
(
  command: PromptCommand,
  args: string,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

189 * This handles the common setup that both SkillTool and slash commands need.
190 */
191export async function prepareForkedCommandContext(
192 command: PromptCommand,
193 args: string,
194 context: ToolUseContext,
195): Promise<PreparedForkedContext> {
196 // Get skill content with $ARGUMENTS replaced
197 const skillPrompt = await command.getPromptForCommand(args, context)
198 const skillContent = skillPrompt
199 .map(block => (block.type === 'text' ? block.text : ''))
200 .join('\n')
201
202 // Parse and prepare allowed tools
203 const allowedTools = parseToolListFromCLI(command.allowedTools ?? [])
204
205 // Create modified context with allowed tools
206 const modifiedGetAppState = createGetAppStateWithAllowedTools(
207 context.getAppState,
208 allowedTools,
209 )
210
211 // Use command.agent if specified, otherwise 'general-purpose'
212 const agentTypeName = command.agent ?? 'general-purpose'
213 const agents = context.options.agentDefinitions.activeAgents
214 const baseAgent =
215 agents.find(a => a.agentType === agentTypeName) ??
216 agents.find(a => a.agentType === 'general-purpose') ??
217 agents[0]
218
219 if (!baseAgent) {
220 throw new Error('No agent available for forked execution')
221 }
222
223 // Prepare prompt messages
224 const promptMessages = [createUserMessage({ content: skillContent })]
225
226 return {
227 skillContent,
228 modifiedGetAppState,
229 baseAgent,
230 promptMessages,
231 }
232}
233
234/**
235 * Extracts result text from agent messages.

Callers 2

executeForkedSkillFunction · 0.85

Calls 3

parseToolListFromCLIFunction · 0.85
createUserMessageFunction · 0.85

Tested by

no test coverage detected