Skip to content

Commit 8158640

Browse files
committed
mainPrompt: Don't run terminal command check unless agent has access to terminal tool
1 parent 1ad643f commit 8158640

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

backend/src/main-prompt.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -50,66 +50,6 @@ export const mainPrompt = async (
5050
} = action
5151
const { fileContext, mainAgentState } = sessionState
5252

53-
if (prompt) {
54-
// Check if this is a direct terminal command
55-
const startTime = Date.now()
56-
const terminalCommand = await checkTerminalCommand(prompt, {
57-
clientSessionId,
58-
fingerprintId,
59-
userInputId: promptId,
60-
userId,
61-
})
62-
const duration = Date.now() - startTime
63-
64-
if (terminalCommand) {
65-
logger.debug(
66-
{
67-
duration,
68-
prompt,
69-
},
70-
`Detected terminal command in ${duration}ms, executing directly: ${prompt}`,
71-
)
72-
73-
const { output } = await requestToolCall(
74-
ws,
75-
promptId,
76-
'run_terminal_command',
77-
{
78-
command: terminalCommand,
79-
mode: 'user',
80-
process_type: 'SYNC',
81-
timeout_seconds: -1,
82-
},
83-
)
84-
85-
mainAgentState.messageHistory.push({
86-
role: 'tool',
87-
content: {
88-
type: 'tool-result',
89-
toolName: 'run_terminal_command',
90-
toolCallId: generateCompactId(),
91-
output: output,
92-
},
93-
})
94-
95-
const newSessionState = {
96-
...sessionState,
97-
messageHistory: expireMessages(
98-
mainAgentState.messageHistory,
99-
'userPrompt',
100-
),
101-
}
102-
103-
return {
104-
sessionState: newSessionState,
105-
output: {
106-
type: 'lastMessage',
107-
value: output,
108-
},
109-
}
110-
}
111-
}
112-
11353
const availableAgents = Object.keys(localAgentTemplates)
11454

11555
// Determine agent type - prioritize CLI agent selection, then config base agent, then cost mode
@@ -190,6 +130,66 @@ export const mainPrompt = async (
190130
mainAgentTemplate.spawnableAgents = updatedSubagents
191131
localAgentTemplates[agentType] = mainAgentTemplate
192132

133+
if (prompt && mainAgentTemplate.toolNames.includes('run_terminal_command')) {
134+
// Check if this is a direct terminal command
135+
const startTime = Date.now()
136+
const terminalCommand = await checkTerminalCommand(prompt, {
137+
clientSessionId,
138+
fingerprintId,
139+
userInputId: promptId,
140+
userId,
141+
})
142+
const duration = Date.now() - startTime
143+
144+
if (terminalCommand) {
145+
logger.debug(
146+
{
147+
duration,
148+
prompt,
149+
},
150+
`Detected terminal command in ${duration}ms, executing directly: ${prompt}`,
151+
)
152+
153+
const { output } = await requestToolCall(
154+
ws,
155+
promptId,
156+
'run_terminal_command',
157+
{
158+
command: terminalCommand,
159+
mode: 'user',
160+
process_type: 'SYNC',
161+
timeout_seconds: -1,
162+
},
163+
)
164+
165+
mainAgentState.messageHistory.push({
166+
role: 'tool',
167+
content: {
168+
type: 'tool-result',
169+
toolName: 'run_terminal_command',
170+
toolCallId: generateCompactId(),
171+
output: output,
172+
},
173+
})
174+
175+
const newSessionState = {
176+
...sessionState,
177+
messageHistory: expireMessages(
178+
mainAgentState.messageHistory,
179+
'userPrompt',
180+
),
181+
}
182+
183+
return {
184+
sessionState: newSessionState,
185+
output: {
186+
type: 'lastMessage',
187+
value: output,
188+
},
189+
}
190+
}
191+
}
192+
193193
const { agentState, output } = await loopAgentSteps(ws, {
194194
userInputId: promptId,
195195
prompt,

0 commit comments

Comments
 (0)