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

Function reconstructCommand

source code/utils/bash/commands.ts:1197–1341  ·  view source on GitHub ↗
(kept: ParseEntry[], originalCmd: string)

Source from the content-addressed store, hash-verified

1195}
1196
1197function reconstructCommand(kept: ParseEntry[], originalCmd: string): string {
1198 if (!kept.length) return originalCmd
1199
1200 let result = ''
1201 let cmdSubDepth = 0
1202 let inProcessSub = false
1203
1204 for (let i = 0; i < kept.length; i++) {
1205 const part = kept[i]
1206 const prev = kept[i - 1]
1207 const next = kept[i + 1]
1208
1209 // Handle strings
1210 if (typeof part === 'string') {
1211 // For strings containing command separators (|&;), use double quotes to make them unambiguous
1212 // For other strings (spaces, etc), use shell-quote's quote() which handles escaping correctly
1213 const hasCommandSeparator = /[|&;]/.test(part)
1214 const str = hasCommandSeparator
1215 ? `"${part}"`
1216 : needsQuoting(part)
1217 ? quote([part])
1218 : part
1219
1220 // Check if this string ends with $ and next is (
1221 const endsWithDollar = str.endsWith('$')
1222 const nextIsParen =
1223 next && typeof next === 'object' && 'op' in next && next.op === '('
1224
1225 // Special spacing rules
1226 const noSpace =
1227 result.endsWith('(') || // After opening paren
1228 prev === '$' || // After standalone $
1229 (typeof prev === 'object' && prev && 'op' in prev && prev.op === ')') // After closing )
1230
1231 // Special case: add space after <(
1232 if (result.endsWith('<(')) {
1233 result += ' ' + str
1234 } else {
1235 result = addToken(result, str, noSpace)
1236 }
1237
1238 // If string ends with $ and next is (, don't add space after
1239 if (endsWithDollar && nextIsParen) {
1240 // Mark that we should not add space before next (
1241 }
1242 continue
1243 }
1244
1245 // Handle operators
1246 if (typeof part !== 'object' || !part || !('op' in part)) continue
1247 const op = part.op as string
1248
1249 // Handle glob patterns
1250 if (op === 'glob' && 'pattern' in part) {
1251 result = addToken(result, part.pattern as string)
1252 continue
1253 }
1254

Callers 1

Calls 5

needsQuotingFunction · 0.85
quoteFunction · 0.85
addTokenFunction · 0.85
isOperatorFunction · 0.70

Tested by

no test coverage detected