fix(windows): ConPTY + kernel32 metrics + agent loop cap (v0.7.6) #14

Merged
Muyue merged 1 commits from release/v0.7.6 into develop 2026-04-27 12:06:17 +00:00
Owner

Trois bugs Windows + une amélioration agent

1. Dashboard CPU/RAM/Réseau tous à 0

handleSystemMetrics lisait exclusivement /proc/* — ces fichiers n'existent pas sur Windows, donc tous les compteurs restaient à zéro.

Fix : split en metrics_unix.go (!windows, code existant) et metrics_windows.go :

  • CPU : kernel32!GetSystemTimes — ratio dIdle/dTotal entre deux samples FILETIME
  • RAM : kernel32!GlobalMemoryStatusEx — TotalPhys / AvailPhys
  • Network : zéro pour l'instant (MIB_IF_ROW2 trop version-sensitive pour parser à la main proprement, TODO)

Appels directs au kernel via golang.org/x/sys/windows, pas de spawn PowerShell, ~50 µs par appel.

2. Terminal écran noir sur Windows

creack/pty/v2 retourne "operating system not supported" sur Windows. Le fallback pipes (v0.7.1) ne porte pas de signaux TTY, donc cmd/pwsh/wsl détectent l'absence de TTY et passent silencieux ou attendent.

Fix : implémentation ConPTY native via kernel32!CreatePseudoConsole (internal/api/terminal_conpty_windows.go) :

  • CreatePseudoConsole + 2 pipes anonymes
  • STARTUPINFOEX + PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE via windows.NewProcThreadAttributeList
  • CreateProcessW lance le shell avec le PC attaché → ANSI / cursor / line discipline complets
  • ResizePseudoConsole câblé sur les events xterm.js
  • canUseConPTY() probe une fois au démarrage (Win 10 1809+ requis), cached
  • Fallback pipeSession conservé pour les hosts trop vieux ou si la création échoue

Restructure : terminal_session.go (interface + structs uniquement), terminal_session_unix.go (creack/pty), terminal_session_windows.go (ConPTY puis pipe), terminal_conpty_windows.go (impl).

3. Agent s'arrête après 15 outils

l'IA semble s'arrêter après 15 exécution d'outils, je ne veux pas cela, elle peut executer 100, voire 1000

Fix : MaxToolIterations 15 → 500 dans chat_engine.go. Cap conservé pour éviter les boucles infinies en cas de bug modèle, mais 500 itérations couvre largement les cas réels (refactor multi-fichiers, debug exploratoire). Doc inline ajoutée.

Versioning

  • v0.7.5 → v0.7.6
  • CHANGELOG.md : entrée v0.7.6 couvre les trois fixes

Test plan

  • go vet ./... (Linux + cross-compile Windows)
  • manuel Windows : Dashboard montre CPU% et RAM% non-nuls qui bougent
  • manuel Windows : double-clic raccourci → tab terminal → choisir "PowerShell" → prompt PS s'affiche, on peut taper et voir la sortie
  • manuel Windows : tab terminal → choisir "WSL: Debian" → bash s'affiche avec prompt, vim fonctionne (test TTY complet)
  • manuel Studio : demander une tâche complexe nécessitant 50+ outils → l'agent ne s'arrête plus à 15
  • régression Linux/macOS : terminal local + WSL + SSH continuent comme avant
## Trois bugs Windows + une amélioration agent ### 1. Dashboard CPU/RAM/Réseau tous à 0 `handleSystemMetrics` lisait exclusivement `/proc/*` — ces fichiers n'existent pas sur Windows, donc tous les compteurs restaient à zéro. **Fix** : split en `metrics_unix.go` (`!windows`, code existant) et `metrics_windows.go` : - CPU : `kernel32!GetSystemTimes` — ratio dIdle/dTotal entre deux samples FILETIME - RAM : `kernel32!GlobalMemoryStatusEx` — TotalPhys / AvailPhys - Network : zéro pour l'instant (MIB_IF_ROW2 trop version-sensitive pour parser à la main proprement, TODO) Appels directs au kernel via `golang.org/x/sys/windows`, pas de spawn PowerShell, ~50 µs par appel. ### 2. Terminal écran noir sur Windows `creack/pty/v2` retourne *"operating system not supported"* sur Windows. Le fallback pipes (v0.7.1) ne porte pas de signaux TTY, donc cmd/pwsh/wsl détectent l'absence de TTY et passent silencieux ou attendent. **Fix** : implémentation **ConPTY native** via `kernel32!CreatePseudoConsole` (`internal/api/terminal_conpty_windows.go`) : - `CreatePseudoConsole` + 2 pipes anonymes - `STARTUPINFOEX` + `PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE` via `windows.NewProcThreadAttributeList` - `CreateProcessW` lance le shell avec le PC attaché → ANSI / cursor / line discipline complets - `ResizePseudoConsole` câblé sur les events xterm.js - `canUseConPTY()` probe une fois au démarrage (Win 10 1809+ requis), cached - Fallback `pipeSession` conservé pour les hosts trop vieux ou si la création échoue **Restructure** : `terminal_session.go` (interface + structs uniquement), `terminal_session_unix.go` (creack/pty), `terminal_session_windows.go` (ConPTY puis pipe), `terminal_conpty_windows.go` (impl). ### 3. Agent s'arrête après 15 outils > *l'IA semble s'arrêter après 15 exécution d'outils, je ne veux pas cela, elle peut executer 100, voire 1000* **Fix** : `MaxToolIterations` 15 → 500 dans `chat_engine.go`. Cap conservé pour éviter les boucles infinies en cas de bug modèle, mais 500 itérations couvre largement les cas réels (refactor multi-fichiers, debug exploratoire). Doc inline ajoutée. ### Versioning - v0.7.5 → v0.7.6 - CHANGELOG.md : entrée v0.7.6 couvre les trois fixes ### Test plan - [ ] go vet ./... (Linux + cross-compile Windows) - [ ] manuel Windows : Dashboard montre CPU% et RAM% non-nuls qui bougent - [ ] manuel Windows : double-clic raccourci → tab terminal → choisir "PowerShell" → prompt PS s'affiche, on peut taper et voir la sortie - [ ] manuel Windows : tab terminal → choisir "WSL: Debian" → bash s'affiche avec prompt, vim fonctionne (test TTY complet) - [ ] manuel Studio : demander une tâche complexe nécessitant 50+ outils → l'agent ne s'arrête plus à 15 - [ ] régression Linux/macOS : terminal local + WSL + SSH continuent comme avant
Muyue added 1 commit 2026-04-27 12:05:30 +00:00
fix(windows): native ConPTY + kernel32 metrics + agent loop cap (v0.7.6)
All checks were successful
PR Check / check (pull_request) Successful in 1m0s
d557b8e74c
Three issues reported on Windows + one user-requested limit bump:

1. Dashboard CPU/RAM/Network all at 0
   handleSystemMetrics read /proc/* exclusively. Replaced with a
   platform-split:
   - metrics_unix.go (!windows): existing /proc reading code.
   - metrics_windows.go: kernel32!GetSystemTimes for CPU
     (delta of idle vs kernel+user FILETIMEs) and
     kernel32!GlobalMemoryStatusEx for memory. Network left at zero
     for now — MIB_IF_ROW2 is too version-sensitive to parse by hand.
   handlers_info.go::handleSystemMetrics reduced to one delegating
   call.

2. Terminal black screen on Windows
   creack/pty/v2 returns "unsupported" on Windows; the v0.7.1 pipe
   fallback works but pipes don't carry TTY signals, so cmd/pwsh/wsl
   go silent. Implemented native ConPTY:
   - terminal_conpty_windows.go: CreatePseudoConsole + STARTUPINFOEX
     + PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE wiring via
     windows.NewProcThreadAttributeList. CreateProcessW launches
     child with the PC attached, full ANSI / line discipline /
     resize.
   - canUseConPTY() probes once at startup (Win10 1809+ check).
   - Restructure: terminal_session.go now holds just the interface
     + ptySession + pipeSession structs. terminal_session_unix.go
     wires creack/pty. terminal_session_windows.go tries ConPTY
     first, falls back to pipeSession.

3. Agent stops after 15 tool calls
   MaxToolIterations bumped 15 → 500. Doc comment explains why the
   cap exists at all (infinite-loop safety) and that 500 is well
   above realistic usage.

- internal/version/version.go: 0.7.5 → 0.7.6
- CHANGELOG.md: v0.7.6 entry covers the three fixes
Muyue merged commit 9d1d717999 into develop 2026-04-27 12:06:17 +00:00
Muyue deleted branch release/v0.7.6 2026-04-27 12:06:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Muyue/MuyueWorkspace#14