MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / prepareForkedCommandContext

Function prepareForkedCommandContext

source code/utils/forkedAgent.ts:193–234  ·  view source on GitHub ↗
(
  command: PromptCommand,
  args: string,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

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