feat(terminal): find, xargs and rmdir as GNU runs them; wc widths and grep -l from the real tools - #418
Conversation
… grep -l from the real tools
find did not exist; it now walks the tree with -name/-iname/-path/-regex,
-type (lists too), -size, -empty, -maxdepth/-mindepth, !, -a, -o and
parentheses, -print, -exec with ; and +, and -delete (bottom-up, on the
tree as it is now). Outputs, errors and exit codes come from findutils
4.9.0, coreutils 9.4 and grep 3.11 on Ubuntu 24.04 (WSL 2), captured on
2 October 2026 in a copy of the simulator's home generated from
createInitialState. Folder order follows NTFS (Git Bash): ext4 order
changes from one machine to another, and the reference says to add | sort.
- xargs: -n, -L, -I/-i, -t, -r, long forms, quotes, exit 123/127; shell
builtins (cd, export...) are not programs for find -exec or xargs, and
what those commands run cannot change the learner's directory.
- rmdir: empty folders only, -p, -v, --ignore-fail-on-non-empty, GNU's
messages. In PowerShell, rmdir and rd are Remove-Item.
- wc: GNU wc.c widths (one count of one file unpadded, total size digits,
7 for a pipe or a folder), a total line, -m, -L. Two old tests and the
wc lesson expected the wrong width; corrected from captures in Git Bash
and Ubuntu alike.
- grep on files: -v, -c, -l, -L, and exit status 0/1/2.
- bash backslash removal in the Linux/macOS terminal (`\;`, `\(`, `\"`
inside double quotes); Windows paths keep their backslashes.
- Windows: find is find.exe ("File not found - *.txt", or "FIND: Parameter
format not correct", exit 2), with a pointer to Get-ChildItem -Recurse.
- Reference page: xargs and rmdir, new find examples and pitfalls
(79 -> 81 commands).
terminal-fidelity-auditor compared about 480 commands; its findings on
this code are fixed and tested, the others recorded in docs/plan.md
(no globbing at all yet, $?, printf, more grep options). code-reviewer's
two important findings (a malformed class threw, -exec cd changed the
cwd) are fixed and tested.
Phase 5d, lot 1, PR 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 1 day and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Guide du réviseurCette PR ajoute Diagramme de séquence pour find avec exec et delete tenant compte de l’étatsequenceDiagram
participant User
participant Terminal
participant Find as runFind
participant Runner as commandRunner
participant FS as FileSystem
User->>Terminal: find . -name "*.md" -exec wc -l {} +
Terminal->>Find: runFind(args, deps)
Find->>FS: node(path)
FS-->>Find: matching entries
Find->>Runner: run(wc -l paths)
Runner->>FS: read files
FS-->>Runner: counts
Runner-->>Find: output and status
Find-->>Terminal: lines and status
Terminal-->>User: GNU-like results
User->>Terminal: find . -type d -empty -delete
Terminal->>Find: runFind(args, deps)
Find->>FS: node(path) bottom-up
FS-->>Find: current directory state
Find->>Runner: run(rm -r path)
Runner->>FS: remove empty entry
FS-->>Runner: updated state
Find-->>Terminal: deletion results
Diagramme de flux pour le comportement spécifique à la plateforme de find et rmdirflowchart TD
Start[Command entered] --> Platform{Terminal environment}
Platform -->|Linux or macOS| Unix[Unix command implementation]
Unix --> Find[find with tests actions and depth]
Unix --> Xargs[xargs with batching and quoting]
Unix --> Rmdir[rmdir empty-directory removal]
Platform -->|Windows| Windows[PowerShell and find.exe handling]
Windows --> FindExe[find.exe error and Get-ChildItem guidance]
Windows --> RemoveItem[rmdir and rd aliases to Remove-Item]
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 GuideThis PR adds Unix Sequence diagram for find with stateful exec and deletesequenceDiagram
participant User
participant Terminal
participant Find as runFind
participant Runner as commandRunner
participant FS as FileSystem
User->>Terminal: find . -name "*.md" -exec wc -l {} +
Terminal->>Find: runFind(args, deps)
Find->>FS: node(path)
FS-->>Find: matching entries
Find->>Runner: run(wc -l paths)
Runner->>FS: read files
FS-->>Runner: counts
Runner-->>Find: output and status
Find-->>Terminal: lines and status
Terminal-->>User: GNU-like results
User->>Terminal: find . -type d -empty -delete
Terminal->>Find: runFind(args, deps)
Find->>FS: node(path) bottom-up
FS-->>Find: current directory state
Find->>Runner: run(rm -r path)
Runner->>FS: remove empty entry
FS-->>Runner: updated state
Find-->>Terminal: deletion results
Flow diagram for platform-specific find and rmdir behaviorflowchart TD
Start[Command entered] --> Platform{Terminal environment}
Platform -->|Linux or macOS| Unix[Unix command implementation]
Unix --> Find[find with tests actions and depth]
Unix --> Xargs[xargs with batching and quoting]
Unix --> Rmdir[rmdir empty-directory removal]
Platform -->|Windows| Windows[PowerShell and find.exe handling]
Windows --> FindExe[find.exe error and Get-ChildItem guidance]
Windows --> RemoveItem[rmdir and rd aliases to Remove-Item]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
This is Phase 5d, lot 1, second PR.
finddid not exist in the simulator; it now works, along withxargsandrmdir. Writing it brought out older defects inwc,grepand backslash handling, which this PR fixes from real captures.The reference shell is Ubuntu 24.04 under WSL 2: findutils 4.9.0, coreutils 9.4, grep 3.11,
LC_ALL=en_US.UTF-8. Captures were run on 2 October 2026 in a copy of the simulator's home. That copy is a fixture generated fromcreateInitialState, so file sizes match exactly.find(src/app/data/commands/find.ts, new)-name,-iname,-path,-regex(Emacs syntax),-type(comma lists too),-size(rounded up to the unit, 512-byte blocks by default),-empty,-maxdepth/-mindepth, with!/-not,-a,-oand parentheses.-print,-exec … \;and-exec … {} +, and-delete.-deleteworks bottom-up and tests each folder as it is at that moment, so-type d -empty -deletealso removes the parents...-mtime,-newer,-perm…) print a note, and a real error later on the line takes precedence over that note.| sort.xargs,rmdir,wc,grepxargs:-n,-L,-I/-i,-t(quoted trace),-rand the long forms;Shell builtins (
cd,export…) are not programs forxargsorfind -exec. What those programs run cannot change the learner's directory.rmdir(new): removes empty folders only, with-p,-v,--ignore-fail-on-non-emptyand GNU's messages. In PowerShell,rmdirandrdareRemove-Item.wcfollowswc.c's width rules: one count of one file is unpadded; otherwise the width is the number of digits of the total size, and at least 7 for a pipe or a folder. It also gets atotalline,-mand-L.wclesson expected the wrong width. All three are corrected from captures that agree in Git Bash (8.32) and in Ubuntu (9.4).curriculum.tsedit is that single string;curriculum-validatorsaid GO.grepon files:-v,-c,-land-L, and exit status 0/1/2. With-L, the status says whether a line matched, as in grep 3.11.Shell layer and Windows
\;,\(,\*, and\"inside double quotes). Windows paths keep their backslashes.findon Windows answers asfind.exedoes:File not found - *.txtfor-name,FIND: Parameter format not correctotherwise, exit 2. It then points toGet-ChildItem -Recurse. The captures were made on a French Windows, which prints « Fichier introuvable - … » and « FIND : format incorrect de paramètre ».Reference and public pages
xargsandrmdir, plusfindexamples and pitfalls: quotes around the pattern, macOS needing a starting folder,find.exein PowerShell, and the order of results. The reference goes from 79 to 81 commands (landingContent.tsand theindex.htmlFAQ).Checks
terminal-fidelity-auditorcompared about 480 commands; it found no THEORY-WRONG. Its findings on this code are fixed and tested. Findings outside this PR are recorded indocs/plan.md:$?;printfandecho -e;grepoptions;lsgiven several folders.feature-dev:code-reviewerreported two Important findings, both fixed and tested:find -name '[z-a]'threw an exception; it now matches nothing, as in GNU;find -exec cd {} \;changed the learner's directory.It also raised
-type f,dand a note that hid a real error; both are fixed.Local gates:
tscclean, lint clean, vitest 3055 passed / 20 skipped, build OK.Ratchets unchanged: theory gaps 90, bash shown on Windows 32.
Incident during the captures (local, recovered)
An inline
wsl … bash -c "…"command was re-split bywsl.exe. The fixture then ran in the real WSL home and overwrote.bashrc/.profile.Nothing was deleted:
~/.tl-incident-2026-10-02/;/etc/skel.Captures now run only as script files, and the fixture refuses to run outside a temp dir. This touched no repo file.
🤖 Generated with Claude Code
Résumé par Sourcery
Implémentation de la recherche de fichiers et du chaînage de commandes compatibles avec GNU, tout en corrigeant les outils de traitement de texte associés, l’échappement des commandes shell et le comportement multiplateforme du terminal.
Nouvelles fonctionnalités :
findcompatible avec GNU, avec tests de fichiers, opérateurs d’expression, actions d’exécution, suppression et comportement de diagnostic.xargset de la prise en charge dermdir, y compris les options Unix pertinentes ainsi que les alias et comportements Windows.find,xargsetrmdir.Corrections de bugs :
wc, des totaux, du comptage des caractères et du nombre maximal de caractères par ligne sur le comportement de GNU.grepappliqué aux fichiers, ainsi que la correction des codes de sortie.find -execetxargs, des commandes intégrées au shell susceptibles de modifier l’état du shell de l’apprenant.Améliorations :
grep, les erreurs et les comportements spécifiques aux plateformes.Documentation :
Tests :
find,xargs,rmdir,wcetgrepcompatibles avec GNU, l’échappement du shell, les diagnostics et le comportement sous Windows.Tâches annexes :
Original summary in English
Summary by Sourcery
Implement GNU-compatible file searching and command chaining while correcting related text-tool, shell-escaping, and cross-platform terminal behavior.
New Features:
findsupport with file tests, expression operators, execution actions, deletion, and diagnostic behavior.xargsargument processing andrmdirsupport, including relevant Unix options and Windows aliases/behavior.find,xargs, andrmdirexamples and documentation.Bug Fixes:
wcoutput widths, totals, character and maximum-line-length counts with GNU behavior.grepinversion, counting, filename listing, and correct exit statuses.find -execandxargsfrom invoking shell builtins that could mutate the learner's shell state.Enhancements:
Documentation:
Tests:
find,xargs,rmdir,wc,grep, shell escaping, diagnostics, and Windows behavior.Chores: