74 Commits

Author SHA1 Message Date
Joan Bordeau 93364b5457 feat(sqlite): add custom sqlite db location 2026-02-10 21:42:46 +01:00
Florian BRUNIAUX 645a773a65 feat(cargo): add cargo install filtering with 80-90% token reduction
Strip dep compilation, downloading, locking noise from cargo install output.
Keep only installed/replaced/error lines with compact summary format.

Closes #69

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 11:36:14 +01:00
Florian BRUNIAUX 848a63dfac feat(init): auto-patch settings.json for frictionless hook installation
## Summary

Eliminates manual settings.json setup friction by automating hook
registration with safety (backup, atomic writes, idempotency).

## Changes

### Core Features
- **Auto-patch**: Default `rtk init -g` prompts to patch settings.json [y/N]
- **CLI flags**: `--auto-patch` (no prompt), `--no-patch` (manual), `--uninstall` (full cleanup)
- **Safety**: Automatic backup to `settings.json.bak` before modification
- **Idempotency**: Detects existing hook, skips modification
- **Status check**: `rtk init --show` now displays settings.json registration

### Implementation
- New types: `PatchMode` (Ask/Auto/Skip), `PatchResult` (tracking outcomes)
- New functions in `src/init.rs`:
  - `hook_already_present()` - Detects RTK hook via substring match
  - `insert_hook_entry()` - Deep-merges hook using idiomatic `entry()` API
  - `atomic_write()` - Crash-safe writes with tempfile
  - `patch_settings_json()` - Main orchestrator
  - `uninstall()` - Complete cleanup (hook, RTK.md, settings.json)
- Modified functions: `run()`, `run_default_mode()`, `run_hook_only_mode()`, `show_config()`

### Code Quality Improvements
- Refactored `insert_hook_entry()` to use Rust `entry()` API (no manual unwraps)
- Simplified `hook_already_present()` with iterator chains (3x shorter)
- Improved error messages with file paths and actionable hints
- Fixed string allocation (to_str() vs to_string())

### Dependencies
- Added `preserve_order` feature to `serde_json` (key order preservation)
- Moved `tempfile` to production dependencies (atomic writes)

### Documentation
- **README.md**: Updated Quick Install, added Installation Flags, Uninstalling, Troubleshooting, What Are Hooks sections
- **INSTALL.md**: Updated Recommended Setup, added Common User Flows, Uninstalling sections
- **CHANGELOG.md**: Documented new feature under Unreleased

### Testing
- 11 new unit tests for hook detection, insertion, atomic writes, cleanup
- All 249 tests passing
- Smoke tested: install, idempotency, show, uninstall

## User Impact

**Before**: Users had to manually copy JSON snippet to settings.json
**After**: Single command with prompt, automatic backup, clean uninstall

## Breaking Changes

None. Backwards compatible - manual setup still works via `--no-patch`.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 16:12:40 +01:00
Florian BRUNIAUX 38fc860c31 refactor(init): eliminate DRY violations and improve error handling
## Code Quality Improvements

**Extracted helper functions:**
- `prepare_hook_paths()`: Prepare hook directory and paths (DRY)
- `ensure_hook_installed()`: Idempotent hook installation with chmod
- `write_if_changed()`: Generic file write with idempotence

**Before (duplicated):**
- Hook path logic repeated in default_mode + hook_only_mode
- Hook write logic repeated (lost idempotence in hook-only)
- RTK.md write logic duplicated

**After (DRY):**
- Single source of truth for each operation
- Consistent idempotence across all modes
- Reusable helpers for future file operations

## Error Handling Enhancements

**Improved error context:**
- `.with_context(|| format!("Failed to write hook to {}", path))`
- All fs operations now include the path that failed
- Migration warnings include line numbers and actionable steps

**Better Windows messaging:**
- Clear explanation of platform limitations
- Explicit fallback behavior

## API Improvements

**Idiomatic Rust:**
- `&PathBuf` → `&Path` for all function parameters
- Pattern match tuple instead of if/else chain
- `anyhow::bail!` for Windows hook-only error

## Impact

- **Maintainability**: Single place to update hook/file logic
- **Debuggability**: Error messages show exact paths
- **Robustness**: Consistent idempotence prevents conflicts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 15:28:24 +01:00
Florian BRUNIAUX 9620f66cd6 feat(init): refactor to hook-first with slim RTK.md
## Changes

**New default mode (hook + RTK.md):**
- Embed hook script in binary (include_str!)
- Write hook + chmod +x with guards (rtk/jq check before set -e)
- Write slim RTK.md (10 lines: meta commands only)
- Add @RTK.md reference to CLAUDE.md
- Print settings.json instructions (no auto-patch)

**Migration:**
- Auto-detect old <!-- rtk-instructions --> block
- Remove 137-line block, preserve user content
- Replace with @RTK.md reference

**New CLI flags:**
- `--claude-md`: Legacy mode (full injection)
- `--hook-only`: Hook only, no RTK.md
- Default (no flags): Hook + RTK.md (recommended)

**Enhanced --show:**
- Detect hook executable status (Unix)
- Detect hook guards (rtk/jq)
- Detect @RTK.md vs old block
- Show slim vs legacy mode

**Files added:**
- hooks/rtk-rewrite.sh (embedded, with guards)
- hooks/rtk-awareness.md (slim RTK.md content)

**Token savings:**
~2000 tokens → ~10 tokens in context (99.5% reduction)
Hook rewrites commands transparently (0 tokens overhead)

**Tests:** 9 new tests, all passing (236 total)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 15:11:24 +01:00
Florian BRUNIAUX d5f8a94604 fix(discover): add cargo check support, wire RtkStatus::Passthrough, enhance rtk init
## Discover Registry Fixes
- Add `check` to cargo pattern (registry.rs:52)
- Add `("check", 80.0)` savings to cargo rule
- Wire `RtkStatus::Passthrough` for `cargo fmt` (0% savings, passthrough mode)
- Add `status: RtkStatus` field to `Classification::Supported`
- Extract status from subcommand rules in classify_command()
- Fix UTF-8 truncation bug in report.rs truncate_str() (panic on multi-byte chars)

## Tests (7 new)
- test_classify_cargo_check()
- test_classify_cargo_check_all_targets()
- test_classify_cargo_fmt_passthrough() → status = Passthrough
- test_classify_cargo_clippy_savings()
- test_patterns_rules_length_match() → assert PATTERNS.len() == RULES.len()
- test_registry_covers_all_cargo_subcommands() → coupling test
- test_registry_covers_all_git_subcommands() → coupling test

## RTK Init Rewrite
- Rewrite template in English with 32+ commands grouped by workflow
- Add version marker `<!-- rtk-instructions v2 -->` for idempotency
- Fix idempotency detection: use marker instead of French text
- Add tests:
  - test_init_mentions_all_top_level_commands() → 15 key commands
  - test_init_has_version_marker()

## Documentation
- CLAUDE.md: dual format (raw + rtk) for all dev commands
- CLAUDE.md: pre-commit gate uses rtk
- ~/.claude/CLAUDE.md: add Cargo section (80-90% savings)

## Verification
✅ 229 tests pass (7 new)
✅ 88 smoke tests pass
✅ cargo fmt + clippy clean
✅ All coupling tests enforce registry/Commands alignment

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 16:28:13 +01:00
Florian BRUNIAUX 60d2d252ef fix: P0 crashes + cargo check + dedup utilities + discover status
Phase 1: Fix P0 crashes (3 bugs)
- Add external_subcommand fallback for cargo/docker/kubectl
- Fixes crashes on unsupported subcommands (e.g., cargo fmt, docker build)
- All passthroughs now route gracefully instead of Clap parse errors

Phase 2: cargo check handler + refactor (-40 lines)
- Add dedicated cargo check handler (most frequently used missing command)
- Extract run_cargo_filtered() to eliminate 90 lines of duplication
- Fix filter_cargo_build() to handle "Checking" prefix (not just "Compiling")
- Normalize exit code propagation in run_test()

Phase 3: Utility deduplication (-60 lines)
- Fix utils::truncate() Unicode handling (char-aware, not byte-based)
- Remove 5 duplicated utility functions across modules:
  - 3x truncate() → use crate::utils::truncate
  - 1x strip_ansi() → use crate::utils::strip_ansi
- Replace ~60 lines of inline package manager detection with utils::package_manager_exec()
- Clean: lint_cmd, prettier_cmd, playwright_cmd now use shared utils

Phase 4: Discover reporting improvements
- Add RtkStatus enum (Existing/Passthrough/NotSupported)
- Show status column in discover report to distinguish handler types
- Prevents future misleading "build 9 git subcommands" false analyses

Cleanup:
- Remove 2 unused imports (parser::ParseError, std::collections::HashMap)
- Reduce clippy warnings from 23 to 19

Testing:
- 220 tests pass
- 88 smoke tests pass
- All manual verification complete

Net: +10 lines, -3 P0 bugs, -5 duplications, +1 feature, +1 enum

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 10:37:50 +01:00
Florian BRUNIAUX 40e7eadbaf fix(git): accept native git flags in add command (including -A)
Problem:
- `rtk git add -A` failed with "unexpected argument '-A' found"
- Git flags like -A, -p, --all were rejected by Clap parser
- Only filenames could be passed to `git add`

Solution:
- Add `allow_hyphen_values = true` to Add command args (following PR #5 pattern)
- Change Add enum variant from `Add { files }` to `Add` (unified with other git commands)
- Modify run_add() to accept args slice and pass all arguments to git
- Add exit code propagation for consistency with other git commands

Impact:
- All native git add flags now work: -A, -p, --all, --update, etc.
- Maintains RTK compact output format ("ok ✓ 2 files changed, ...")
- Preserves backward compatibility (no args defaults to ".")

Testing:
- Manual: `rtk git add -A` works correctly
- All existing tests pass (154 passed)
- Smoke tests unchanged (git add not included in test-all.sh)

Fixes: Argument parsing error for git add with native flags

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 15:54:20 +01:00
patrick szymkowiak 3df8ce5525 Merge pull request #57 from FlorianBruniaux/fix/rtk-tsc-show-all-errors
fix(tsc): show every TypeScript error instead of collapsing by code
2026-02-04 18:23:45 +01:00
Florian BRUNIAUX 67e8de8732 fix(tsc): show every TypeScript error instead of collapsing by code
The previous implementation grouped errors by error code within each
file, showing only the first message when multiple errors shared the
same code (e.g. TS2322). This hid critical debugging information and
forced users to bypass rtk entirely.

Changes:
- Show each error individually with line number and full message
- Capture and display tsc continuation/context lines
- Increase message truncation from 60 to 120 chars
- Remove artificial limits (was: 3 codes/file, 10 files max)
- Compact top-codes summary to a single line

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 18:12:46 +01:00
patrick szymkowiak a5d0fd19fd Merge pull request #55 from LivioGama/fix/rtk-init-global-path
Fix rtk init global path
2026-02-03 17:40:11 +01:00
Patrick szymkowiak ea7cdb7a3b fix(ls): compact output (-72% tokens) + fix discover panic
- ls: rewrite to strip permissions/owner/group/dates, show only
  names with dir/ suffix and human sizes. Properly handle flag
  ordering (path -l), -lh, multi-paths, --all.
- discover: remove orphan diff pattern that caused index out of
  bounds panic (PATTERNS had 22 entries vs RULES 21)
- benchmark: add 8 ls test cases
- test-all: add 5 ls smoke tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:05:01 +01:00
Patrick szymkowiak ffe0d2e037 chore: cleanup diff references, fix docker ps, widen diff truncation
- Remove rtk diff from docs, tests, discover registry (command exists
  but was over-promoted)
- docker ps: include container ID in compact output
- diff_cmd: widen truncation from 35 to 70 chars per side

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 15:38:56 +01:00
Patrick szymkowiak fcc14624f8 fix(find): rewrite with ignore crate + fix json stdin + benchmark pipeline
- find: replace fd/find subprocess with ignore::WalkBuilder for native
  .gitignore support, fix "." pattern, fix --max file counting
- json: add stdin support via "-" path (same pattern as read)
- benchmark: one-line-per-test format with icons for CI logs,
  local debug files only when not in CI, remove md upload/PR steps

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 15:38:17 +01:00
Florian BRUNIAUX b13d92c9ea fix(docs): escape HTML tags in rustdoc comments
Fixes 6 rustdoc warnings:
- Escape <action>, <detail>, <hash>, <branch>, <stats> tags
- Use backticks for [RTK:PASSTHROUGH] marker

All rustdoc warnings now resolved.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 11:33:40 +01:00
Florian BRUNIAUX 521eb1b9bc docs(tracking): complete API documentation + rustdoc comments
Add comprehensive documentation for tracking.rs public APIs:

**New Files:**
- docs/tracking.md (12 pages)
  - Architecture & data flow
  - All public APIs (12 methods, 7 types)
  - Usage examples (basic, CI/CD, dashboards, Rust lib)
  - JSON/CSV export schemas
  - Database schema & migrations
  - Integration examples (GitHub Actions, Python, Rust)
  - Security, performance, troubleshooting

- claudedocs/TRACKING_DOCUMENTATION.md
  - Documentation summary & metrics

**Updated Files:**
- src/tracking.rs
  - Module-level docs (//!)
  - Comprehensive doc comments (///) for all public APIs
  - Examples with error handling
  - Deprecation notices for legacy functions

- README.md
  - Pointer to docs/tracking.md after rtk gain section

**Coverage:**
- 7 public structs documented
- 12 public methods documented
- 3 utility functions documented
- 20+ code examples
- 3 integration examples (CI/CD, dashboards, Rust lib)
- JSON/CSV/SQL schemas

**Testing:**
- All 6 tracking tests still pass
- 100% coverage maintained

Closes gap: CLI was documented, but public APIs were not.
Now fully documented for external integration (CI/CD, dashboards, Rust lib usage).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 11:22:20 +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
Livio Gamassia c58bd95062 Fix global init path and append behavior 2026-02-03 08:30:54 +00: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 32bbd02534 feat(git): add fallback passthrough for unsupported subcommands
Add external_subcommand variant to GitCommands enum to handle
unsupported git operations (tag, remote, rev-parse, etc.) by
passing them through directly to git.

Changes:
- src/git.rs: Add run_passthrough() function with OsString support
- src/main.rs: Add GitCommands::Other variant with external_subcommand
- src/main.rs: Add OsString import and match arm for passthrough
- Unit test: test_run_passthrough_accepts_args verifies signature
- Smoke tests: 3 new assertions for tag, remote, rev-parse

This preserves all git functionality while maintaining RTK's
token-optimized commands for supported operations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 21:58:09 +01:00
Florian BRUNIAUX 278cc5700b feat: add rtk tree + fix rtk ls + audit phase 1-2
⚠️ MERGE AFTER: Résoudre issues Patrick (curl, benchmark, bypass)

## Changes

### 1. rtk tree - NEW COMMAND ✨
- Proxy vers `tree` natif avec filtrage token-optimized
- Filtre ligne summary ("X directories, Y files")
- Support complet flags natifs (-L, -d, -a, etc.)
- Message installation si tree absent
- Tests: 5/5 passing

Files:
- src/tree.rs (new, 159 lines)
- src/main.rs (add Tree command)

### 2. rtk ls - FIX 🐛
- Fix: ne force plus `-la` par défaut
- Comportement: passthrough pur vers ls natif
- Permet `rtk ls` simple sans flags forcés

Files:
- src/ls.rs (remove default -la)

### 3. Tests - UPDATE ✅
- Fix 3 tests obsolètes rtk ls (--depth, -f tree)
- Add 4 tests rtk tree
- Results: 75 PASS, 0 FAIL, 1 SKIP (98.7%)

Files:
- scripts/test-all.sh

## Audit Phase 1-2 (local docs)

Inventaire complet + analyse paramètres (40+ commandes):
- claudedocs/COMMAND_AUDIT.md
- claudedocs/PARAMETER_ANALYSIS.md
- claudedocs/rtk-tree-implementation.md
- claudedocs/PATRICK_FEEDBACK.md

15+ gaps critiques identifiés (grep -i, git fallback, etc.)

## Issues Patrick à résoudre AVANT merge

1. curl global à remettre
2. Benchmark.sh à exécuter
3. Souci de token à investiguer
4. Erreur PR/bypass des commandes
5. Commandes cassées à identifier

## Test

```bash
# Tree
rtk tree -L 2 src/
rtk tree -d -L 1 .

# Ls (nouveau comportement)
rtk ls          # Simple listing
rtk ls -la      # Detailed
rtk ls -lh      # Human readable

# Tests
bash scripts/test-all.sh  # 75 PASS ✅
cargo test tree::tests    # 5 PASS ✅
```

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 21:01:19 +01:00
Florian BRUNIAUX 2df4a348ab docs: add suggest hook pattern + fix discover issues URL
Changes:
- Fix discover issues URL: FlorianBruniaux → rtk-ai upstream repo
- Document suggest hook pattern as non-intrusive alternative to auto-rewrite
- Add rtk-suggest.sh template with systemMessage strategy
- Provide comparison table and setup instructions

The suggest hook emits system reminders instead of rewriting commands,
giving Claude Code explicit visibility into rtk alternatives while
preserving user control over execution decisions.

Use cases:
- Learning rtk patterns with visibility into rewrite logic
- Auditing command choices without forced adoption
- Debugging workflows requiring exact command preservation
- User preference for explicit control over transparency

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 17:03:19 +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 edab4e142e feat: add parser infrastructure with three-tier fallback system
Implement Phase 3 of maintainability plan - unified parser architecture:

**Core Components:**
- parser/mod.rs: OutputParser trait + ParseResult enum (Full/Degraded/Passthrough)
- parser/error.rs: ParseError types with thiserror (JSON, Pattern, Partial, etc.)
- parser/types.rs: Canonical types (TestResult, LintResult, DependencyState, BuildOutput)
- parser/formatter.rs: TokenFormatter trait with Compact/Verbose/Ultra modes
- parser/README.md: Complete usage guide and migration examples

**Three-Tier Fallback System:**
1. Tier 1 (Full): Complete JSON parsing with structured data
2. Tier 2 (Degraded): Partial regex extraction with warnings
3. Tier 3 (Passthrough): Truncated raw output with [RTK:PASSTHROUGH] marker

**Benefits:**
- Never returns false data silently (fixes prisma_cmd issue)
- Graceful degradation on tool version changes
- Unified interface across all tool types
- Observable degradation with [RTK:DEGRADED] warnings
- Foundation for Phase 4 module migrations

**Dependencies:**
- Added thiserror 1.0 for structured error types

**Testing:**
- 3 unit tests for ParseResult tier system
- Tests pass: tier(), is_ok(), map(), warnings()

Next: Phase 4 - Migrate existing modules to use parser trait

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 08:43:19 +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 1d857914d6 feat: add local LLM analysis, filter improvements, and testing scripts
Add smart code analysis with local LLM integration (rtk smart command),
improve filter.rs formatting and readability, and add comprehensive
testing utilities.

Key changes:
- local_llm.rs: Ultra-compact code summaries for LLM contexts
- filter.rs: Better formatting, enhanced comment/docstring detection
- main.rs: Integrate smart command routing
- config.rs: Code formatting improvements
- .gitignore: Exclude claudedocs/ directory
- scripts/rtk-economics.sh: Token savings analysis
- scripts/test-all.sh: Comprehensive test runner
- scripts/test-aristote.sh: Project-specific test suite

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 08:43:19 +01:00
Florian BRUNIAUX 2a1e1a8ef3 feat: add execution time tracking to rtk gain analytics
Add exec_time_ms column to SQLite schema and track execution time
for all rtk commands. Display time metrics in gain summary, daily/
weekly/monthly breakdowns, and JSON/CSV exports.

Changes:
- tracking.rs: Add exec_time_ms column, TimedExecution struct
- display_helpers.rs: Add format_duration() helper, update tables
- gain.rs: Display total/avg exec time in summary and by-command
- All command modules: Apply TimedExecution timer wrapper
- Exports: Include total_time_ms and avg_time_ms in JSON/CSV

Example output:
  Total exec time:   24.6s (avg 34ms)
  rtk cargo test        7    -86.1%   349ms avg
  rtk git status      111    -84.1%     1ms avg

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 00:14:06 +01:00
Florian BRUNIAUX 2176369467 fix: convert rtk ls from reimplementation to native proxy
BREAKING CHANGE: Removes --depth, --format (tree/flat/json) flags

Before: `rtk ls` was a reimplementation using WalkBuilder that didn't
support native ls flags like -l, -a, -h, -R.

After: `rtk ls` proxies to native ls, supporting all flags:
- `rtk ls -la` works
- `rtk ls -alh` works
- `rtk ls -R src/` works
- Default: `-la` when no args

Token optimization: filters "total X" line from output.

This aligns with rtk philosophy: proxy and filter, don't reimplement.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-01 21:22:17 +01:00
patrick szymkowiak c9c64cfd30 Merge pull request #36 from FlorianBruniaux/feat/git-show
feat: discover command, auto-rewrite hook, git show
2026-02-01 20:07:12 +01:00
Florian BRUNIAUX 4bb0130695 fix: forward args in rtk git push/pull to support -u, remote, branch
rtk git push and rtk git pull now accept trailing arguments and forward
them to git. Fixes the auto-rewrite hook failing on commands like
`git push -u origin feat/branch`.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 16:38:02 +01:00
Florian BRUNIAUX ff1c7598c2 feat: add discover command, auto-rewrite hook, and git show support
- New `rtk discover` command scans Claude Code JSONL session history to
  identify missed RTK savings and suggest unhandled commands for issues.
  Modular architecture: registry (RegexSet classification), provider
  (SessionProvider trait + ClaudeProvider), report (text/json formatting).

- New PreToolUse auto-rewrite hook transparently intercepts Bash commands
  and rewrites them to rtk equivalents before execution, ensuring 100%
  adoption across all conversations including subagents.

- New `rtk git show` command with compact output: one-line commit summary
  + stat + compacted diff (reuses compact_diff from git diff).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 16:31:34 +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 314accbfd9 feat: curl with auto-JSON detection
- Execute curl -s, auto-detect JSON responses
- JSON output piped through filter_json_string() for schema view
- Non-JSON output truncated to 30 lines with byte count

New module: src/curl_cmd.rs with 4 unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:39:55 +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 517a93d0e4 feat: gh pr create/merge/diff/comment/edit + gh api
- gh pr create: capture URL + number, "ok created #N url"
- gh pr merge: "ok merged #N" confirmation
- gh pr diff: reuse compact_diff() for condensed output
- gh pr comment/edit: generic "ok {action} #N" confirmations
- gh api: auto-detect JSON, pipe through filter_json_string()

5 new tests in gh_cmd.rs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:37:17 +01:00
Florian BRUNIAUX bc31da8ad9 feat: git branch, fetch, stash, worktree commands
- git branch: compact listing (current/local/remote-only)
- git fetch: "ok fetched (N new refs)" confirmation
- git stash: list/show/pop/apply/drop with compact output
- git worktree: compact listing with home dir abbreviation

4 new tests in git.rs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:36:44 +01:00
Florian BRUNIAUX bfd5646f4e feat: cargo build/test/clippy with compact output
- cargo build: strip Compiling/Downloading lines, show errors + summary
- cargo test: show failures only + summary line
- cargo clippy: group warnings by lint rule with locations

New module: src/cargo_cmd.rs with 6 unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:35:59 +01:00
Florian BRUNIAUX 9dbc1178e7 feat: shared infrastructure for new commands
- Make compact_diff pub(crate) in git.rs for cross-module use
- Extract filter_json_string() from json_cmd.rs for reuse
- Add ok_confirmation() to utils.rs for write operation confirmations
- Add detect_package_manager() and package_manager_exec() to utils.rs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:34:54 +01:00
Florian BRUNIAUX 9e322e2aee fix: patrick's 3 issues (latest tag, ccusage fallback, versioning)
1. CRITICAL: Fix 'latest' tag creation after releases
   - Move update-latest-tag job from release.yml to release-please.yml
   - release-please creates tags via API (no push event) → must run in same workflow
   - Job now conditional on release_created output

2. IMPORTANT: Add npx fallback for ccusage + improve message
   - Check binary in PATH first, fallback to 'npx ccusage'
   - Updated message: "npm i -g ccusage (or use npx ccusage)"
   - Consistent with other JS tooling (next_cmd, tsc_cmd, prettier_cmd)

3. PROCESS: Slow down version bumps with release-please config
   - Add release-please-config.json with bump-patch-for-minor-pre-major
   - In 0.x versions: feat: → patch bump instead of minor
   - Prevents rapid version inflation (0.3.1 → 0.5.0 in 21h)

Fixes issues raised by Patrick after PR #21 merge.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 15:24:56 +01:00
Florian BRUNIAUX 3b847f863a fix: optimize HashMap merge and add safety checks
Applies targeted code quality improvements:

Issue #5: Reduce clones in HashMap merge
- Destructure CcusagePeriod to avoid cloning key
- Use .or_insert_with_key() for ccusage data merging
- Keep necessary clones for rtk data (HashMap ownership requirement)
- Affects: merge_daily, merge_weekly, merge_monthly

Issue #7: Replace magic number with named constant
- Add const BILLION: f64 = 1e9
- Improves readability in cache token calculation

Issue #8: Add NaN/Infinity safety check
- Guard format_usd() against invalid float values
- Return "$0.00" for non-finite inputs

Build: Clean (1 pre-existing warning)
Tests: 79/82 passing (3 pre-existing failures)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 14:05:50 +01:00
Florian BRUNIAUX 5b840cca49 fix: comprehensive code quality improvements
Apply systematic quality fixes identified in code audit:

Phase 1: Remove dead code (4 warnings → 0)
- Remove unused run_compact() function in gain.rs
- Remove unused track_tokens() function in tracking.rs
- Remove unused TRACKER singleton (Mutex)
- Clean up CommandRecord struct (remove unused fields)

Phase 2: Add error context and quality fixes
- Add .context() to all ? operators in cc_economics.rs (15+ callsites)
- Add .context() to all ? operators in gain.rs (10+ callsites)
- Fix bounds check panic risk in gain.rs:252 (week_start slice)
- Reduce visibility: estimate_tokens pub → private
- Replace 6 manual loops with idiomatic .collect::<Result<Vec<_>, _>>()?
- Remove residual dev comment (// psk:)
- Remove unnecessary .clone() in main.rs

Phase 3: Refactor duplication (132 lines eliminated)
- Create display_helpers.rs module with PeriodStats trait
- Unify print_daily_full/weekly/monthly in gain.rs (152 lines → 9 lines)
- Implement trait for DayStats, WeekStats, MonthStats
- Zero-overhead compile-time dispatch (monomorphization)
- Output bit-identical, all tests passing

Impact:
- Dead code: -20 lines
- Error context: Errors now actionable instead of opaque
- Duplication: -132 lines of pure duplication
- Safety: Bounds check prevents potential panic
- Idiomaticity: .collect() over manual loops

Metrics:
- Build: 0 errors, 1 warning (pre-existing cache_* fields)
- Tests: 79/82 passing (3 pre-existing failures)
- Clippy: 13 warnings (all pre-existing)
- Functional: rtk gain --daily, rtk cc-economics validated

Addresses code audit feedback from parallel session
Detailed report: claudedocs/refactoring-report.md

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 13:48:03 +01:00
Florian BRUNIAUX ec1cf9a56d feat: add comprehensive claude code economics analysis
Implement `rtk cc-economics` command combining ccusage spending data
with rtk savings analytics for economic impact reporting.

Features:
- Dual metric system (active vs blended cost-per-token)
- Daily/weekly/monthly granularity with ISO-8601 week alignment
- JSON/CSV export support for data analysis
- Graceful degradation when ccusage unavailable
- Real-time data merge with O(n+m) HashMap performance

Architecture:
- src/ccusage.rs: Isolated ccusage CLI interface (7 tests)
- src/cc_economics.rs: Business logic + display (10 tests)
- src/utils.rs: Shared formatting utilities (8 tests)
- Refactored gain.rs to use shared format_tokens()

Test coverage: 17 new tests, all passing
Validated with real-world data (2 months, $3.4K spent, 1.2M saved)

Addresses: #economics-integration
Impact: 24.4% cost savings identified ($830.91 active pricing)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 12:34:47 +01:00
Florian BRUNIAUX 76703ca3f5 feat: add comprehensive temporal audit system for token savings analytics
Implement day-by-day, week-by-week, and monthly breakdowns with JSON/CSV export
capabilities for in-depth token savings analysis and reporting.

New Features:
- Daily breakdown (--daily): Complete day-by-day statistics without 30-day limit
- Weekly breakdown (--weekly): Sunday-to-Saturday week aggregations with date ranges
- Monthly breakdown (--monthly): Calendar month aggregations (YYYY-MM format)
- Combined view (--all): All temporal breakdowns in single output
- JSON export (--format json): Structured data for APIs, dashboards, scripts
- CSV export (--format csv): Tabular data for Excel, Google Sheets, data science

Technical Implementation:
- src/tracking.rs: Add DayStats, WeekStats, MonthStats structures with Serialize
- src/tracking.rs: Implement get_all_days(), get_by_week(), get_by_month() SQL queries
- src/main.rs: Extend Commands::Gain with --daily, --weekly, --monthly, --all, --format flags
- src/gain.rs: Add print_daily_full(), print_weekly(), print_monthly() display functions
- src/gain.rs: Implement export_json() and export_csv() for data export

Documentation:
- docs/AUDIT_GUIDE.md: Comprehensive guide with examples, workflows, integrations
- README.md: Update Data section with new audit commands and export formats
- claudedocs/audit-feature-summary.md: Technical summary and implementation details

Database Scope:
- Global machine storage: ~/.local/share/rtk/history.db
- Shared across all projects, worktrees, and Claude sessions
- 90-day retention policy with automatic cleanup
- SQLite with indexed timestamp for fast aggregations

Use Cases:
- Trend analysis: identify daily/weekly patterns in token usage
- Cost reporting: monthly savings reports for budget tracking
- Data science: export CSV/JSON for pandas, R, Excel analysis
- Dashboards: integrate JSON export with Chart.js, D3.js, Grafana
- CI/CD: automated weekly/monthly savings reports via GitHub Actions

Examples:
  rtk gain --daily                    # Day-by-day breakdown
  rtk gain --weekly                   # Weekly aggregations
  rtk gain --all                      # All breakdowns combined
  rtk gain --all --format json | jq . # JSON export with jq
  rtk gain --all --format csv         # CSV for Excel/analysis

Backwards Compatibility:
- All existing flags (--graph, --history, --quota) preserved
- Default behavior unchanged (summary view)
- No database migration required
- Zero breaking changes

Performance:
- Efficient SQL aggregations with timestamp index
- No impact on rtk command execution speed
- Instant queries even with 90 days of data

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 11:12:45 +01:00
Florian BRUNIAUX d7d8c65b86 fix: improve command robustness and flag support
## Fixes

### Lint crash handling
- Add graceful error handling for linter crashes (SIGABRT, OOM)
- Display warning message when process terminates abnormally
- Show first 5 lines of stderr for debugging context

### Grep command
- Add --type/-t flag for file type filtering (e.g., --type ts, --type py)
- Passes --type argument to ripgrep for efficient filtering

### Find command
- Add --type/-t flag for file/directory filtering
- Default: "f" (files only)
- Options: "f" (file), "d" (directory)

## Testing
- ✅ cargo check passes
- ✅ cargo build --release succeeds
- ✅ rtk grep --help shows --file-type flag
- ✅ rtk find --help shows --file-type flag with default

## Breaking Changes
None - all changes are backwards compatible additions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 17:43:20 +01:00
patrick szymkowiak 64c0b03d4e Merge pull request #11 from FlorianBruniaux/feat/quota-analysis
feat: add quota analysis with multi-tier support
2026-01-29 16:22:36 +01:00
Florian BRUNIAUX 0f7418e958 feat: add GitHub CLI integration with token optimizations
Add rtk gh command for GitHub CLI operations with intelligent
output filtering:

Commands:
- rtk gh pr list/view/checks/status: PR management (53-87% reduction)
- rtk gh issue list/view: Issue tracking (26% reduction)
- rtk gh run list/view: Workflow monitoring (82% reduction)
- rtk gh repo view: Repository info (29% reduction)

Features:
- Level 1 optimizations (default): Remove header counts, @ prefix,
  compact mergeable status (+12-18% savings, zero UX loss)
- Level 2 optimizations (--ultra-compact flag): ASCII icons,
  inline checks format (+22% total savings on PR view)
- GraphQL response parsing and grouping
- Preserves all critical information for code review

Token Savings (validated on production repo):
- rtk gh pr view: 87% (24.7K → 3.2K chars)
- rtk gh pr checks: 79% (8.9K → 1.8K chars)
- rtk gh run list: 82% (10.2K → 1.8K chars)

Global --ultra-compact flag added to enable Level 2 optimizations
across all GitHub commands.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 14:07:39 +01:00
Florian BRUNIAUX 26b314d45b feat: add --quota flag to rtk gain with tier-based analysis
Implements heuristic calculation of monthly quota savings percentage
with support for Pro, Max 5x, and Max 20x subscription tiers.

Features:
- --quota flag displays monthly quota analysis
- --tier <pro|5x|20x> selects subscription tier (default: 20x)
- Heuristic based on ~44K tokens/5h Pro baseline
- Estimates: Pro=6M, 5x=30M, 20x=120M tokens/month
- Clear disclaimer about rolling 5-hour windows vs monthly caps

Example output for Max 20x:
  Subscription tier:        Max 20x ($200/mo)
  Estimated monthly quota:  120.0M
  Tokens saved (lifetime):  356.7K
  Quota preserved:          0.3%

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 12:11:43 +01:00