Skip to content

feat(yarn): add yarn command support with smart delegation - #867

Open
jzambrano12 wants to merge 3 commits into
rtk-ai:developfrom
jzambrano12:feat/yarn_commands
Open

jzambrano12 wants to merge 3 commits into
rtk-ai:developfrom
jzambrano12:feat/yarn_commands

Conversation

@jzambrano12

Copy link
Copy Markdown

Summary

  • Add yarn_cmd.rs module following the npm_cmd.rs flat-args pattern with run injection logic and YARN_SUBCOMMANDS list (35 known subcommands)
  • Smart routing: auto-detect known tools (vitest, tsc, eslint, biome, next, prettier, playwright) and delegate to existing specialized RTK filters for maximum savings (up to 99%)
  • Generic filter strips Yarn Classic v1 boilerplate (yarn run vX.Y.Z, $ cmd, Done in Xs) and Berry v2+ info lines (YN0000:)
  • Specialized install filter strips progress phases ([1/4]...), info/warning lines (75% reduction)
  • Register Yarn variant in Commands enum, routing, and operational command list in main.rs
  • Add discover/rewrite rules: yarn pattern + rule with per-subcommand savings estimates
  • Add yarn\s+ prefix to 7 existing tool patterns (tsc, lint, prettier, next, vitest, playwright, prisma) so yarn tsc, yarn vitest, etc. are recognized by discover

Motivation

rtk discover on a real project (615 sessions, 30 days) shows 126+ unhandled yarn commands:

yarn build          58 uses
yarn lint           19 uses
yarn check          17 uses
yarn vitest         14 uses
yarn tsc             9 uses
yarn validate-translations  9 uses

Token Savings

Command Strategy Expected Savings
yarn vitest Delegate to vitest_cmd 99%
yarn build Delegate to next_cmd or generic filter 85%
yarn lint Delegate to lint_cmd 84%
yarn tsc Delegate to tsc_cmd 83%
yarn install Specialized install filter 75%
yarn check Generic filter 65%
Custom scripts Generic boilerplate strip 10-40%

Test Plan

  • 35 yarn-specific tests passing (cargo test yarn → 35 passed)
  • Full suite: 1149 tests passing, 0 clippy errors, clean fmt
  • Unit tests: filter output, edge cases (ANSI, unicode, errors, Berry format, malformed input)
  • Token savings assertions (≥55% for install, ≥10% for generic)
  • Subcommand routing: all 35 YARN_SUBCOMMANDS verified, discover commands verified
  • Registry tests: rewrite/classify for yarn build, install, lint, tsc, vitest, check, add, compound, redirect
  • Smoke tests: help, --help, --version (conditional), --skip-env
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test passes

Files Changed

File Action Lines
src/yarn_cmd.rs NEW +479 (module + 35 tests)
src/main.rs EDIT +13 (mod, enum, routing)
src/discover/rules.rs EDIT +41 (patterns, rules, prefixes)
src/discover/registry.rs EDIT +125 (12 rewrite/classify tests)
scripts/test-all.sh EDIT +12 (smoke tests)
CHANGELOG.md EDIT +5 (feature entries)
README.md EDIT +1 (command table)

@CLAassistant

CLAassistant commented Mar 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aeppling

Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

…ized filters

Add yarn_cmd.rs module following npm_cmd flat-args pattern with run injection
logic and YARN_SUBCOMMANDS list. Smart routing delegates vitest, tsc, eslint,
biome, next, prettier, and playwright to existing specialized filters for
maximum token savings. Generic filter strips Classic v1 and Berry boilerplate.
Includes install-specific filter and discover rules with yarn prefixes on
7 existing tool patterns.
25 new tests: unit tests for edge cases (errors, ANSI, unicode, Berry
format, malformed input), registry rewrite/classify tests for yarn
commands and tool delegation, token savings assertions, and smoke
tests in test-all.sh. Total yarn coverage: 35 tests.
@jzambrano12

Copy link
Copy Markdown
Author

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

Done!

@pszymkowiak

Copy link
Copy Markdown
Collaborator

@jzambrano12 — bench-tested this PR on a real Yarn 4 / Berry project
(babel/babel, 1487 packages, 148 MB). The architecture works well:
Berry YN0000: parsing kicks in, smart routing for tsc shows real
savings, exit codes preserved.

yarn lint           raw=1793B  rtk-#867=1790B  (~0%, exit 2 preserved)
yarn tsc            raw=18436B rtk-#867=11351B (38.4%, group-by-file + top codes)
yarn workspaces fe  raw=1675B  rtk-#867=1674B  (~0%, exit 0 preserved)

One blocking issue before merge: the install filter is too
aggressive.

Reproduced with yarn install on babel (exit code 1 — workspace build
failure):

raw output (7389 B, head):
  ➤ YN0000: · Yarn 4.14.1
  ➤ YN0060: │ @babel/core is listed by your project with version 8.0.0-rc.5 (p5fada6), which doesn't satisfy what @babel/eslint-parser ...
  ➤ YN0060: │ @babel/core is listed by your project with version 8.0.0-rc.6 (p07b993), ...
  [40+ YN0060 peer-dep warnings]
  ➤ YN0086: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements for details.
  ➤ YN0007: │ babel@workspace:. must be built because it never has been before or the last one failed
  ➤ YN0009: │ babel@workspace:. couldn't be built successfully (exit code 1, ...)
  ➤ YN0000: · Failed with errors in 31s 918ms

rtk-#867 output (2 B): `ok`

The filter collapses to literal "ok" even though the install
failed with YN0009 (workspace build failure) plus 40+ peer-dep
warnings. Exit code 1 is correctly preserved, but the diagnostic
context is gone — an agent or developer seeing ok + exit 1 has no
way to know what broke without re-running raw yarn install.

Suggested fix: keep the "ok" short-circuit only when the install
truly succeeds (no YN0009, no YN0086, exit 0). On failure or with
peer-dep warnings, emit the offending YN-coded lines (typically <2KB
even for large projects).

Once that lands, this looks ready to merge. #317 will be closed as
superseded by this PR.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants