MCPcopy Create free account
hub / github.com/PankajKumardev/claude-code-clone / processUserInput

Function processUserInput

src/index.ts:11–82  ·  view source on GitHub ↗
(
  cli: CLIInterface,
  userInput: string,
  conversation: any,
  availableTools: any[]
)

Source from the content-addressed store, hash-verified

9
10// Helper function to process user input
11async function processUserInput(
12 cli: CLIInterface,
13 userInput: string,
14 conversation: any,
15 availableTools: any[]
16) {
17 // Handle commands
18 if (userInput.toLowerCase() === '/exit') {
19 cli.displayInfo('Goodbye! 👋');
20 return 'exit';
21 }
22
23 if (userInput.toLowerCase() === '/help') {
24 cli.displayHelp();
25 return 'continue';
26 }
27
28 if (userInput.toLowerCase() === '/tools') {
29 cli.displayTools(availableTools);
30 return 'continue';
31 }
32
33 // Process user message through the agent
34 cli.displayThinking();
35
36 // Load previous conversation history from database (last 10 messages to stay within context limits)
37 const conversationHistory = await conversationService.getConversationMessages(
38 conversation.id,
39 10
40 );
41
42 // Create initial state with conversation history + new message
43 const initialState = {
44 messages: [...conversationHistory, new HumanMessage(userInput)],
45 conversationId: conversation.id,
46 shouldContinue: true,
47 toolResults: {},
48 metadata: {
49 workingDirectory: process.cwd(),
50 },
51 };
52
53 // Run the graph with streaming to show tool executions
54 const result = await graph.invoke(initialState);
55
56 cli.stopThinking();
57
58 // Find the final AI response (last AIMessage that's not empty)
59 let finalResponse = '';
60 for (let i = result.messages.length - 1; i >= 0; i--) {
61 const msg = result.messages[i];
62 if (
63 msg instanceof AIMessage &&
64 msg.content &&
65 typeof msg.content === 'string' &&
66 msg.content.trim().length > 0
67 ) {
68 finalResponse = msg.content;

Callers 1

mainFunction · 0.85

Calls 7

displayInfoMethod · 0.80
displayHelpMethod · 0.80
displayToolsMethod · 0.80
displayThinkingMethod · 0.80
stopThinkingMethod · 0.80
displayResponseMethod · 0.80

Tested by

no test coverage detected