Phillnet-2 / Tools /utils /shell-utils.ts
ayjays132's picture
Upload 478 files
101858b verified
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 '';
}