MCPcopy Create free account
hub / github.com/freecodexyz/free-code / validateIncompleteCommands

Function validateIncompleteCommands

src/tools/BashTool/bashSecurity.ts:244–286  ·  view source on GitHub ↗
(
  context: ValidationContext,
)

Source from the content-addressed store, hash-verified

242}
243
244function validateIncompleteCommands(
245 context: ValidationContext,
246): PermissionResult {
247 const { originalCommand } = context
248 const trimmed = originalCommand.trim()
249
250 if (/^\s*\t/.test(originalCommand)) {
251 logEvent('tengu_bash_security_check_triggered', {
252 checkId: BASH_SECURITY_CHECK_IDS.INCOMPLETE_COMMANDS,
253 subId: 1,
254 })
255 return {
256 behavior: 'ask',
257 message: 'Command appears to be an incomplete fragment (starts with tab)',
258 }
259 }
260
261 if (trimmed.startsWith('-')) {
262 logEvent('tengu_bash_security_check_triggered', {
263 checkId: BASH_SECURITY_CHECK_IDS.INCOMPLETE_COMMANDS,
264 subId: 2,
265 })
266 return {
267 behavior: 'ask',
268 message:
269 'Command appears to be an incomplete fragment (starts with flags)',
270 }
271 }
272
273 if (/^\s*(&&|\|\||;|>>?|<)/.test(originalCommand)) {
274 logEvent('tengu_bash_security_check_triggered', {
275 checkId: BASH_SECURITY_CHECK_IDS.INCOMPLETE_COMMANDS,
276 subId: 3,
277 })
278 return {
279 behavior: 'ask',
280 message:
281 'Command appears to be a continuation line (starts with operator)',
282 }
283 }
284
285 return { behavior: 'passthrough', message: 'Command appears complete' }
286}
287
288/**
289 * Checks if a command is a "safe" heredoc-in-substitution pattern that can

Callers

nothing calls this directly

Calls 1

logEventFunction · 0.85

Tested by

no test coverage detected