Skip to content

git add: tracking records -1300% savings (filter adds info to silent command) #89

Closed

Description

@thehoff

Symptom

`contextcrawler gain` shows worst-performing buckets dominated by `git add` (26 distinct buckets, all around −1300% savings):

```
rtk git add src/cmds | n=26 | input=26 | output=377 | -1350%
rtk git add src/hook | n=18 | input=18 | output=257 | -1327%
rtk git add -A | n=25 | input=25 | output=301 | -1104%
…
```

Root cause

`src/cmds/git/git.rs:1007-1055` (`run_add`):

  1. Native `git add` produces ~0 stdout when successful.
  2. Filter runs an extra `git diff --cached --stat --shortstat` to summarise what was staged.
  3. Prints `"ok 7 files changed, 87 insertions(+)"` — ~14 tokens.
  4. Tracking records `input_tokens=1, output_tokens=14, savings=(1-14)/1 = -1300%`.

The summary is genuinely useful (the agent learns what was staged) but the tracking math treats an information addition as a regression.

Fix options

Option 1 — exclude informational-addition commands from the savings %.

Add a flag on `TimedExecution::track` (or new `track_informational`) that records the row but excludes it from `SUM(savings_pct)` aggregations.

Option 2 — apples-to-apples baseline.

Treat the would-have-been output as the baseline. For `git add`: the user would have followed up with `git status` / `git diff --cached` anyway. Include that hypothetical token count in `input_tokens` so the math reflects real savings.

Option 3 (preferred for v1) — track `git add` against a synthetic baseline = output of `git status --short` had the user run it next.

```rust
let synthetic_baseline = git_cmd(global_args)
.args(["status", "--short"])
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).into_owned())
.unwrap_or_default();
timer.track(
&format!("git add {}", args.join(" ")),
&format!("contextcrawler git add {}", args.join(" ")),
&synthetic_baseline, // input = what user would have asked next
&compact, // output = compact summary
);
```

This gives positive savings when the change is large, negative when trivial — which is the honest picture.

Acceptance

  • `git add` no longer dominates the worst-savings list.
  • Aggregate savings for `git add` over a busy session sits in roughly +30% to +70% range, not -1300%.
  • The user-visible `"ok N files…"` summary stays unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions