git diff
built-in 0.0% Savings
0 Commands
0 Tokens saved
6 Tests
Install
Safety checks passed
Filter definition
# git-diff.toml — reduce a full unified diff to a per-file change summary
#
# Raw: full unified diff (potentially thousands of lines)
# Filtered: one line per file with insertion/deletion counts, plus a total
#
# This filter used to `run = "git diff --stat {args}"`. The patch content was
# then destroyed before tokf ever saw it — a user asking for a diff got a line
# summary, and `tokf raw <id>` could not give the patch back (issue #430).
# The summary is now computed here, over the real diff, so the patch is
# captured in history and recoverable.
#
# Escape hatches: when the model needs the actual diff content (or an
# alternative summary format), it can pass any of the flags in
# `passthrough_args` and tokf will pass `git diff` straight through. The list
# below was chosen from observed agent retry patterns: forcing a summary with
# no escape caused models to thrash through ~50 retries trying every variation
# of `git diff` to get the patch content out.
command = "git diff"
description = "Summarise a diff as per-file insertion/deletion counts"
# Skip the filter entirely when the user explicitly asks for diff content,
# specific context-line counts, or an alternative summary format they would
# rather have than ours.
passthrough_args = [
"-p", # patch (full diff content)
"--patch", # also matches --patch-with-stat, --patch-with-raw, --patch-id
"--stat", # git's own stat rendering
"-U", # -U3, -U10, ... custom unified context line counts
"--unified",
"--numstat", # alternative summary: machine-readable
"--shortstat", # alternative summary: one line
"--raw", # alternative summary: raw format
]
# Anchored to column 0 on purpose. `contains = "fatal:"` would fire on any
# patch whose *content* mentions "fatal:", collapsing a legitimate diff to a
# single error line — a real hazard now that the full patch flows through this
# filter rather than a `--stat` summary. In a unified diff every content line
# is prefixed with `+`, `-`, or a space, so only git's own errors start at
# column 0.
match_output = [
{ pattern = "(?m)^fatal: ", output = "✗ {line_containing}" },
]
# NOTE: the counting sections, the per-file [[chunk]] and the totals
# aggregates below are duplicated in git/show.toml. tokf filters have no
# include mechanism (config resolution is first-match-wins, by design),
# so this is copied on purpose — but it is logic, not boilerplate.
# Fix the sign-prefix patterns in both files or neither.
# Whole-output counts for the totals line.
#
# Stateful on purpose: they only collect inside a hunk body (between an `@@`
# header and the next file's `diff --git`), so nothing outside a real diff can
# be mistaken for changed content.
#
# The patterns exclude the `+++ b/…` / `--- a/…` file headers — and nothing
# else. An earlier, simpler `^\+([^+]|$)` also swallowed every content line
# whose own first character was `+` or `-` (markdown bullets, YAML list items,
# `--flag` in a script), silently undercounting very ordinary diffs.
#
# Read them as "starts with the sign, but is not the literal `+++ `/`--- `
# header": the alternation spells out the 1-, 2- and 3-character cases because
# Rust's regex crate has no lookahead.
[[section]]
name = "file-headers"
match = '^diff --git '
collect_as = "file_header_lines"
[[section]]
name = "added"
enter = '^@@ '
exit = '^diff --git '
match = '^\+([^+]|$|\+([^+]|$)|\+\+[^ ])'
collect_as = "added_lines"
[[section]]
name = "removed"
enter = '^@@ '
exit = '^diff --git '
match = '^-([^-]|$|-([^-]|$)|--[^ ])'
collect_as = "removed_lines"
# One chunk per file, counting its own added/removed lines.
[[chunk]]
split_on = '^diff --git '
collect_as = "files"
# Use the `b/` (destination) path so renames report where the file ended up.
[chunk.extract]
pattern = '^diff --git a/.* b/(.*)$'
as = "path"
[[chunk.aggregate]]
pattern = '^\+([^+]|$|\+([^+]|$)|\+\+[^ ])'
count_as = "added"
[[chunk.aggregate]]
pattern = '^-([^-]|$|-([^-]|$)|--[^ ])'
count_as = "removed"
[on_success]
output = """{files | each: "{path} | +{added} -{removed}" | join: "\n"}
{file_count} files changed, {insertions} insertions(+), {deletions} deletions(-)"""
[[on_success.aggregates]]
from = "file_header_lines"
pattern = '^diff --git '
count_as = "file_count"
[[on_success.aggregates]]
from = "added_lines"
pattern = '^\+'
count_as = "insertions"
[[on_success.aggregates]]
from = "removed_lines"
pattern = '^-'
count_as = "deletions"
[on_failure]
tail = 5
# Route --name-only / --name-status to a tree-structured child filter
# instead of passing through unfiltered.
[[variant]]
name = "name-list"
detect.args_pattern = '--(name-only|name-status)'
filter = "git/diff-name-list"
Examples
empty diff produces no output
~0 tokens → ~0 tokens
Raw output
Filtered output
non-fatal failure passes through via tail
~11 tokens → ~11 tokens
Raw output
error: something went wrong details here
Filtered output
error: something went wrong details here
fatal revision error shows friendly message
~9 tokens → ~10 tokens
Raw output
fatal: bad revision 'nonexistent'
Filtered output
✗ fatal: bad revision 'nonexistent'
a patch whose content mentions fatal: is not mistaken for an error
~56 tokens → ~19 tokens
(66% saved)
Raw output
diff --git a/src/log.rs b/src/log.rs
index c2f62a6..79d15bc 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -1,3 +1,3 @@
- eprintln!("fatal: {}", err);
+ eprintln!("fatal: {} ({})", err, code);
} Filtered output
src/log.rs | +1 -1 1 files changed, 1 insertions(+), 1 deletions(-)
full patch reduces to per-file insertion/deletion counts
~334 tokens → ~45 tokens
(87% saved)
Raw output
diff --git a/src/main.rs b/src/main.rs
index c2f62a6..79d15bc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,9 @@
use std::process::exit;
-fn main() {
- let code = run();
- exit(code);
+fn main() -> anyhow::Result<()> {
+ let code = run()?;
+ exit(code)
}
+
// trailing comment
diff --git a/src/config.rs b/src/config.rs
index 49728a7..d2d8dfb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -12,7 +12,6 @@ impl Config {
pub fn load() -> Self {
Self::default()
}
-
- pub fn unused(&self) {}
+ pub fn used(&self) {}
}
diff --git a/docs/old-name.md b/docs/new-name.md
similarity index 94%
rename from docs/old-name.md
rename to docs/new-name.md
index ef8c5ff..e2bb6e0 100644
--- a/docs/old-name.md
+++ b/docs/new-name.md
@@ -1,4 +1,4 @@
-# Old Title
+# New Title
Body text that did not change.
More body text.
diff --git a/assets/logo.png b/assets/logo.png
index 1088fc2..0cbf404 100644
Binary files a/assets/logo.png and b/assets/logo.png differ
diff --git a/src/added.rs b/src/added.rs
new file mode 100644
index 0000000..7cfcc0f
--- /dev/null
+++ b/src/added.rs
@@ -0,0 +1,3 @@
+pub fn brand_new() -> u32 {
+ 42
+} Filtered output
src/main.rs | +4 -3 src/config.rs | +1 -2 docs/new-name.md | +1 -1 assets/logo.png | +0 -0 src/added.rs | +3 -0 5 files changed, 9 insertions(+), 6 deletions(-)
content lines starting with + or - are counted, not mistaken for headers
~88 tokens → ~23 tokens
(74% saved)
Raw output
diff --git a/flags.sh b/flags.sh new file mode 100644 index 0000000..886e1ac --- /dev/null +++ b/flags.sh @@ -0,0 +1,2 @@ +--verbose +--quiet diff --git a/notes.md b/notes.md index 510a976..7888c12 100644 --- a/notes.md +++ b/notes.md @@ -1,4 +1,5 @@ - alpha -- beta +- BETA - gamma -plain +- delta +plain2
Filtered output
flags.sh | +2 -0 notes.md | +3 -2 2 files changed, 5 insertions(+), 2 deletions(-)
Warning: Community filters are third-party code. Review the filter definition above before installing it in production environments.Browse all filters