File size: 1,217 Bytes
101858b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

export function stripShellWrapper(command: string): string {
  // Simple heuristic to strip common wrappers if present
  if (command.startsWith('powershell.exe -NoProfile -Command "')) {
    return command.slice(36, -1);
  }
  if (command.startsWith('bash -c "')) {
    return command.slice(9, -1);
  }
  return command;
}

export function getCommandRoots(command: string): string[] {
  // Extracting the main executable names from a command string
  const cleanCommand = command.trim();
  if (!cleanCommand) return [];
  
  // Basic split to get first tokens of piped/chained commands
  const parts = cleanCommand.split(/[|&;]|\s&&\s|\s\|\|\s/);
  return parts.map(p => p.trim().split(/\s+/)[0]).filter(Boolean);
}

export async function initializeShellParsers(): Promise<void> {
  // Placeholder for parser initialization
}

export function parseCommandDetails(command: string): any {
  return { details: [{ name: command.split(' ')[0] }], hasError: false };
}

export function hasRedirection(command: string): boolean {
  return /[><]/.test(command);
}

export async function* execStreaming(command: string, args: string[], options: any = {}): AsyncGenerator<string> {
  // Mock streaming execution
  yield '';
}