MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / runUserTurn

Function runUserTurn

compatible-shell/src/cli.mjs:98–142  ·  view source on GitHub ↗
(prompt, state, rl)

Source from the content-addressed store, hash-verified

96}
97
98async function runUserTurn(prompt, state, rl) {
99 state.messages.push({
100 role: 'user',
101 content: [{ type: 'text', text: prompt }],
102 })
103
104 for (let round = 0; round < state.maxToolRounds; round += 1) {
105 const response = await sendMessages({
106 ...state.clientConfig,
107 system: buildSystemPrompt(state.workspaceDir),
108 messages: state.messages,
109 tools: TOOL_DEFINITIONS,
110 maxTokens: state.clientConfig.maxTokens,
111 })
112
113 const assistantContent = normalizeAssistantContent(response.content)
114 state.messages.push({
115 role: 'assistant',
116 content: assistantContent,
117 })
118
119 printAssistantText(assistantContent)
120
121 const hasToolCalls = assistantContent.some(block => block.type === 'tool_use')
122 if (!hasToolCalls) {
123 await persistSession(state)
124 return
125 }
126
127 const toolResults = await executeToolCalls({
128 workspaceDir: state.workspaceDir,
129 assistantContent,
130 confirmShellCommand: command => confirmShellCommand(command, state, rl),
131 printLog: message => console.log(message),
132 })
133
134 state.messages.push({
135 role: 'user',
136 content: toolResults,
137 })
138 }
139
140 console.error('Reached the maximum tool rounds for this turn.')
141 await persistSession(state)
142}
143
144async function handleSlashCommand(line, state) {
145 switch (line) {

Callers 2

runPromptOnceFunction · 0.85
mainFunction · 0.85

Calls 8

sendMessagesFunction · 0.90
executeToolCallsFunction · 0.90
buildSystemPromptFunction · 0.85
printAssistantTextFunction · 0.85
persistSessionFunction · 0.85
confirmShellCommandFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected