shrinker-ai 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,295 +1,363 @@
1
- # shrinker
2
-
3
- A small local CLI proof of concept that removes noise from command output before a coding agent or LLM reads it.
4
-
5
- this POC proves that a few conservative, deterministic filters can save useful context without requiring an API key, service, UI, database, or agent-specific integration.
6
-
7
- ## What the POC demonstrates
8
-
9
- - Explicit cross-agent command wrapping: `shrinker exec -- <command>`.
10
- - Filters for Git status, Git diff, test output, and generic logs.
11
- - Failures, warnings, changed paths, and command exit codes are preserved.
12
- - Omitted raw output is saved locally for recovery.
13
- - Optional per-run metrics report bytes and approximate before/after tokens.
14
- - Local SQLite statistics accumulate savings across runs.
15
- - No command output leaves the machine.
16
-
17
- ## Quick start
18
-
19
- Requires Node.js 22.13 or newer. This is the first Node 22 release where the built-in SQLite module no longer requires an experimental flag.
20
-
21
- ### One-command install (Windows PowerShell)
22
-
23
- Quick one-liner:
24
-
25
- ```powershell
26
- irm https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/install.ps1 | iex
27
- ```
28
-
29
- ### Package install from npm
30
-
31
- The installer downloads the published package from the public npm registry, then installs its local integration files.
32
-
33
- ```powershell
34
- irm https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/install.ps1 | iex
35
- ```
36
-
37
- This script installs `shrinker-ai` from `https://registry.npmjs.org` and installs Copilot/Claude rules by default.
38
-
39
- To enable automatic PowerShell routing (so `git log` routes through `shrinker`), download the script and pass the option:
40
-
41
- ```powershell
42
- $tmp = Join-Path $env:TEMP "install-shrinker.ps1"
43
- Invoke-WebRequest "https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/install.ps1" -OutFile $tmp
44
- pwsh -ExecutionPolicy Bypass -File $tmp -EnableProfileRouting
45
- ```
46
-
47
- For a local checkout, use the complete installer without profile routing:
48
-
49
- ```powershell
50
- pwsh -ExecutionPolicy Bypass -File .\integrations\install-shrinker.ps1
51
- ```
52
-
53
- This writes managed guidance blocks to:
54
-
55
- - `.copilot-instructions.md`
56
- - `CLAUDE.md`
57
-
58
- The shared guidance source is `templates/agent-rules.md`; the two files above are generated in the target project.
59
-
60
- The rules tell agents to prefer `shrinker <command>` for high-volume commands while leaving native commands untouched.
61
-
62
- ### Remote package uninstall
63
-
64
- Quick one-liner:
65
-
66
- ```powershell
67
- irm https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/uninstall.ps1 | iex
68
- ```
69
-
70
- ### Local repo install/uninstall (contributors)
71
-
72
- If you cloned this repository and want to run scripts directly from the local path:
73
-
74
- ```powershell
75
- pwsh -ExecutionPolicy Bypass -File .\integrations\install-shrinker.ps1
76
- ```
77
-
78
- To uninstall:
79
-
80
- ```powershell
81
- pwsh -ExecutionPolicy Bypass -File .\integrations\uninstall-shrinker.ps1
82
- ```
83
-
84
- Uninstall options:
85
-
86
- ```powershell
87
- # Remove only profile routing, keep shrinker command installed
88
- pwsh -ExecutionPolicy Bypass -File .\integrations\uninstall-shrinker.ps1 -SkipUnlink
89
-
90
- # Remove managed Copilot/Claude rules block only
91
- pwsh -ExecutionPolicy Bypass -File .\integrations\uninstall-shrinker.ps1 -SkipUnlink
92
- ```
93
-
94
- If your current terminal had already loaded `shrinker-profile.ps1`, restart terminal (or remove loaded wrapper functions) to fully return to native command behavior.
95
-
96
- ```powershell
97
- npm install
98
- npm run build
99
- node dist\src\cli.js exec -- git status
100
- node dist\src\cli.js exec -- git diff
101
- node dist\src\cli.js exec -- git log -n 10
102
- node dist\src\cli.js exec -- npm test
103
- Get-Content .\tests\fixtures\generic-log.txt -Raw |
104
- node dist\src\cli.js pipe --kind log
105
- ```
106
-
107
- To install the `shrinker` command locally:
108
-
109
- ```powershell
110
- npm link
111
- shrinker git status
112
- shrinker git log -n 10
113
- shrinker npm test
114
- ```
115
-
116
- ## CLI
117
-
118
- ```text
119
- shrinker <command> [args...]
120
- shrinker exec [options] [--] <command> [args...]
121
- shrinker pipe [options]
122
- shrinker stats [--json]
123
- shrinker last [--path]
124
- shrinker raw <capture-id> [--path]
125
- shrinker help
126
-
127
- --kind <auto|git-status|git-diff|git-log|test|log>
128
- --max-lines <number> default: 120
129
- --per-file-lines <number> default: 40
130
- --raw bypass filtering
131
- --metrics print per-run savings and duration
132
- --no-save do not save omitted raw output
133
- --no-stats do not record this run
134
- ```
135
-
136
- `help`, `stats`, `last`, `raw`, `pipe`, and `exec` are reserved shrinker commands. Every other top-level token starts a wrapped command, so `shrinker git log` is equivalent to `shrinker exec git log`. The `--` separator remains optional because npm's PowerShell shim may consume it. `pipe` reads existing text from stdin and defaults to the generic log filter unless `--kind` is specified.
137
-
138
- ## Automatic PowerShell routing
139
-
140
- The optional profile integration routes allowlisted commands through `shrinker` and invokes the native executable for everything else. Install it after `npm link`:
141
-
142
- ```powershell
143
- if (!(Test-Path $PROFILE)) {
144
- New-Item -ItemType File -Path $PROFILE -Force | Out-Null
145
- }
146
-
147
- $integration = (Resolve-Path .\integrations\shrinker-profile.ps1).Path
148
- Add-Content $PROFILE "`n. `"$integration`""
149
- . $PROFILE
150
- ```
151
-
152
- The default rules are:
153
-
154
- ```text
155
- git status -> shrinker git status
156
- git diff -> shrinker git diff
157
- git log -> shrinker git log
158
- npm test -> shrinker npm test
159
- docker ps -> shrinker docker ps
160
- kubectl get -> shrinker kubectl get
161
- gh pr list -> shrinker gh pr list
162
- rg/find/tail/cat/ls/dir -> shrinker <command>
163
-
164
- git push, git fetch, and all other commands -> native executable
165
- ```
166
-
167
- Edit `$global:ShrinkPowerShellRules` in `integrations\shrinker-profile.ps1` to change the allowlist. The router is now option-aware for common global flags, so forms like `git -C <path> log` and `kubectl --context prod get pods` are routed correctly.
168
-
169
- ## Savings statistics
170
-
171
- Filtered runs are recorded locally in `~/.shrinker/stats.db`. The database stores only measurements, filter kind, executable basename, duration, omission state, and exit code. It does **not** store command arguments or command output.
172
-
173
- ```powershell
174
- node dist\src\cli.js stats
175
- node dist\src\cli.js stats --json
176
- node dist\src\cli.js stats --chart
177
- node dist\src\cli.js stats --dashboard
178
- ```
179
-
180
- The summary shows all-time and last-seven-day savings plus a breakdown by filter. Use `--no-stats` before `--` to opt out for an individual run:
181
-
182
- `stats --chart` shows daily runs, estimated tokens saved, reduction percentage, and an activity bar for the last 30 days.
183
- `stats --dashboard` writes a self-contained browser dashboard to `~/.shrinker/dashboard.html` with a line chart and filter breakdown.
184
-
185
- ```powershell
186
- node dist\src\cli.js exec --no-stats -- git log -n 10
187
- ```
188
-
189
- Detailed per-run measurements are hidden by default so agents do not spend tokens reading wrapper telemetry. Enable them for benchmarking or demos:
190
-
191
- ```powershell
192
- shrinker --metrics git log -n 10
193
- ```
194
-
195
- When meaningful content is omitted, the full capture is saved under `~/.shrinker/raw` and a compact exact-recovery hint such as `[full: shrinker raw ab12cd34]` is printed instead of an absolute path. Retrieve it only when needed:
196
-
197
- ```powershell
198
- shrinker raw ab12cd34
199
- shrinker raw ab12cd34 --path
200
- shrinker last
201
- shrinker last --path
202
- ```
203
-
204
- `raw` retrieves the exact capture referenced by a hint; `last` is a convenience for human use. The cache uses atomic publication and best-effort rotation to retain up to 20 recent files. File names contain only the executable name, not command arguments. Wrapped `git log` output never creates a recovery file or hint because the full history can be reproduced by rerunning Git; piped Git-log text still gets a recovery hint when meaningful content is omitted. Use `--no-save` for other output that should not be persisted.
205
-
206
- ## Demo
207
-
208
- ```powershell
209
- npm run demo
210
- ```
211
-
212
- Current representative fixtures:
213
-
214
- | Output | Estimated token reduction |
215
- |---|---:|
216
- | Git status | 62% |
217
- | Git diff | 26% |
218
- | Git log with commit bodies | 39% |
219
- | Git log with one short commit | 69%, but only 27 estimated tokens |
220
- | Test failure | 51% |
221
- | Noisy log | 39% |
222
- | **Average** | **48%** |
223
-
224
- The token estimate uses `ceil(characters / 4)`. It is suitable for relative before/after comparisons, not billing claims. Byte counts and absolute estimated tokens saved are also reported; gains below 50 tokens are labeled as small.
225
-
226
- ## Architecture
227
-
228
- ```text
229
- command/stdin
230
- |
231
- v
232
- capture output + exit code
233
- |
234
- v
235
- select deterministic filter
236
- |
237
- +--> git status: group files by state
238
- +--> git diff: retain changed lines, drop metadata/context
239
- +--> git log: retain short hash, refs, subject, author, date,
240
- | and up to three useful body lines
241
- +--> tests: collapse passes, retain failures and summaries
242
- +--> logs: collapse progress and repeated lines
243
- |
244
- v
245
- compact output + optional metrics + meaningful-omission recovery hint
246
- ```
247
-
248
- Filters are pure functions, so the same pipeline can later sit behind a GitHub Copilot hook or MCP server without rewriting the compression logic.
249
-
250
- ## Safety and limitations
251
-
252
- - The tool does not execute through a shell. Compound shell expressions and interactive commands are out of scope.
253
- - Stdout and stderr are captured separately and presented as stdout followed by stderr; exact interleaving is not preserved.
254
- - Filtering is conservative, but any lossy transform can hide useful context. The recovery file and `--raw` are escape hatches.
255
- - Git log patch/stat/name-list flags and explicit custom formats are preserved rather than destructively reinterpreted.
256
- - Git log does not impose hidden commit limits or suppress merge commits.
257
- - This measures command-output reduction, not total Copilot usage, total conversation context, or billing.
258
- - Streaming, agent hooks, MCP, telemetry, dashboards, custom configuration, and a broad command registry are deliberately deferred.
259
-
260
- ## Validation
261
-
262
- ```powershell
263
- npm test
264
- ```
265
-
266
- Tests cover information retention, reduction targets, ANSI cleanup, filter selection, command capture, and non-zero exit-code propagation.
267
-
268
- ## Release to npm
269
-
270
- A GitHub Actions workflow publishes this CLI to npm:
271
-
272
- - Workflow file: `.github/workflows/publish-npm.yml`
273
- - Triggers:
274
- - Tag push matching `v*` (for example `v0.2.0`)
275
- - Manual run via workflow_dispatch
276
- - Pipeline steps:
277
- - `npm ci`
278
- - `npm test`
279
- - `npm publish` to `https://registry.npmjs.org`
280
-
281
- How to publish:
282
-
283
- 1. Push your changes to GitHub.
284
- 2. Push a version tag (or run the workflow manually):
285
- - `git tag v0.2.0`
286
- - `git push origin v0.2.0`
287
- 3. After the workflow succeeds, install from npm:
288
- - `npm install -g shrinker-ai`
289
-
290
- ## Suggested roadmap
291
-
292
- 1. Validate the POC with real Copilot/Agency workflows and identify the highest-volume commands.
293
- 2. Add a GitHub Copilot pre-tool hook for transparent rewriting.
294
- 3. Expose the executor and filters through MCP for other agents.
295
- 4. Add filters only when measured usage justifies them.
1
+ # shrinker
2
+
3
+ A small local CLI proof of concept that removes noise from command output before a coding agent or LLM reads it.
4
+
5
+ this POC proves that a few conservative, deterministic filters can save useful context without requiring an API key, service, UI, database, or agent-specific integration.
6
+
7
+ ## What the POC demonstrates
8
+
9
+ - Explicit cross-agent command wrapping: `shrinker exec -- <command>`.
10
+ - Filters for Git status, Git diff, test output, and generic logs.
11
+ - Failures, warnings, changed paths, and command exit codes are preserved.
12
+ - Omitted raw output is saved locally for recovery.
13
+ - Optional per-run metrics report bytes and approximate before/after tokens.
14
+ - Local SQLite statistics accumulate savings across runs.
15
+ - No command output leaves the machine.
16
+
17
+ ## Quick start
18
+
19
+ Requires Node.js 22.13 or newer. This is the first Node 22 release where the built-in SQLite module no longer requires an experimental flag.
20
+
21
+ ### One-command install (macOS zsh)
22
+
23
+ ```bash
24
+ curl -fsSL https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/macos/install.sh | bash
25
+ ```
26
+
27
+ ### One-command install (Windows PowerShell)
28
+
29
+ ```powershell
30
+ irm https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/windows/install.ps1 | iex
31
+ ```
32
+
33
+ ### Install from npm package
34
+
35
+ Windows PowerShell:
36
+
37
+ ```powershell
38
+ npm install --global shrinker-ai --registry=https://registry.npmjs.org
39
+ $pkg = Join-Path ((npm root --global).Trim()) "shrinker-ai"
40
+ pwsh -ExecutionPolicy Bypass -File (Join-Path $pkg "integrations\\windows\\install.ps1") -Local -SkipNpmInstall -SkipBuild -SkipLink
41
+ ```
42
+
43
+ To enable automatic PowerShell routing, add `-EnableProfileRouting` to the final command.
44
+
45
+ macOS zsh:
46
+
47
+ ```bash
48
+ npm install --global shrinker-ai --registry=https://registry.npmjs.org
49
+ pkg="$(npm root --global)/shrinker-ai"
50
+ bash "$pkg/integrations/macos/install.sh" --local --skip-npm-install --skip-build --skip-link --enable-profile-routing
51
+ ```
52
+
53
+ ### Install from local checkout
54
+
55
+ Windows PowerShell:
56
+
57
+ ```powershell
58
+ pwsh -ExecutionPolicy Bypass -File .\integrations\windows\install.ps1 -Local
59
+ ```
60
+
61
+ macOS zsh:
62
+
63
+ ```bash
64
+ bash ./integrations/macos/install.sh --local
65
+ ```
66
+
67
+ This writes managed guidance blocks globally to:
68
+
69
+ - `~/.copilot/copilot-instructions.md`
70
+ - `~/.claude/CLAUDE.md`
71
+
72
+ The shared guidance source is `templates/agent-rules.md`; the files above are created in the corresponding global agent directory.
73
+
74
+ The rules tell agents to prefer `shrinker <command>` for high-volume commands while leaving native commands untouched.
75
+
76
+ ### Uninstall
77
+
78
+ If you installed from npm, remove the package first:
79
+
80
+ ```bash
81
+ npm uninstall --global shrinker-ai --registry=https://registry.npmjs.org
82
+ ```
83
+
84
+ If you also installed profile/rules through the package scripts, run the matching local uninstaller from the installed package before uninstalling:
85
+
86
+ Windows PowerShell:
87
+
88
+ ```powershell
89
+ $pkg = Join-Path ((npm root --global).Trim()) "shrinker-ai"
90
+ pwsh -ExecutionPolicy Bypass -File (Join-Path $pkg "integrations\\windows\\uninstall.ps1") -SkipUnlink
91
+ ```
92
+
93
+ macOS zsh:
94
+
95
+ ```bash
96
+ pkg="$(npm root --global)/shrinker-ai"
97
+ bash "$pkg/integrations/macos/uninstall.sh" --skip-unlink
98
+ ```
99
+
100
+ macOS one-liner uninstall:
101
+
102
+ ```bash
103
+ curl -fsSL https://raw.githubusercontent.com/ivanduplenskikh/shrinker/main/integrations/macos/uninstall.sh | bash
104
+ ```
105
+
106
+ ### Local repo install/uninstall (contributors)
107
+
108
+ If you cloned this repository and want to run scripts directly from the local path:
109
+
110
+ ```powershell
111
+ pwsh -ExecutionPolicy Bypass -File .\integrations\windows\install.ps1 -Local
112
+ ```
113
+
114
+ Or on macOS:
115
+
116
+ ```bash
117
+ bash ./integrations/macos/install.sh --local
118
+ ```
119
+
120
+ To uninstall:
121
+
122
+ ```powershell
123
+ pwsh -ExecutionPolicy Bypass -File .\integrations\windows\install.ps1 -Uninstall
124
+ ```
125
+
126
+ Or on macOS:
127
+
128
+ ```bash
129
+ bash ./integrations/macos/install.sh --uninstall
130
+ ```
131
+
132
+ Uninstall options:
133
+
134
+ ```powershell
135
+ # Keep shrinker command installed, but remove profile integration and managed rules
136
+ pwsh -ExecutionPolicy Bypass -File .\integrations\windows\install.ps1 -Uninstall -SkipUnlink
137
+
138
+ # Keep managed rules files unchanged while uninstalling command/profile hooks
139
+ pwsh -ExecutionPolicy Bypass -File .\integrations\windows\install.ps1 -Uninstall -SkipAgentRules
140
+ ```
141
+
142
+ macOS uninstall options:
143
+
144
+ ```bash
145
+ # Keep shrinker command installed, but remove profile integration and managed rules
146
+ bash ./integrations/macos/install.sh --uninstall --skip-unlink
147
+
148
+ # Keep managed rules files unchanged while uninstalling command/profile hooks
149
+ bash ./integrations/macos/install.sh --uninstall --skip-agent-rules
150
+ ```
151
+
152
+ If your current terminal had already loaded `shrinker-profile.ps1` or `shrinker-profile.zsh`, restart terminal (or remove loaded wrapper functions) to fully return to native command behavior.
153
+
154
+ ```powershell
155
+ npm install
156
+ npm run build
157
+ node dist\src\cli.js exec -- git status
158
+ node dist\src\cli.js exec -- git diff
159
+ node dist\src\cli.js exec -- git log -n 10
160
+ node dist\src\cli.js exec -- npm test
161
+ Get-Content .\tests\fixtures\generic-log.txt -Raw |
162
+ node dist\src\cli.js pipe --kind log
163
+ ```
164
+
165
+ To install the `shrinker` command locally:
166
+
167
+ ```powershell
168
+ npm link
169
+ shrinker git status
170
+ shrinker git log -n 10
171
+ shrinker npm test
172
+ ```
173
+
174
+ ## CLI
175
+
176
+ ```text
177
+ shrinker <command> [args...]
178
+ shrinker exec [options] [--] <command> [args...]
179
+ shrinker pipe [options]
180
+ shrinker stats [--json]
181
+ shrinker last [--path]
182
+ shrinker raw <capture-id> [--path]
183
+ shrinker help
184
+
185
+ --kind <auto|git-status|git-diff|git-log|test|log>
186
+ --max-lines <number> default: 120
187
+ --per-file-lines <number> default: 40
188
+ --raw bypass filtering
189
+ --metrics print per-run savings and duration
190
+ --no-save do not save omitted raw output
191
+ --no-stats do not record this run
192
+ ```
193
+
194
+ `help`, `stats`, `last`, `raw`, `pipe`, and `exec` are reserved shrinker commands. Every other top-level token starts a wrapped command, so `shrinker git log` is equivalent to `shrinker exec git log`. The `--` separator remains optional because npm's PowerShell shim may consume it. `pipe` reads existing text from stdin and defaults to the generic log filter unless `--kind` is specified.
195
+
196
+ ## Automatic PowerShell routing
197
+
198
+ The optional profile integration routes allowlisted commands through `shrinker` and invokes the native executable for everything else. Install it after `npm link`:
199
+
200
+ ```powershell
201
+ if (!(Test-Path $PROFILE)) {
202
+ New-Item -ItemType File -Path $PROFILE -Force | Out-Null
203
+ }
204
+
205
+ $integration = (Resolve-Path .\integrations\windows\shrinker-profile.ps1).Path
206
+ Add-Content $PROFILE "`n. `"$integration`""
207
+ . $PROFILE
208
+ ```
209
+
210
+ macOS zsh profile integration:
211
+
212
+ ```bash
213
+ echo '' >> ~/.zshrc
214
+ echo '# >>> shrinker integration >>>' >> ~/.zshrc
215
+ echo 'source "'"$(pwd)/integrations/macos/shrinker-profile.zsh"'"' >> ~/.zshrc
216
+ echo '# <<< shrinker integration <<<' >> ~/.zshrc
217
+ source ~/.zshrc
218
+ ```
219
+
220
+ The default rules are:
221
+
222
+ ```text
223
+ git status -> shrinker git status
224
+ git diff -> shrinker git diff
225
+ git log -> shrinker git log
226
+ npm test -> shrinker npm test
227
+ docker ps -> shrinker docker ps
228
+ kubectl get -> shrinker kubectl get
229
+ gh pr list -> shrinker gh pr list
230
+ rg/find/tail/cat/ls/dir -> shrinker <command>
231
+
232
+ git push, git fetch, and all other commands -> native executable
233
+ ```
234
+
235
+ Edit `$global:ShrinkPowerShellRules` in `integrations\windows\shrinker-profile.ps1` to change the allowlist. The router is now option-aware for common global flags, so forms like `git -C <path> log` and `kubectl --context prod get pods` are routed correctly.
236
+
237
+ ## Savings statistics
238
+
239
+ Filtered runs are recorded locally in `~/.shrinker/stats.db`. The database stores only measurements, filter kind, executable basename, duration, omission state, and exit code. It does **not** store command arguments or command output.
240
+
241
+ ```powershell
242
+ node dist\src\cli.js stats
243
+ node dist\src\cli.js stats --json
244
+ node dist\src\cli.js stats --chart
245
+ node dist\src\cli.js stats --dashboard
246
+ ```
247
+
248
+ The summary shows all-time and last-seven-day savings plus a breakdown by filter. Use `--no-stats` before `--` to opt out for an individual run:
249
+
250
+ `stats --chart` shows daily runs, estimated tokens saved, reduction percentage, and an activity bar for the last 30 days.
251
+ `stats --dashboard` writes a self-contained browser dashboard to `~/.shrinker/dashboard.html` with a line chart and filter breakdown.
252
+
253
+ ```powershell
254
+ node dist\src\cli.js exec --no-stats -- git log -n 10
255
+ ```
256
+
257
+ Detailed per-run measurements are hidden by default so agents do not spend tokens reading wrapper telemetry. Enable them for benchmarking or demos:
258
+
259
+ ```powershell
260
+ shrinker --metrics git log -n 10
261
+ ```
262
+
263
+ When meaningful content is omitted, the full capture is saved under `~/.shrinker/raw` and a compact exact-recovery hint such as `[full: shrinker raw ab12cd34]` is printed instead of an absolute path. Retrieve it only when needed:
264
+
265
+ ```powershell
266
+ shrinker raw ab12cd34
267
+ shrinker raw ab12cd34 --path
268
+ shrinker last
269
+ shrinker last --path
270
+ ```
271
+
272
+ `raw` retrieves the exact capture referenced by a hint; `last` is a convenience for human use. The cache uses atomic publication and best-effort rotation to retain up to 20 recent files. File names contain only the executable name, not command arguments. Wrapped `git log` output never creates a recovery file or hint because the full history can be reproduced by rerunning Git; piped Git-log text still gets a recovery hint when meaningful content is omitted. Use `--no-save` for other output that should not be persisted.
273
+
274
+ ## Demo
275
+
276
+ ```powershell
277
+ npm run demo
278
+ ```
279
+
280
+ Current representative fixtures:
281
+
282
+ | Output | Estimated token reduction |
283
+ |---|---:|
284
+ | Git status | 62% |
285
+ | Git diff | 26% |
286
+ | Git log with commit bodies | 39% |
287
+ | Git log with one short commit | 69%, but only 27 estimated tokens |
288
+ | Test failure | 51% |
289
+ | Noisy log | 39% |
290
+ | **Average** | **48%** |
291
+
292
+ The token estimate uses `ceil(characters / 4)`. It is suitable for relative before/after comparisons, not billing claims. Byte counts and absolute estimated tokens saved are also reported; gains below 50 tokens are labeled as small.
293
+
294
+ ## Architecture
295
+
296
+ ```text
297
+ command/stdin
298
+ |
299
+ v
300
+ capture output + exit code
301
+ |
302
+ v
303
+ select deterministic filter
304
+ |
305
+ +--> git status: group files by state
306
+ +--> git diff: retain changed lines, drop metadata/context
307
+ +--> git log: retain short hash, refs, subject, author, date,
308
+ | and up to three useful body lines
309
+ +--> tests: collapse passes, retain failures and summaries
310
+ +--> logs: collapse progress and repeated lines
311
+ |
312
+ v
313
+ compact output + optional metrics + meaningful-omission recovery hint
314
+ ```
315
+
316
+ Filters are pure functions, so the same pipeline can later sit behind a GitHub Copilot hook or MCP server without rewriting the compression logic.
317
+
318
+ ## Safety and limitations
319
+
320
+ - The tool does not execute through a shell. Compound shell expressions and interactive commands are out of scope.
321
+ - Stdout and stderr are captured separately and presented as stdout followed by stderr; exact interleaving is not preserved.
322
+ - Filtering is conservative, but any lossy transform can hide useful context. The recovery file and `--raw` are escape hatches.
323
+ - Git log patch/stat/name-list flags and explicit custom formats are preserved rather than destructively reinterpreted.
324
+ - Git log does not impose hidden commit limits or suppress merge commits.
325
+ - This measures command-output reduction, not total Copilot usage, total conversation context, or billing.
326
+ - Streaming, agent hooks, MCP, telemetry, dashboards, custom configuration, and a broad command registry are deliberately deferred.
327
+
328
+ ## Validation
329
+
330
+ ```powershell
331
+ npm test
332
+ ```
333
+
334
+ Tests cover information retention, reduction targets, ANSI cleanup, filter selection, command capture, and non-zero exit-code propagation.
335
+
336
+ ## Release to npm
337
+
338
+ A GitHub Actions workflow publishes this CLI to npm:
339
+
340
+ - Workflow file: `.github/workflows/publish-npm.yml`
341
+ - Triggers:
342
+ - Tag push matching `v*` (for example `v0.2.0`)
343
+ - Manual run via workflow_dispatch
344
+ - Pipeline steps:
345
+ - `npm ci`
346
+ - `npm test`
347
+ - `npm publish` to `https://registry.npmjs.org`
348
+
349
+ How to publish:
350
+
351
+ 1. Push your changes to GitHub.
352
+ 2. Push a version tag (or run the workflow manually):
353
+ - `git tag v0.2.0`
354
+ - `git push origin v0.2.0`
355
+ 3. After the workflow succeeds, install from npm:
356
+ - `npm install -g shrinker-ai`
357
+
358
+ ## Suggested roadmap
359
+
360
+ 1. Validate the POC with real Copilot/Agency workflows and identify the highest-volume commands.
361
+ 2. Add a GitHub Copilot pre-tool hook for transparent rewriting.
362
+ 3. Expose the executor and filters through MCP for other agents.
363
+ 4. Add filters only when measured usage justifies them.