fix(terminal): a real shell layer — lists, pipelines and redirections (THI-353) - #389
Conversation
… (THI-353) The engine only knew `echo > file` and two-stage pipes split on every `|`. `ls fichier 2> erreurs.txt` printed the error anyway, `tee` wrote nothing, and `chmod +x x && ./x`, cited by the lessons, ran as one broken command. - shellSyntax.ts: quote-aware parsing of `;` `&&` `||` `|` and redirections `>` `>>` `2>` `2>&1` `>&2` `&>` `<` (PowerShell `*>`, `2>$null`) - runLine / runPipeline: stdout and stderr routed separately (screen, next command, file, /dev/null), targets opened before the command runs, pipeline stages in a subshell (only files persist), history records the line once - runFilter: wc, grep -v/-c, sort -k/-n/-r, head, tail, uniq -c, tee -a, Tee-Object, Out-File, Set/Add-Content, Out-Null, Measure-Object, Select-Object, Sort-Object, Select-String, findstr, Stop-Process - ls writes one name per line into a pipe or a file, like a real ls (`ls | wc -l` counted 1); `ls -1` added - Get-Item (PowerShell) - KNOWN_DESYNCS ratchet: 3 -> 0 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Sorry @thierryvm, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 2 days and 7 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Guide du réviseurConstruit une véritable couche shell autour du moteur de terminal : un analyseur prenant en charge les guillemets alimente le routage ordonné de stdout/stderr, les pipelines à plusieurs étapes, les listes de commandes conditionnelles, les filtres stdin et les équivalents PowerShell, tout en préservant le chemin d’exécution des commandes simples et en ajoutant une couverture complète des régressions. Diagramme de séquence pour l’exécution des pipelines et des redirectionssequenceDiagram
participant User
participant Engine as processCommand
participant Parser as parseCommandLine
participant Runner as runPipeline
participant Command as runSimple or runFilter
participant FS as Virtual filesystem
participant Screen
User->>Engine: Enter command line
Engine->>Parser: parseCommandLine(line, env)
Parser-->>Engine: Lists, stages, redirects
Engine->>Runner: runPipeline(state, stages, env)
Runner->>FS: Open redirection targets
Runner->>Command: Execute stage with stdin
Command-->>Runner: stdout and stderr lines
Runner->>FS: Write redirected file output
Runner->>Command: Pass stdout to next stage
Runner->>Screen: Route screen output and errors
Runner-->>Engine: Pipeline status and state
Engine-->>User: Display output
Modifications au niveau des fichiers
Conseils et commandesInteragir avec Sourcery
Personnaliser votre expérienceAccédez à votre tableau de bord pour :
Obtenir de l’aide
Original review guide in EnglishReviewer's GuideBuilds a real shell layer around the terminal engine: a quote-aware parser feeds ordered stdout/stderr routing, multi-stage pipelines, conditional command lists, stdin filters, and PowerShell equivalents, while preserving the plain-command path and adding comprehensive regression coverage. Sequence diagram for pipeline and redirection executionsequenceDiagram
participant User
participant Engine as processCommand
participant Parser as parseCommandLine
participant Runner as runPipeline
participant Command as runSimple or runFilter
participant FS as Virtual filesystem
participant Screen
User->>Engine: Enter command line
Engine->>Parser: parseCommandLine(line, env)
Parser-->>Engine: Lists, stages, redirects
Engine->>Runner: runPipeline(state, stages, env)
Runner->>FS: Open redirection targets
Runner->>Command: Execute stage with stdin
Command-->>Runner: stdout and stderr lines
Runner->>FS: Write redirected file output
Runner->>Command: Pass stdout to next stage
Runner->>Screen: Route screen output and errors
Runner-->>Engine: Pipeline status and state
Engine-->>User: Display output
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…, pipeline subshells - A command that does not read stdin runs normally after a pipe (`echo x | mkdir d` created nothing, `echo hi | pwd` printed "hi") - `claude` after a pipe explains that Claude Code is not simulated (info, not a red line); sed / awk / cut / tr / xargs say they are not simulated yet and let the text through - CommandOutput.status: grep, Select-String and findstr exit 1 without a match, so `grep x f || echo repli` works - Every command of a pipeline starts from the caller's cwd and variables; only files are shared (`cd documents | tee out.txt` wrote into documents/) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review follow-ups (c263b50) —
Final checks on c263b50: CI green; browser census on the preview 198/198 desktop (and 198/198 at 390 px on the first commit); lesson theory replay (757 commands) 0 regression; Chrome (local): all three fixes behave like bash. |
…manent replay (THI-353) (#391) - Replay every terminal session shown in a lesson code block through the engine, from the lesson's starting state, in each environment (src/test/lessonTheory.test.ts). Known gaps are a shrink-only ratchet (lessonTheoryGaps.ts, 174 entries), plus a ceiling on lessons that show bash to Windows learners (39). - Fix 13 lesson examples whose output did not match (ls -l, ls -a, grep -n, wc, chmod, chown, apt, stderr, Windows ping) and give the PATH and git init lessons a single block per environment. - ls -l size comes from the content bytes, like wc -c. - $env:X = "..." expands $env:Y inside double quotes (PowerShell). - git init prints C:/Users/user/... on Windows, like Git for Windows. - CHANGELOG and STORY: catch up #389 and #390, add this change. Co-authored-by: Claude Opus 5.5 <[email protected]>
Why
THI-353, step 3 — the last 3 cases of the ratchet. The engine only knew
echo > fileand two-stage pipes split on every|character:ls fichier-inexistant 2> erreurs.txt(the stderr lesson) still printed the error in red and wrote nothing;ls | tee ma-liste.txtnever wrote the file;chmod +x script.sh && ./script.sh, cited by the lessons, ran as one broken command;grep "a|b" fwas cut in two.What
shellSyntax.ts(pure parser): quote-aware;&&|||and redirections>>>2>2>&1>&2&><, PowerShell*>and2>$null. Escaped operators stay literal (find … \;), Windows paths keep their backslashes.runLine/runPipeline: stdout and stderr are routed separately (screen, next command, file,/dev/null/$null), in the order they are written (> f 2>&1differs from2>&1 > f, like bash). Targets are opened before the command runs (a missing directory stops that command).&&/||use the status of the last command of the pipeline. Pipeline stages run in a subshell: only files persist. The history records the line once.isPlainCommand→runSimple(state, line)).wc,grep -v/-c,sort -k/-n/-r,head,tail,uniq -c,tee -a,Tee-Object,Out-File,Set-Content,Add-Content,Out-Null,Measure-Object,Select-Object,Sort-Object,Select-String,findstr,Stop-Process.lsinto a pipe or a file writes one name per line, like a realls— found in the browser check:ls | wc -landGet-ChildItem | Measure-Objectcounted 1.ls -1added.Get-Item(PowerShell): the item, orCannot find path '…' because it does not exist.success, e.g.git log) are standard output: they now travel through pipes (the old pipe dropped them).Ratchet
KNOWN_DESYNCS: 3 → 0. Lesson theory replay (757 commands): 0 regression, 23 more examples now match.Gates
src/test/shellLayer.test.ts(48 tests) written first and seen red onmain(31 failing); engine tests for every new command interminalEngine.test.ts2>leaves no red line and fills the file,Tee-Objectshows and writes,Measure-Objectcounts 3 items,&&/||/;behave like bash, 0 horizontal overflowRefs THI-353
🤖 Generated with Claude Code
Résumé par Sourcery
Implémentation d’une véritable couche d’exécution shell pour les commandes composées, les pipelines et la redirection des flux dans les terminaux Unix et PowerShell.
Nouvelles fonctionnalités :
tee), la redirection du contenu et la gestion des processus.Get-Itemde PowerShell pour les chemins existants et inexistants.Corrections de bugs :
lset les listes de répertoires PowerShell, d’une sortie orientée ligne lorsqu’elles sont utilisées avec des pipelines ou des fichiers.Améliorations :
Tests :
Original summary in English
Résumé par Sourcery
Implémentation d’une couche d’exécution shell prenant en charge la composition réaliste des commandes, le routage des flux, les pipelines et les redirections dans les terminaux Unix et PowerShell.
Nouvelles fonctionnalités :
Get-Itempour les chemins existants et inexistants.Corrections de bugs :
Améliorations :
Tests :
Original summary in English
Summary by Sourcery
Implement a shell execution layer that supports realistic command composition, stream routing, pipelines, and redirections in Unix and PowerShell terminals.
New Features:
Bug Fixes:
Enhancements:
Tests: