Skip to content

feat(terminal): sort, uniq and cut as GNU coreutils 9.4 runs them, with their PowerShell counterparts - #417

Merged
thierryvm merged 1 commit into
mainfrom
feat/sort-uniq-cut
Oct 2, 2026
Merged

thierryvm merged 1 commit into
mainfrom
feat/sort-uniq-cut

Conversation

@thierryvm

@thierryvm thierryvm commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Phase 5d, lot 1, first PR: sort, uniq and cut work on files and pipes, faithful to GNU coreutils 9.4, with their PowerShell counterparts. Before, sort file.txt answered "commande introuvable".

Reference shells:

  • Linux: Ubuntu 24.04 under WSL 2, coreutils 9.4, LC_ALL=en_US.UTF-8. The en_US, fr_FR and fr_BE locales were generated for this; their sort order is identical.
  • Windows: PowerShell 7.6.6, en-US culture.

All captures were made in a sandbox holding the same files, more than 150 commands in all. Git Bash's sort is not the reference here, because its Cygwin collation differs.

Linux / macOS (src/app/data/commands/textTools.ts)

  • sort uses glibc collation. Punctuation, symbols and case only break ties. A collator matched glibc line for line on 69 tricky lines.
    • Options: -b -d -f -h -n -r -u -s -c -o, and -k with GNU's begfield/limfield rules and per-key options.
    • Ties: the last-resort comparison is reversed only by a global -r.
    • -t, plus GNU's exact error messages and exit codes.
  • uniq: -c -d -D -u, and -i with ASCII-only folding (é and É stay different). It also takes an output file.
  • cut: -f -d -s, --complement and --output-delimiter. -c/-b count bytes, as in GNU 9.4: "Tâches" cut at 5 gives "Tâch". Missing files are reported one by one.
  • Real options that are not simulated (-g -M -V -z, uniq -f…) and --help print a note, never a wrong result.
  • With no file and no pipe, a note explains what to give the command, instead of the real tool's wait for keyboard input.
  • macOS shows the GNU behaviour. There is no Mac to check the BSD tools on, and the code says so.

Windows

  • Sort-Object on text (and its alias sort): case is ignored and ties keep their order, which is true for PowerShell up to 16 lines. It supports -Descending, -Unique, -CaseSensitive, -Top and -Bottom, with parameters bound by the shared PowerShell binder (sort -u).
  • New cmdlets: Get-Unique (gu), Select-Object -Unique, and Group-Object (group, -NoElement) with PowerShell's table.
  • Tables:
    • a table keeps its blank-line frame through Sort-Object/Select-Object;
    • Name sorts Get-Process by ProcessName;
    • Sort-Object { … } script blocks print a "not simulated" note.

Reference and public pages

  • sort, uniq and cut are added to the reference page with Windows variants, executable examples, common errors and official docs (man7.org, Microsoft Learn; all 7 URLs return 200). The reference goes from 76 to 79 commands, in landingContent.ts and the index.html FAQ.
  • Landing roadmap:
    • a new in-progress group, "Des bases au niveau intermédiaire";
    • removed "Parcours avancés (Docker, scripting…)", which contradicted the 1 October decision.

Checks

  • Tests: 15 new engine tests. Every expected value is a real-shell output.
  • terminal-fidelity-auditor: compared 301 commands with the real shells.
    • Its findings F1–F4, F6, F7 and the script-block note are fixed and tested.
    • F5 and F8, both rare, are recorded in the plan, along with a global debt it surfaced: --help is wrong for every other command.
  • feature-dev:code-reviewer: found that sort --constructor reached Object.prototype in getopt. This is fixed and tested.
  • Bug caught by an existing test: the garbage-input contract (curriculumEnvAwareness) caught a prototype lookup on typed command names. INPUT_CMDLETS is now a Map.
  • Ratchets unchanged: theory gaps 90, bash shown on Windows 32.
  • Local gates: tsc clean, lint clean, vitest 3043 passed / 20 skipped, build OK.

Known debt, written down in docs/plan.md:

  • Get-Content a, b and ForEach-Object are not simulated.
  • On Windows, an unknown command keeps the teaching message instead of PowerShell's.
  • --help for the other commands.

🤖 Generated with Claude Code

Résumé par Sourcery

Implémentation d’un tri de texte multiplateforme fidèle, de la déduplication et de l’extraction de champs, avec une documentation de référence et une validation correspondantes.

Nouvelles fonctionnalités :

  • Ajout de la prise en charge compatible avec GNU coreutils de sort, uniq et cut pour les fichiers et les pipelines sous Linux et macOS.
  • Ajout des équivalents PowerShell pour le traitement de texte et le regroupement, notamment Sort-Object, Get-Unique, Select-Object -Unique et Group-Object.
  • Extension de la référence des commandes avec les trois commandes, les variantes par plateforme, des exemples, les erreurs et la documentation officielle.

Corrections de bugs :

  • Correction de la gestion des options de commande, des rapports d’erreur, de la structure des tableaux et de la recherche de commandes sécurisée contre les prototypes, identifiées lors des audits de fidélité et des tests.

Améliorations :

  • Alignement du tri de texte, de l’unicité, de la sélection de champs, de la gestion des octets, du comportement de PowerShell et de l’affichage des tableaux sur le comportement observé de GNU coreutils 9.4 et de PowerShell 7.6.
  • Documentation des limitations connues du simulateur et mise à jour de la feuille de route d’apprentissage de niveau intermédiaire.

Documentation :

  • Mise à jour du journal des modifications, de la présentation du projet, de la feuille de route, du plan, des totaux de la page d’accueil et de la FAQ afin de refléter les trois commandes désormais prises en charge.

Tests :

  • Ajout d’une couverture complète du moteur pour les outils texte GNU, leurs équivalents PowerShell, les cas d’erreur, les corrections issues des audits et le comportement sous macOS.
Original summary in English

Summary by Sourcery

Implement faithful cross-platform text sorting, deduplication, and field extraction with matching reference documentation and validation.

New Features:

  • Add GNU coreutils-compatible sort, uniq, and cut support for files and pipelines on Linux and macOS.
  • Add PowerShell text and grouping counterparts including Sort-Object, Get-Unique, Select-Object -Unique, and Group-Object.
  • Expand the command reference with the three commands, platform variants, examples, errors, and official documentation.

Bug Fixes:

  • Correct command option handling, error reporting, table framing, and prototype-safe command lookup identified through fidelity audits and tests.

Enhancements:

  • Align text sorting, uniqueness, field selection, byte handling, PowerShell behavior, and table output with the captured GNU coreutils 9.4 and PowerShell 7.6 behavior.
  • Document known simulator limitations and update the intermediate-level learning roadmap.

Documentation:

  • Update the changelog, project story, roadmap, plan, landing page totals, and FAQ to reflect the three newly supported commands.

Tests:

  • Add comprehensive engine coverage for GNU text tools, PowerShell counterparts, error cases, audit fixes, and macOS behavior.

…th their PowerShell counterparts

sort, uniq and cut now read files as well as pipes. Before, `sort file`
answered "command not found". Expected outputs come from Ubuntu 24.04 under
WSL 2 (coreutils 9.4, en_US.UTF-8, whose order matches fr_FR) and PowerShell
7.6.6 (en-US), captured on 2 October 2026 in a sandbox with the same files.

- sort: glibc collation (punctuation, symbols and case only break ties,
  matched line for line on 69 tricky lines), -b -d -f -h -n -r -u -s -c -o,
  -k with GNU's begfield/limfield, -t, per-key options, the last-resort
  comparison reversed only by a global -r, GNU's error messages.
- uniq: -c -d -D -u -i (ASCII folding), an output file. cut: -f -d -s,
  --complement, --output-delimiter, and -c/-b counting bytes like GNU 9.4.
- Real options that are not simulated print a note, never a wrong result.
- PowerShell: Sort-Object on text (case ignored, ties kept, -Descending,
  -Unique, -CaseSensitive, -Top, -Bottom), Get-Unique, Select-Object
  -Unique, Group-Object with its table. A table keeps its frame through
  Select-Object; Name sorts Get-Process by ProcessName.
- Reference page: sort, uniq, cut (76 -> 79 commands). The landing roadmap
  tells the path from the basics to an intermediate level.

terminal-fidelity-auditor compared 301 commands with the real shells; its
eight findings are fixed or recorded in the plan. code-reviewer found a
prototype lookup in getopt (`sort --constructor`), fixed and tested.

Phase 5d, lot 1, PR 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
terminal-learning Ready Ready Preview Oct 2, 2026 6:15pm UTC

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sourcery-ai

sourcery-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Guide du réviseur

Implémente sort, uniq et cut basés sur des fichiers et des pipes, avec un comportement conforme à GNU coreutils 9.4 dans les environnements de type Unix, ajoute les comportements PowerShell correspondants pour le tri, l’unicité et le regroupement, ainsi que la prise en charge des tableaux, documente les commandes et les mises à jour de la feuille de route, et verrouille l’implémentation grâce à des tests de régression dérivés de shells réels.

Diagramme de séquence du traitement de texte Unix à partir de fichiers ou de pipes

sequenceDiagram
  participant User
  participant Engine as TerminalEngine
  participant Tool as GNUTextTool
  participant FS as VirtualFilesystem
  participant Output
  User->>Engine: sort/uniq/cut args
  Engine->>Tool: runSort/runUniq/runCut(args, stdin, read)
  Tool->>FS: read file operands
  FS-->>Tool: file contents or error
  Tool->>Tool: textLines and transform input
  alt output file requested
    Tool-->>Engine: writeTo(path, lines)
    Engine->>FS: writeFileAt(path, lines)
  else terminal output
    Tool-->>Engine: lines and status
    Engine-->>Output: print result or GNU error
  end
Loading

Diagramme de séquence du tri et du regroupement PowerShell

sequenceDiagram
  participant User
  participant Engine as TerminalEngine
  participant Cmdlet as PowerShellCmdlet
  participant Table as PowerShellTable
  User->>Engine: Get-Content | Sort-Object/Get-Unique/Group-Object
  Engine->>Cmdlet: parsePsArgs(args)
  Cmdlet->>Cmdlet: compare or group piped lines
  alt tabular input
    Cmdlet->>Table: preserve frame and sort/select rows
    Table-->>Engine: formatted table
  else text input
    Cmdlet-->>Engine: sorted, unique, or grouped lines
  end
  Engine-->>User: PowerShell-compatible output
Loading

Modifications au niveau des fichiers

Modification Détails Fichiers
Ajout de moteurs de traitement de texte compatibles avec GNU pour les environnements de type Unix.
  • Implémentation de l’entrée provenant de fichiers et de pipes pour sort, uniq et cut, y compris la prise en charge des fichiers de sortie et les indications en cas d’absence d’entrée.
  • Ajout de l’analyse des options au format GNU, du classement, de la sélection de clés/plages, du tri numérique et lisible par l’humain, de l’unicité, de l’extraction de champs/octets, des compléments, des délimiteurs, des vérifications et des statuts d’erreur.
  • Signalement explicite des options non prises en charge sous forme de notes informatives et protection des recherches d’options contre les propriétés de la chaîne de prototypes.
src/app/data/commands/textTools.ts
src/app/data/terminalEngine.ts
Ajout des équivalents PowerShell pour le tri, l’unicité, le regroupement et la gestion des tableaux.
  • Implémentation de la gestion des paramètres Sort-Object/sort, Get-Unique/gu, Group-Object/group et Select-Object -Unique.
  • Simulation de la sensibilité à la casse, du tri textuel stable, de la sélection des éléments uniques/supérieurs/inférieurs, des tableaux de sortie regroupés, des alias de noms de processus, des notes sur les blocs de script et de la préservation du cadre des tableaux.
  • Remplacement du registre des cmdlets d’entrée Windows par une Map afin d’éviter les collisions avec des noms de propriétés de prototype.
src/app/data/commands/textTools.ts
src/app/data/terminalEngine.ts
Extension de la documentation des commandes et des métadonnées publiques du programme pédagogique.
  • Ajout d’entrées au catalogue, de variantes par plateforme, d’exemples, d’erreurs courantes et de liens vers la documentation officielle pour les trois commandes.
  • Mise à jour du nombre total de commandes, des métadonnées de la FAQ, des groupes de la feuille de route, du journal des modifications, de l’histoire et de l’état du plan de livraison.
src/app/data/commandCatalogue.ts
src/app/data/commandExamples.ts
src/app/data/landingContent.ts
index.html
docs/ROADMAP.md
docs/plan.md
CHANGELOG.md
STORY.md
Ajout de tests de régression assurant la fidélité au shell.
  • Ajout de 15 tests du moteur couvrant le comportement Unix/macOS, les cmdlets PowerShell, les fichiers/pipes, le formatage, les erreurs, les options non prises en charge, les régressions de sécurité et les résultats d’audit.
src/test/terminalEngine.test.ts

Conseils et commandes

Interagir avec Sourcery

  • Déclencher une nouvelle revue : commentez @sourcery-ai review sur la pull request.
  • Poursuivre les discussions : répondez directement aux commentaires de revue de Sourcery.
  • Générer une issue GitHub à partir d’un commentaire de revue : demandez à Sourcery de créer une issue à partir d’un commentaire de revue en y répondant. Vous pouvez également répondre à un commentaire de revue avec @sourcery-ai issue pour créer une issue à partir de celui-ci.
  • Générer un titre de pull request : écrivez @sourcery-ai n’importe où dans le titre de la pull request pour générer un titre à tout moment. Vous pouvez également commenter @sourcery-ai title sur la pull request pour générer ou régénérer le titre à tout moment.
  • Générer un résumé de pull request : écrivez @sourcery-ai summary n’importe où dans le corps de la pull request pour générer un résumé de PR à tout moment, exactement à l’endroit souhaité. Vous pouvez également commenter @sourcery-ai summary sur la pull request pour générer ou régénérer le résumé à tout moment.
  • Générer le guide du réviseur : commentez @sourcery-ai guide sur la pull request pour générer ou régénérer le guide du réviseur à tout moment.
  • Résoudre tous les commentaires de Sourcery : commentez @sourcery-ai resolve sur la pull request pour résoudre tous les commentaires de Sourcery. Utile si vous avez déjà traité tous les commentaires et ne souhaitez plus les voir.
  • Ignorer toutes les revues de Sourcery : commentez @sourcery-ai dismiss sur la pull request pour ignorer toutes les revues existantes de Sourcery. Particulièrement utile si vous souhaitez repartir de zéro avec une nouvelle revue — n’oubliez pas de commenter @sourcery-ai review pour déclencher une nouvelle revue !

Personnaliser votre expérience

Accédez à votre tableau de bord pour :

  • Activer ou désactiver les fonctionnalités de revue, telles que le résumé de pull request généré par Sourcery, le guide du réviseur, etc.
  • Modifier la langue de revue.
  • Ajouter, supprimer ou modifier les instructions de revue personnalisées.
  • Ajuster les autres paramètres de revue.

Obtenir de l’aide

Original review guide in English

Reviewer's Guide

Implements file- and pipe-based sort, uniq, and cut with GNU coreutils 9.4 behavior on Unix-like environments, adds corresponding PowerShell sorting/uniqueness/grouping behavior and table support, documents the commands and roadmap updates, and locks the implementation down with real-shell-derived regression tests.

Sequence diagram for Unix text processing from files or pipes

sequenceDiagram
  participant User
  participant Engine as TerminalEngine
  participant Tool as GNUTextTool
  participant FS as VirtualFilesystem
  participant Output
  User->>Engine: sort/uniq/cut args
  Engine->>Tool: runSort/runUniq/runCut(args, stdin, read)
  Tool->>FS: read file operands
  FS-->>Tool: file contents or error
  Tool->>Tool: textLines and transform input
  alt output file requested
    Tool-->>Engine: writeTo(path, lines)
    Engine->>FS: writeFileAt(path, lines)
  else terminal output
    Tool-->>Engine: lines and status
    Engine-->>Output: print result or GNU error
  end
Loading

Sequence diagram for PowerShell sorting and grouping

sequenceDiagram
  participant User
  participant Engine as TerminalEngine
  participant Cmdlet as PowerShellCmdlet
  participant Table as PowerShellTable
  User->>Engine: Get-Content | Sort-Object/Get-Unique/Group-Object
  Engine->>Cmdlet: parsePsArgs(args)
  Cmdlet->>Cmdlet: compare or group piped lines
  alt tabular input
    Cmdlet->>Table: preserve frame and sort/select rows
    Table-->>Engine: formatted table
  else text input
    Cmdlet-->>Engine: sorted, unique, or grouped lines
  end
  Engine-->>User: PowerShell-compatible output
Loading

File-Level Changes

Change Details Files
Added GNU-compatible text-processing engines for Unix-like environments.
  • Implemented file and pipe input for sort, uniq, and cut, including output-file support and no-input guidance.
  • Added GNU-style option parsing, collation, key/range selection, numeric and human-readable sorting, uniqueness, field/byte extraction, complements, delimiters, checks, and error statuses.
  • Explicitly report unsupported options as informational notes and guard option lookups against prototype-chain properties.
src/app/data/commands/textTools.ts
src/app/data/terminalEngine.ts
Added PowerShell counterparts for sorting, uniqueness, grouping, and table handling.
  • Implemented Sort-Object/sort, Get-Unique/gu, Group-Object/group, and Select-Object -Unique parameter handling.
  • Simulated case sensitivity, stable text sorting, unique/top/bottom selection, grouped output tables, process-name aliases, script-block notes, and table frame preservation.
  • Replaced the Windows input-cmdlet registry with a Map to prevent prototype-name collisions.
src/app/data/commands/textTools.ts
src/app/data/terminalEngine.ts
Expanded command documentation and public curriculum metadata.
  • Added catalogue entries, platform variants, examples, common errors, and official documentation links for the three commands.
  • Updated command totals, FAQ metadata, roadmap groups, changelog, story, and delivery-plan status.
src/app/data/commandCatalogue.ts
src/app/data/commandExamples.ts
src/app/data/landingContent.ts
index.html
docs/ROADMAP.md
docs/plan.md
CHANGELOG.md
STORY.md
Added shell-fidelity regression coverage.
  • Added 15 engine tests covering Unix/macOS behavior, PowerShell cmdlets, files/pipes, formatting, errors, unsupported options, security regressions, and audit findings.
src/test/terminalEngine.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@thierryvm
thierryvm merged commit 30fc67d into main Oct 2, 2026
4 checks passed
@thierryvm
thierryvm deleted the feat/sort-uniq-cut branch October 2, 2026 18:17

This branch was successfully deployed

1 active deployment
Preview — d7450522 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant