shrinker-ai 0.3.3 → 0.4.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 +449 -363
- package/dist/src/cli.js +144 -25
- package/dist/src/config.js +42 -0
- package/dist/src/execution/run-command.js +2 -2
- package/dist/src/filters/select-filter.js +26 -18
- package/dist/src/metrics/coverage.js +67 -0
- package/dist/src/metrics/dashboard-template.generated.js +4 -0
- package/dist/src/metrics/dashboard.js +131 -116
- package/dist/src/metrics/stats-store.js +211 -51
- package/integrations/macos/install.sh +54 -1
- package/integrations/macos/shrinker-profile.zsh +165 -98
- package/integrations/macos/uninstall.sh +50 -0
- package/integrations/windows/install.ps1 +161 -113
- package/integrations/windows/shrinker-profile.ps1 +206 -136
- package/integrations/windows/uninstall.ps1 +101 -57
- package/package.json +46 -39
- package/templates/agent-rules.md +18 -18
- package/.copilot-instructions.md +0 -28
- package/CLAUDE.md +0 -28
package/README.md
CHANGED
|
@@ -1,363 +1,449 @@
|
|
|
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
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
--
|
|
187
|
-
--
|
|
188
|
-
--
|
|
189
|
-
--
|
|
190
|
-
--
|
|
191
|
-
--no-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
echo '
|
|
216
|
-
echo '#
|
|
217
|
-
source ~/.zshrc
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
git
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
node dist\src\cli.js stats
|
|
245
|
-
node dist\src\cli.js stats --
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
The
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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 (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 track --executable <name> [--subcommand <name>] [--bytes <number>] [--exit-code <number>]
|
|
184
|
+
shrinker help
|
|
185
|
+
|
|
186
|
+
--kind <auto|git-status|git-diff|git-log|test|log>
|
|
187
|
+
--max-lines <number> default: 120
|
|
188
|
+
--per-file-lines <number> default: 40
|
|
189
|
+
--raw bypass filtering
|
|
190
|
+
--metrics print per-run savings and duration
|
|
191
|
+
--no-save do not save omitted raw output
|
|
192
|
+
--no-stats do not record this run
|
|
193
|
+
--coverage list commands shrinker does not cover yet
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`help`, `stats`, `last`, `raw`, `track`, `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. `track` is used by the shell integrations to record coverage gaps and prints nothing.
|
|
197
|
+
|
|
198
|
+
## Automatic PowerShell routing
|
|
199
|
+
|
|
200
|
+
The optional profile integration routes allowlisted commands through `shrinker` and invokes the native executable for everything else. Install it after `npm link`:
|
|
201
|
+
|
|
202
|
+
```powershell
|
|
203
|
+
if (!(Test-Path $PROFILE)) {
|
|
204
|
+
New-Item -ItemType File -Path $PROFILE -Force | Out-Null
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
$integration = (Resolve-Path .\integrations\windows\shrinker-profile.ps1).Path
|
|
208
|
+
Add-Content $PROFILE "`n. `"$integration`""
|
|
209
|
+
. $PROFILE
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
macOS zsh profile integration:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
echo '' >> ~/.zshrc
|
|
216
|
+
echo '# >>> shrinker integration >>>' >> ~/.zshrc
|
|
217
|
+
echo 'source "'"$(pwd)/integrations/macos/shrinker-profile.zsh"'"' >> ~/.zshrc
|
|
218
|
+
echo '# <<< shrinker integration <<<' >> ~/.zshrc
|
|
219
|
+
source ~/.zshrc
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The default rules are:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
git status -> shrinker git status
|
|
226
|
+
git diff -> shrinker git diff
|
|
227
|
+
git log -> shrinker git log
|
|
228
|
+
npm test -> shrinker npm test
|
|
229
|
+
docker ps -> shrinker docker ps
|
|
230
|
+
kubectl get -> shrinker kubectl get
|
|
231
|
+
gh pr list -> shrinker gh pr list
|
|
232
|
+
rg/find/tail/cat/ls/dir -> shrinker <command>
|
|
233
|
+
|
|
234
|
+
git push, git fetch, and all other commands -> native executable
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
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.
|
|
238
|
+
|
|
239
|
+
## Savings statistics
|
|
240
|
+
|
|
241
|
+
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.
|
|
242
|
+
|
|
243
|
+
```powershell
|
|
244
|
+
node dist\src\cli.js stats
|
|
245
|
+
node dist\src\cli.js stats --json
|
|
246
|
+
node dist\src\cli.js stats --chart
|
|
247
|
+
node dist\src\cli.js stats --dashboard
|
|
248
|
+
node dist\src\cli.js stats --dashboard --port 4318
|
|
249
|
+
node dist\src\cli.js stats --dashboard --restart
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
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:
|
|
253
|
+
|
|
254
|
+
`stats --coverage` lists commands shrinker does not cover yet; see [Coverage gaps](#coverage-gaps).
|
|
255
|
+
`stats --chart` shows daily runs, estimated tokens saved, reduction percentage, and an activity bar for the last 30 days.
|
|
256
|
+
`stats --dashboard` starts the local dashboard server in the background at `http://127.0.0.1:4317` and opens it in your browser, then returns to the terminal. The page reads the latest local stats whenever it is refreshed; use `--port` to choose another port. The same command also refreshes the standalone copy at `~/.shrinker/dashboard.html`, which can be opened directly without a server running.
|
|
257
|
+
|
|
258
|
+
Use `stats --dashboard --restart` after rebuilding to replace an already-running dashboard server with the current code.
|
|
259
|
+
|
|
260
|
+
The dashboard estimates input API cost saved from the recorded token savings. Set the input price directly in the dashboard; it is retained in that browser. It defaults to `$5.00` per million input tokens, or `SHRINKER_INPUT_COST_PER_MILLION_TOKENS` when set before starting the dashboard:
|
|
261
|
+
|
|
262
|
+
```powershell
|
|
263
|
+
$env:SHRINKER_INPUT_COST_PER_MILLION_TOKENS = "2.50"
|
|
264
|
+
shrinker stats --dashboard
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
```powershell
|
|
268
|
+
node dist\src\cli.js exec --no-stats -- git log -n 10
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Detailed per-run measurements are hidden by default so agents do not spend tokens reading wrapper telemetry. Enable them for benchmarking or demos:
|
|
272
|
+
|
|
273
|
+
```powershell
|
|
274
|
+
shrinker --metrics git log -n 10
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
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:
|
|
278
|
+
|
|
279
|
+
```powershell
|
|
280
|
+
shrinker raw ab12cd34
|
|
281
|
+
shrinker raw ab12cd34 --path
|
|
282
|
+
shrinker last
|
|
283
|
+
shrinker last --path
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`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.
|
|
287
|
+
|
|
288
|
+
## Coverage gaps
|
|
289
|
+
|
|
290
|
+
Shrinker only measures what it filters. Coverage tracking answers the opposite question: **which commands does an agent run that shrinker does not cover yet?** It ranks them by the estimated tokens a dedicated filter could have seen, so the top row is the next filter worth writing.
|
|
291
|
+
|
|
292
|
+
The installer asks whether to enable it and stores the answer in `~/.shrinker/config`:
|
|
293
|
+
|
|
294
|
+
```text
|
|
295
|
+
SHRINKER_TRACK_UNCOVERED=1
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Pass `--enable-uncovered-tracking` / `--disable-uncovered-tracking` (macOS) or `-EnableUncoveredTracking` / `-DisableUncoveredTracking` (Windows) to answer ahead of time. Non-interactive installs skip the prompt and enable tracking.
|
|
299
|
+
|
|
300
|
+
The environment variable still wins for a single shell or command, in either direction:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
SHRINKER_TRACK_UNCOVERED=0 shrinker git status # off for one command
|
|
304
|
+
export SHRINKER_TRACK_UNCOVERED=1 # on for this shell
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
```powershell
|
|
308
|
+
$env:SHRINKER_TRACK_UNCOVERED = "1"
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Both the CLI and the shell integration read `~/.shrinker/config`; the shell profile reads it once at load, so change it and restart the shell (or export the variable) to take effect immediately. Set `SHRINKER_CONFIG_PATH` to relocate the file.
|
|
312
|
+
|
|
313
|
+
Two kinds of gaps are recorded:
|
|
314
|
+
|
|
315
|
+
- `no-filter` / `low-reduction` — the command ran through shrinker, but no filter matched it, or the matching filter barely reduced the output.
|
|
316
|
+
- `unlisted-subcommand` — the shell integration shadows the executable, but the subcommand is outside the routing allowlist, so the native binary ran instead (`git blame`, `docker inspect`, `npm run build`).
|
|
317
|
+
|
|
318
|
+
Read the results with:
|
|
319
|
+
|
|
320
|
+
```powershell
|
|
321
|
+
shrinker stats --coverage
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
Ranked by estimated tokens a dedicated filter could see:
|
|
326
|
+
Command Runs Est. tokens Avg Reason Source Last seen
|
|
327
|
+
------------------------- ---------- ----------- ---------- --------------------- --------------- -------------------
|
|
328
|
+
docker inspect 12 runs 148,204 12,350 unlisted-subcommand shell 2025-05-14 09:22:41
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
The same data is included in `stats --json` and appears as a "Coverage gaps" panel in the dashboard.
|
|
332
|
+
|
|
333
|
+
**What is stored:** the executable name and its subcommand only, plus an occurrence count, output size, and exit code — for example `docker inspect`. Command arguments, flag values, paths, and command output are never stored. Tokens that are not bare command names are dropped rather than written, so a misfiring hook cannot leak a path or secret into the database. Everything stays in `~/.shrinker/stats.db` on this machine; nothing is uploaded.
|
|
334
|
+
|
|
335
|
+
Runs with small outputs (under ~200 estimated tokens) are ignored so the table stays focused on real savings. Adjust the low-reduction threshold with `SHRINKER_LOW_REDUCTION_PERCENT` (default `10`).
|
|
336
|
+
|
|
337
|
+
Output volume is measured in the shell integration only when stdout is redirected — which is the agent case. Interactive terminal sessions run the native command completely untouched and are recorded with a size of zero, so pagers, colours, and prompts still behave normally.
|
|
338
|
+
|
|
339
|
+
## Demo
|
|
340
|
+
|
|
341
|
+
```powershell
|
|
342
|
+
npm run demo
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Current representative fixtures:
|
|
346
|
+
|
|
347
|
+
| Output | Estimated token reduction |
|
|
348
|
+
|---|---:|
|
|
349
|
+
| Git status | 62% |
|
|
350
|
+
| Git diff | 26% |
|
|
351
|
+
| Git log with commit bodies | 39% |
|
|
352
|
+
| Git log with one short commit | 69%, but only 27 estimated tokens |
|
|
353
|
+
| Test failure | 51% |
|
|
354
|
+
| Noisy log | 39% |
|
|
355
|
+
| **Average** | **48%** |
|
|
356
|
+
|
|
357
|
+
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.
|
|
358
|
+
|
|
359
|
+
## Architecture
|
|
360
|
+
|
|
361
|
+
```text
|
|
362
|
+
command/stdin
|
|
363
|
+
|
|
|
364
|
+
v
|
|
365
|
+
capture output + exit code
|
|
366
|
+
|
|
|
367
|
+
v
|
|
368
|
+
select deterministic filter
|
|
369
|
+
|
|
|
370
|
+
+--> git status: group files by state
|
|
371
|
+
+--> git diff: retain changed lines, drop metadata/context
|
|
372
|
+
+--> git log: retain short hash, refs, subject, author, date,
|
|
373
|
+
| and up to three useful body lines
|
|
374
|
+
+--> tests: collapse passes, retain failures and summaries
|
|
375
|
+
+--> logs: collapse progress and repeated lines
|
|
376
|
+
|
|
|
377
|
+
v
|
|
378
|
+
compact output + optional metrics + meaningful-omission recovery hint
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Filters are pure functions, so the same pipeline can later sit behind a GitHub Copilot hook or MCP server without rewriting the compression logic.
|
|
382
|
+
|
|
383
|
+
### Workspace layout
|
|
384
|
+
|
|
385
|
+
The repository is an npm workspace. The CLI lives at the root; the stats dashboard is a separate React + HeroUI app.
|
|
386
|
+
|
|
387
|
+
```text
|
|
388
|
+
.
|
|
389
|
+
├── src/ CLI (TypeScript, ESM, zero runtime dependencies)
|
|
390
|
+
├── tests/ node:test suites
|
|
391
|
+
└── packages/dashboard-ui/ React + HeroUI dashboard, bundled by Vite
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
`packages/dashboard-ui` builds to a single self-contained HTML file (`vite-plugin-singlefile`), which `scripts/emit-template.mjs` then bakes into `src/metrics/dashboard-template.generated.ts`. The CLI injects the current `StatsSummary` into that template as an embedded JSON blob, so the published package still has no runtime dependencies and the dashboard works from `file://` with no server.
|
|
395
|
+
|
|
396
|
+
| Command | Purpose |
|
|
397
|
+
| --- | --- |
|
|
398
|
+
| `npm run dev:ui` | Vite dev server with hot reload (renders empty-state data) |
|
|
399
|
+
| `npm run build:ui` | Build the dashboard and regenerate the baked template |
|
|
400
|
+
| `npm run build` | `build:ui`, then `tsc` |
|
|
401
|
+
|
|
402
|
+
`npm run build:ui` is a prerequisite for `tsc`, because the generated template module is a compiled source file. `npm run build`, `npm test`, `npm run demo`, and `npm run pack` all chain it automatically.
|
|
403
|
+
|
|
404
|
+
## Safety and limitations
|
|
405
|
+
|
|
406
|
+
- The tool does not execute through a shell. Compound shell expressions and interactive commands are out of scope.
|
|
407
|
+
- Stdout and stderr are captured separately and presented as stdout followed by stderr; exact interleaving is not preserved.
|
|
408
|
+
- Filtering is conservative, but any lossy transform can hide useful context. The recovery file and `--raw` are escape hatches.
|
|
409
|
+
- Git log patch/stat/name-list flags and explicit custom formats are preserved rather than destructively reinterpreted.
|
|
410
|
+
- Git log does not impose hidden commit limits or suppress merge commits.
|
|
411
|
+
- This measures command-output reduction, not total Copilot usage, total conversation context, or billing.
|
|
412
|
+
- Streaming, agent hooks, MCP, telemetry, dashboards, custom configuration, and a broad command registry are deliberately deferred.
|
|
413
|
+
|
|
414
|
+
## Validation
|
|
415
|
+
|
|
416
|
+
```powershell
|
|
417
|
+
npm test
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Tests cover information retention, reduction targets, ANSI cleanup, filter selection, command capture, and non-zero exit-code propagation.
|
|
421
|
+
|
|
422
|
+
## Release to npm
|
|
423
|
+
|
|
424
|
+
A GitHub Actions workflow publishes this CLI to npm:
|
|
425
|
+
|
|
426
|
+
- Workflow file: `.github/workflows/publish-npm.yml`
|
|
427
|
+
- Triggers:
|
|
428
|
+
- Tag push matching `v*` (for example `v0.2.0`)
|
|
429
|
+
- Manual run via workflow_dispatch
|
|
430
|
+
- Pipeline steps:
|
|
431
|
+
- `npm ci`
|
|
432
|
+
- `npm test`
|
|
433
|
+
- `npm publish` to `https://registry.npmjs.org`
|
|
434
|
+
|
|
435
|
+
How to publish:
|
|
436
|
+
|
|
437
|
+
1. Push your changes to GitHub.
|
|
438
|
+
2. Push a version tag (or run the workflow manually):
|
|
439
|
+
- `git tag v0.2.0`
|
|
440
|
+
- `git push origin v0.2.0`
|
|
441
|
+
3. After the workflow succeeds, install from npm:
|
|
442
|
+
- `npm install -g shrinker-ai`
|
|
443
|
+
|
|
444
|
+
## Suggested roadmap
|
|
445
|
+
|
|
446
|
+
1. Validate the POC with real Copilot/Agency workflows and identify the highest-volume commands.
|
|
447
|
+
2. Add a GitHub Copilot pre-tool hook for transparent rewriting.
|
|
448
|
+
3. Expose the executor and filters through MCP for other agents.
|
|
449
|
+
4. Add filters only when measured usage justifies them.
|