Date : 03/02/2026 Status : EN ATTENTE Projet : connectors-api Priorite : HAUTE (bug bloquant sur instances Windows)
Quand shell_type = powershell sur une instance SSH Windows :
ssh.execute() envoie la commande brute via conn.exec() → execute dans CMD (shell SSH par defaut)ForEach-Object, Get-PSDrive, etc. → exit 255tr)shell_type a SSHConfig (ssh.ts:25)export interface SSHConfig {
// ... existant ...
os_type?: 'linux' | 'windows';
shell_type?: 'bash' | 'cmd' | 'powershell' | 'wsl'; // AJOUT
}
ssh.execute() (ssh.ts:~183)Apres let fullCommand = command; et avant this.executeSSH(), ajouter un wrapping deterministe :
// Wrap command for the target shell (deterministic, no AI needed)
fullCommand = this.wrapForShell(fullCommand, config);
Nouvelle methode :
/**
* Wrap command for target shell (deterministic)
* - powershell: wrap with powershell.exe -NoProfile -Command "..."
* - wsl: wrap with wsl.exe -e bash -c "..."
* - cmd/bash: no wrapping needed
*/
wrapForShell(command: string, config: SSHConfig): string {
const shell = config.shell_type || (config.os_type === 'windows' ? 'cmd' : 'bash');
if (shell === 'powershell') {
// Skip if already wrapped
if (/^powershell(\.exe)?\s/i.test(command)) return command;
// Escape double quotes for CMD wrapping
const escaped = command.replace(/"/g, '\\"');
return `powershell.exe -NoProfile -Command "${escaped}"`;
}
if (shell === 'wsl') {
if (/^wsl(\.exe)?\s/i.test(command)) return command;
const escaped = command.replace(/"/g, '\\"');
return `wsl.exe -e bash -c "${escaped}"`;
}
// cmd and bash: no wrapping
return command;
}
Le prompt PowerShell reste correct — on dit a l'IA d'ecrire du PS pur. Mais on renforce :
const shellInstructions: Record<string, string> = {
cmd: 'Use CMD syntax only. No PowerShell cmdlets. No Linux commands (tr, awk, sed, grep). Use findstr, for /f, set.',
powershell: 'Write pure PowerShell cmdlets (Get-Volume, Get-Process, Get-CimInstance, ForEach-Object, etc.). The command will be auto-wrapped in powershell.exe. Do NOT prefix with powershell.exe. Do NOT use CMD commands (findstr, for /f). Do NOT use Linux commands (tr, awk, sed, grep).',
wsl: 'Use bash/Linux syntax. The command runs inside WSL.',
bash: 'Use bash syntax.'
};
Et la regle "never repeat" :
- NEVER repeat a command that failed. NEVER reuse a tool/command that caused an error (e.g. if 'tr' failed, do NOT use 'tr' again). Find a COMPLETELY different approach using only ${shell} native commands.
| Fichier | Modification |
|---|---|
src/services/ssh.ts |
Ajouter shell_type a SSHConfig, methode wrapForShell(), appel dans execute() |
src/services/ai.ts |
Renforcer shellInstructions + regle "never repeat" |
powershell -Command "..." sont detectees et pas re-wrappeespowershell -Command continueront de fonctionnerssh.execute() → beneficie automatiquement du fixGet-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddresspowershell.exe -NoProfile -Command "Get-NetIPAddress ..." → OK