Commit Graph

12 Commits

Author SHA1 Message Date
Artiom Tofan 2e194efb3a fix: resolve Windows command wrapper execution (#269)
- add PATHEXT-aware command resolution via which\n- migrate affected command runners to resolved_command\n- add regression coverage for wrapper/fallback behavior
2026-03-12 15:36:19 +01:00
Florian BRUNIAUX 7975624d0a feat: audit phase 3 + tracking validation + rtk learn
## Audit Tracking Phase 3 (Steps 0-6)
- Systematic tracking integration across all command modules
- TimedExecution pattern enforcement (9 files)
- Passthrough timing support for interactive commands
- Exit code preservation for CI/CD reliability

## Tracking Validation Tests
- 6 unit tests in src/tracking.rs (was 0)
  - estimate_tokens, args_display, DB round-trip
  - Passthrough non-dilution, TimedExecution timing
- 2 UTF-8 tests for gh_cmd truncate() (emoji support)
- scripts/test-tracking.sh: end-to-end smoke tests (9 checks)

## rtk learn (CLI Correction Detector)
- New module: src/learn/ (detector, report, orchestration)
- Analyzes Claude Code JSONL sessions for CLI error patterns
- Auto-generates .claude/rules/cli-corrections.md
- 18 new tests (detector: 15, report: 3)
- Commands: rtk learn [--write-rules] [--since N] [--format json]

## Provider Extensions
- ExtractedCommand: +output_content, +is_error, +sequence_index
- Backward compatible with existing discover::run()
- 3 new provider tests (capture, error flag, sequence)

## Test Results
✓ 201 unit tests passed (183 existing + 18 new)
✓ 9 tracking smoke tests passed
✓ cargo fmt + clippy clean
✓ No deprecation warnings

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 10:05:06 +01:00
Florian BRUNIAUX 060c38b3c1 feat(read): add stdin support via "-" path
Add ability to read from stdin using the special path "-", following
Unix conventions. Also fixes a pre-existing bug in git.rs push output.

Changes:
- src/main.rs: Check for Path::new("-") and route to run_stdin()
- src/read.rs: Add run_stdin() function for stdin processing
- src/read.rs: Use Language::Unknown for stdin (no file extension)
- src/git.rs: Fix unused format! result in push command
- Unit test: test_stdin_support_signature verifies function exists
- Smoke tests: 1 assertion for stdin pipe

Usage:
  echo "code" | rtk read -
  cat file.txt | rtk read - --level aggressive
  somecommand | rtk read - -n

Note: Stdin detection requires explicit "-" path to avoid hanging.
No automatic stdin detection is performed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 23:33:45 +01:00
Florian BRUNIAUX a240d1a1ee feat(grep): add extra args passthrough (-i, -A/-B/-C, etc.)
Add support for passing additional ripgrep arguments to rtk grep
while preserving RTK's token-optimized output formatting.

Changes:
- src/main.rs: Add extra_args field to Grep command variant
- src/main.rs: Pass extra_args to grep_cmd::run()
- src/grep_cmd.rs: Add extra_args parameter to run() signature
- src/grep_cmd.rs: Inject extra_args into ripgrep command
- Unit test: test_extra_args_accepted verifies parameter exists
- Smoke tests: 2 assertions for -i and -A flags

Usage note: Extra args must come AFTER pattern and path:
  ✓ rtk grep "pattern" src/ -i
  ✗ rtk grep "pattern" -i  (clap interprets -i as path)

This enables full ripgrep functionality (case-insensitive, context
lines, word boundaries, globs) while maintaining RTK's compact output.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 23:19:43 +01:00
Florian BRUNIAUX 614ff5c13f feat(pnpm): add fallback passthrough for unsupported subcommands
Add external_subcommand variant to PnpmCommands enum to handle
unsupported pnpm operations by passing them through directly.

Changes:
- src/pnpm_cmd.rs: Add run_passthrough() function with OsString support
- src/pnpm_cmd.rs: Add OsString import
- src/main.rs: Add PnpmCommands::Other variant with external_subcommand
- src/main.rs: Add match arm for pnpm passthrough
- Unit test: test_run_passthrough_accepts_args verifies signature
- Smoke tests: Conditional test for pnpm help if pnpm is available

This maintains compatibility with all pnpm commands while preserving
RTK's token-optimized versions for list/outdated/install.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 22:21:03 +01:00
Florian BRUNIAUX a27bce82f0 fix: allow git status to accept native flags
Previously, `rtk git status` was the only git subcommand that rejected
all arguments. This fix aligns it with other git subcommands (diff, log,
show, etc.) by accepting native git flags.

Changes:
- Extract format_status_output() as pure testable function
- Add args variant to Clap Status command with trailing_var_arg
- Modify run_status() to accept args parameter
- Passthrough mode: if user provides flags (--short, -s, --porcelain),
  forward directly to git without RTK formatting
- Default mode: no flags = RTK compact formatting (unchanged behavior)
- Add 5 unit tests for format_status_output (clean, modified, untracked,
  mixed, truncation)
- Add 4 smoke tests for flag passthrough (--short, -s, --porcelain)

Test results:
- 151 unit tests passed (5 new)
- 69 smoke tests passed (4 new for status flags)

Fixes the issue where commands like `rtk git status --short` were
rejected with "unexpected argument" error.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 16:42:06 +01:00
Florian BRUNIAUX cf26ad477b feat: migrate vitest, playwright, pnpm to OutputParser trait
Complete Phase 4 module migrations - refactor to use unified parser infrastructure:

**Modules Migrated:**
1. vitest_cmd.rs → VitestParser : OutputParser<Output=TestResult>
2. playwright_cmd.rs → PlaywrightParser : OutputParser<Output=TestResult>
3. pnpm_cmd.rs → PnpmListParser + PnpmOutdatedParser : OutputParser<Output=DependencyState>

**Architecture:**
- All modules now use three-tier fallback (Full/Degraded/Passthrough)
- Leverage TokenFormatter trait for Compact/Verbose/Ultra modes
- Canonical types (TestResult, DependencyState) replace ad-hoc structures
- Consistent error handling with emit_degradation_warning/emit_passthrough_warning

**Benefits:**
- 41 lines removed (762 insertions, 803 deletions)
- Unified formatting across all test runners
- Observable parsing tiers in verbose mode
- Better maintainability with shared infrastructure
- Foundation for future module migrations

**Testing:**
- 10 new tests added (4 vitest, 3 playwright, 3 pnpm)
- All migrated modules pass their test suites
- JSON Tier 1 parsing validated
- Regex Tier 2 fallback validated
- Passthrough Tier 3 safety validated

**Next Steps:**
- Migrate remaining modules (lint_cmd, tsc_cmd, gh_cmd, prisma_cmd)
- Add observability (track parse_tier in tracking.db)
- Performance benchmarking of new architecture

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 08:44:11 +01:00
Florian BRUNIAUX 50ba21e2e5 feat: add JSON parsing with safe fallbacks for vitest, playwright, pnpm
Implement "Structured Output First" strategy with graceful degradation:

Phase 1 (Quick Wins):
- vitest: Add --reporter=json flag
- playwright: Add --reporter=json flag
- pnpm list/outdated: Add --json/--format json flags

Phase 2 (Safe Fallbacks):
- All modules: JSON parsing with [RTK:DEGRADED] fallback to regex
- Prevents silent failures and false data returns
- Three-tier fallback: JSON → Regex → Truncated passthrough

Impact:
- Eliminates 75% of maintenance risk from output format changes
- Provides structured data parsing for better token compression
- Maintains backward compatibility with existing regex parsers

Token savings maintained while improving reliability and future-proofing
against tool version changes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 08:43:19 +01:00
Florian BRUNIAUX 2d66726206 Add TDD skill, fix 3 failing tests, add 17 diff_cmd tests
- Fix test_analyze_logs: use normalizable paths instead of distinct IPs
- Fix test_filter_outdated: match real pnpm outdated output format
- Fix test_filter_ansi_colors: add missing Tests line for stats parsing
- Add .claude/skills/rtk-tdd/ with Red-Green-Refactor workflow
- Add testing-patterns.md reference with untested modules backlog
- Update CLAUDE.md Testing Strategy with TDD mandate and pre-commit gate
- Add 17 tests to diff_cmd.rs (similarity, truncate, compute_diff, condense)
- Test suite: 102/105 → 122/122

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 14:20:25 +01:00
Florian BRUNIAUX 49b3cf293d feat: npm/npx routing, pnpm build/typecheck, --skip-env flag
- npm run: filter boilerplate (> script, npm WARN, progress)
- npx: intelligent routing to specialized filters
  (tsc, eslint, prisma, next, prettier, playwright)
- pnpm build: delegates to next_cmd filter
- pnpm typecheck: delegates to tsc_cmd filter
- --skip-env global flag: propagates SKIP_ENV_VALIDATION=1

New module: src/npm_cmd.rs with 2 unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:39:03 +01:00
Florian BRUNIAUX f87be329b5 fix: add security validation and error handling to pnpm
Based on code review feedback:
- Add package name validation (prevent command injection)
- Fix error propagation (return Err instead of Ok on failures)
- Add comprehensive tests for validation

Security improvements:
- Validate package names against npm rules (alphanumeric + @/-/_/.)
- Reject path traversal attempts (..)
- Reject shell metacharacters and excessive length (>214 chars)
- Tests cover injection attempts like "lodash; rm -rf /"

Error handling:
- pnpm failures now return proper errors (fixes CI/CD false positives)
- Error messages include pnpm's stderr for debugging

Testing:
- 4 new tests for package name validation (valid + invalid cases)
- Existing filter tests preserved

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-28 15:14:44 +01:00
Florian BRUNIAUX 681729d205 feat: add pnpm support (list, outdated, install)
Adds ultra-compact output for pnpm commands to support modern
JavaScript stacks (T3 Stack, Turborepo, Nx).

Commands added:
- rtk pnpm list --depth=0 (filter box-drawing, keep packages)
- rtk pnpm outdated (extract upgrades: "pkg: old → new")
- rtk pnpm install <pkg> (filter progress bars, keep summary)

Implementation:
- New module: src/pnpm_cmd.rs
- Filters: box-drawing chars, legend, metadata, progress bars
- Output format: "package: current → latest" for upgrades
- Testing: Verified on production T3 Stack codebase (Méthode Aristote)

Market impact:
- pnpm = 40% of npm downloads (rising rapidly)
- T3 Stack = dominant Next.js starter
- Reduction: 80-90% for outdated, ~70% for list (depth >0)

Related: Issue #3

Test cases verified:
- rtk pnpm list --depth=0 ✓
- rtk pnpm outdated ✓ (shows "All packages up-to-date ✓")
- Unit tests for filter functions ✓

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-28 14:55:19 +01:00