pi-rtk-optimizer 0.3.3 → 0.5.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/CHANGELOG.md +102 -67
- package/README.md +292 -290
- package/config/config.example.json +36 -35
- package/package.json +4 -4
- package/src/additional-coverage-test.ts +278 -0
- package/src/boolean-format.ts +3 -0
- package/src/command-rewriter-test.ts +160 -120
- package/src/command-rewriter.ts +594 -585
- package/src/config-modal-test.ts +168 -0
- package/src/config-modal.ts +613 -600
- package/src/config-store.ts +224 -217
- package/src/index-test.ts +54 -0
- package/src/index.ts +410 -289
- package/src/output-compactor-test.ts +500 -158
- package/src/output-compactor.ts +432 -349
- package/src/record-utils.ts +6 -0
- package/src/rewrite-bypass.ts +332 -173
- package/src/rewrite-pipeline-safety.ts +154 -0
- package/src/rewrite-rules.ts +255 -255
- package/src/rtk-command-environment.ts +64 -0
- package/src/runtime-guard-test.ts +42 -50
- package/src/runtime-guard.ts +14 -14
- package/src/techniques/build.ts +155 -155
- package/src/techniques/emoji.ts +91 -0
- package/src/techniques/git.ts +231 -229
- package/src/techniques/index.ts +10 -16
- package/src/techniques/linter.ts +151 -161
- package/src/techniques/path-utils.ts +67 -0
- package/src/techniques/rtk.ts +136 -0
- package/src/techniques/search.ts +67 -76
- package/src/techniques/source.ts +253 -253
- package/src/techniques/test-output.ts +172 -172
- package/src/test-helpers.ts +10 -0
- package/src/tool-execution-sanitizer.ts +69 -0
- package/src/types-shims.d.ts +192 -183
- package/src/types.ts +103 -114
- package/src/zellij-modal.ts +1001 -1001
- package/src/compat-commands.ts +0 -207
package/README.md
CHANGED
|
@@ -1,290 +1,292 @@
|
|
|
1
|
-
# pi-rtk-optimizer
|
|
2
|
-
|
|
3
|
-
> RTK command rewriting and tool output compaction extension for the Pi coding agent.
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
**pi-rtk-optimizer** automatically rewrites `bash` tool commands to their `rtk` equivalents and compacts noisy tool output (`bash`, `read`, `grep`) to reduce context window usage while preserving actionable information for the AI agent.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
### Command Rewriting
|
|
12
|
-
|
|
13
|
-
- **Automatic rewriting** or **suggestion-only** mode for common development workflows
|
|
14
|
-
- Supported command categories:
|
|
15
|
-
- **Git/GitHub** — `git`, `gh` commands
|
|
16
|
-
- **Filesystem** — `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc`, `bash`, `cmd`, `powershell`
|
|
17
|
-
- **Rust** — `cargo` commands
|
|
18
|
-
- **JavaScript** — `vitest`, `npm`, `yarn`, `pnpm`, `bun` commands
|
|
19
|
-
- **Python** — `pytest`, `python`, `pip`, `uv` commands
|
|
20
|
-
- **Go** — `go` commands
|
|
21
|
-
- **Containers** — `docker`, `docker-compose`, `podman` commands
|
|
22
|
-
- **Network** — `curl`, `wget` commands
|
|
23
|
-
- **Package Managers** — `apt`, `brew`, `dnf`, `pacman`, `yum` commands
|
|
24
|
-
- Runtime guard when `rtk` binary is unavailable (falls back to original commands only in rewrite mode)
|
|
25
|
-
- Safe rewrite bypasses for structured `gh` output commands and non-interactive container shell sessions
|
|
26
|
-
- Improved command parsing for `sed`, shell separators, and `pnpm dlx` proxy rewrites
|
|
27
|
-
|
|
28
|
-
### Output Compaction Pipeline
|
|
29
|
-
|
|
30
|
-
Multi-stage pipeline to reduce token consumption:
|
|
31
|
-
|
|
32
|
-
| Stage | Description |
|
|
33
|
-
|-------|-------------|
|
|
34
|
-
| ANSI Stripping | Removes terminal color/formatting codes |
|
|
35
|
-
| Test Aggregation | Summarizes test runner output (pass/fail counts) |
|
|
36
|
-
| Build Filtering | Extracts errors/warnings from build output |
|
|
37
|
-
| Git Compaction | Condenses `git status`, `git log`, `git diff` output |
|
|
38
|
-
| Linter Aggregation | Summarizes linting tool output |
|
|
39
|
-
| Search Grouping | Groups `grep`/`rg` results by file |
|
|
40
|
-
| Source Code Filtering | `none`, `minimal`, or `aggressive` comment/whitespace removal with userscript metadata preservation |
|
|
41
|
-
| Smart Truncation | Preserves file boundaries and important lines while keeping 80-line reads exact |
|
|
42
|
-
| Hard Truncation | Final character limit enforcement |
|
|
43
|
-
|
|
44
|
-
### Interactive Settings
|
|
45
|
-
|
|
46
|
-
- TUI settings modal via `/rtk` command
|
|
47
|
-
- Real-time configuration changes without restart
|
|
48
|
-
- Command completions for all subcommands
|
|
49
|
-
|
|
50
|
-
### Session Metrics
|
|
51
|
-
|
|
52
|
-
- Tracks compaction savings per tool type
|
|
53
|
-
- View statistics with `/rtk stats`
|
|
54
|
-
|
|
55
|
-
## Installation
|
|
56
|
-
|
|
57
|
-
### Local Extension Folder
|
|
58
|
-
|
|
59
|
-
Place this folder in one of the following locations:
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
~/.pi/agent/extensions/pi-rtk-optimizer # Global (all projects)
|
|
63
|
-
.pi/extensions/pi-rtk-optimizer # Project-specific
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Pi auto-discovers extensions in these paths on startup.
|
|
67
|
-
|
|
68
|
-
### npm Package
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
pi install npm:pi-rtk-optimizer
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Git Repository
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
pi install git:github.com/MasuRii/pi-rtk-optimizer
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Usage
|
|
81
|
-
|
|
82
|
-
### Settings Modal
|
|
83
|
-
|
|
84
|
-
Open the interactive settings modal:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
/rtk
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Use arrow keys to navigate settings, Enter to cycle values, and Escape to close.
|
|
91
|
-
|
|
92
|
-
### Subcommands
|
|
93
|
-
|
|
94
|
-
| Command | Description |
|
|
95
|
-
|---------|-------------|
|
|
96
|
-
| `/rtk` | Open settings modal |
|
|
97
|
-
| `/rtk show` | Display current configuration and runtime status |
|
|
98
|
-
| `/rtk path` | Show config file path |
|
|
99
|
-
| `/rtk verify` | Check if `rtk` binary is available |
|
|
100
|
-
| `/rtk stats` | Show output compaction metrics for current session |
|
|
101
|
-
| `/rtk clear-stats` | Reset compaction metrics |
|
|
102
|
-
| `/rtk reset` | Reset all settings to defaults |
|
|
103
|
-
| `/rtk help` | Display usage help |
|
|
104
|
-
|
|
105
|
-
## Configuration
|
|
106
|
-
|
|
107
|
-
Configuration is stored at:
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
~/.pi/agent/extensions/pi-rtk-optimizer/config.json
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
A starter template is included at `config/config.example.json`.
|
|
114
|
-
|
|
115
|
-
### Configuration Options
|
|
116
|
-
|
|
117
|
-
#### Top-Level Settings
|
|
118
|
-
|
|
119
|
-
| Option | Type | Default | Description |
|
|
120
|
-
|--------|------|---------|-------------|
|
|
121
|
-
| `enabled` | boolean | `true` | Master switch for all extension features |
|
|
122
|
-
| `mode` | string | `"rewrite"` | `"rewrite"` (auto-rewrite) or `"suggest"` (notify only) |
|
|
123
|
-
| `guardWhenRtkMissing` | boolean | `true` | Run original commands when rtk binary unavailable |
|
|
124
|
-
| `showRewriteNotifications` | boolean | `true` | Show rewrite notices in TUI |
|
|
125
|
-
|
|
126
|
-
#### Rewrite Category Toggles
|
|
127
|
-
|
|
128
|
-
| Option | Default | Commands Affected |
|
|
129
|
-
|--------|---------|-------------------|
|
|
130
|
-
| `rewriteGitGithub` | `true` | `git`, `gh` |
|
|
131
|
-
| `rewriteFilesystem` | `true` | `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc` |
|
|
132
|
-
| `rewriteRust` | `true` | `cargo` |
|
|
133
|
-
| `rewriteJavaScript` | `true` | `vitest`, `npm`, `yarn`, `pnpm`, `bun` |
|
|
134
|
-
| `rewritePython` | `true` | `pytest`, `python`, `pip`, `uv` |
|
|
135
|
-
| `rewriteGo` | `true` | `go` |
|
|
136
|
-
| `rewriteContainers` | `true` | `docker`, `docker-compose`, `podman` |
|
|
137
|
-
| `rewriteNetwork` | `true` | `curl`, `wget` |
|
|
138
|
-
| `rewritePackageManagers` | `true` | `apt`, `brew`, `dnf`, `pacman`, `yum` |
|
|
139
|
-
|
|
140
|
-
#### Output Compaction Settings
|
|
141
|
-
|
|
142
|
-
| Option | Type | Default | Description |
|
|
143
|
-
|--------|------|---------|-------------|
|
|
144
|
-
| `outputCompaction.enabled` | boolean | `true` | Enable output compaction pipeline |
|
|
145
|
-
| `outputCompaction.stripAnsi` | boolean | `true` | Remove ANSI escape codes |
|
|
146
|
-
| `outputCompaction.sourceCodeFilteringEnabled` | boolean | `true` | Enable source code filtering for `read` output |
|
|
147
|
-
| `outputCompaction.
|
|
148
|
-
| `outputCompaction.
|
|
149
|
-
| `outputCompaction.
|
|
150
|
-
| `outputCompaction.
|
|
151
|
-
| `outputCompaction.
|
|
152
|
-
| `outputCompaction.
|
|
153
|
-
| `outputCompaction.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
| `outputCompaction.smartTruncate.
|
|
161
|
-
| `outputCompaction.
|
|
162
|
-
| `outputCompaction.truncate.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
190
|
-
"
|
|
191
|
-
"
|
|
192
|
-
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
"
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
├──
|
|
224
|
-
├──
|
|
225
|
-
├──
|
|
226
|
-
├──
|
|
227
|
-
├──
|
|
228
|
-
├──
|
|
229
|
-
├──
|
|
230
|
-
├──
|
|
231
|
-
├──
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
├──
|
|
236
|
-
├──
|
|
237
|
-
├──
|
|
238
|
-
├──
|
|
239
|
-
├──
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
1
|
+
# pi-rtk-optimizer
|
|
2
|
+
|
|
3
|
+
> RTK command rewriting and tool output compaction extension for the Pi coding agent.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**pi-rtk-optimizer** automatically rewrites `bash` tool commands to their `rtk` equivalents and compacts noisy tool output (`bash`, `read`, `grep`) to reduce context window usage while preserving actionable information for the AI agent.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
### Command Rewriting
|
|
12
|
+
|
|
13
|
+
- **Automatic rewriting** or **suggestion-only** mode for common development workflows
|
|
14
|
+
- Supported command categories:
|
|
15
|
+
- **Git/GitHub** — `git`, `gh` commands
|
|
16
|
+
- **Filesystem** — `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc`, `bash`, `cmd`, `powershell`
|
|
17
|
+
- **Rust** — `cargo` commands
|
|
18
|
+
- **JavaScript** — `vitest`, `npm`, `yarn`, `pnpm`, `bun` commands
|
|
19
|
+
- **Python** — `pytest`, `python`, `pip`, `uv` commands
|
|
20
|
+
- **Go** — `go` commands
|
|
21
|
+
- **Containers** — `docker`, `docker-compose`, `podman` commands
|
|
22
|
+
- **Network** — `curl`, `wget` commands
|
|
23
|
+
- **Package Managers** — `apt`, `brew`, `dnf`, `pacman`, `yum` commands
|
|
24
|
+
- Runtime guard when `rtk` binary is unavailable (falls back to original commands only in rewrite mode)
|
|
25
|
+
- Safe rewrite bypasses for structured `gh` output commands and non-interactive container shell sessions
|
|
26
|
+
- Improved command parsing for `sed`, shell separators, and `pnpm dlx` proxy rewrites
|
|
27
|
+
|
|
28
|
+
### Output Compaction Pipeline
|
|
29
|
+
|
|
30
|
+
Multi-stage pipeline to reduce token consumption:
|
|
31
|
+
|
|
32
|
+
| Stage | Description |
|
|
33
|
+
|-------|-------------|
|
|
34
|
+
| ANSI Stripping | Removes terminal color/formatting codes |
|
|
35
|
+
| Test Aggregation | Summarizes test runner output (pass/fail counts) |
|
|
36
|
+
| Build Filtering | Extracts errors/warnings from build output |
|
|
37
|
+
| Git Compaction | Condenses `git status`, `git log`, `git diff` output |
|
|
38
|
+
| Linter Aggregation | Summarizes linting tool output |
|
|
39
|
+
| Search Grouping | Groups `grep`/`rg` results by file |
|
|
40
|
+
| Source Code Filtering | `none`, `minimal`, or `aggressive` comment/whitespace removal with userscript metadata preservation |
|
|
41
|
+
| Smart Truncation | Preserves file boundaries and important lines while keeping 80-line reads exact |
|
|
42
|
+
| Hard Truncation | Final character limit enforcement |
|
|
43
|
+
|
|
44
|
+
### Interactive Settings
|
|
45
|
+
|
|
46
|
+
- TUI settings modal via `/rtk` command
|
|
47
|
+
- Real-time configuration changes without restart
|
|
48
|
+
- Command completions for all subcommands
|
|
49
|
+
|
|
50
|
+
### Session Metrics
|
|
51
|
+
|
|
52
|
+
- Tracks compaction savings per tool type
|
|
53
|
+
- View statistics with `/rtk stats`
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
### Local Extension Folder
|
|
58
|
+
|
|
59
|
+
Place this folder in one of the following locations:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
~/.pi/agent/extensions/pi-rtk-optimizer # Global (all projects)
|
|
63
|
+
.pi/extensions/pi-rtk-optimizer # Project-specific
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pi auto-discovers extensions in these paths on startup.
|
|
67
|
+
|
|
68
|
+
### npm Package
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pi install npm:pi-rtk-optimizer
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Git Repository
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pi install git:github.com/MasuRii/pi-rtk-optimizer
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Usage
|
|
81
|
+
|
|
82
|
+
### Settings Modal
|
|
83
|
+
|
|
84
|
+
Open the interactive settings modal:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
/rtk
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Use arrow keys to navigate settings, Enter to cycle values, and Escape to close.
|
|
91
|
+
|
|
92
|
+
### Subcommands
|
|
93
|
+
|
|
94
|
+
| Command | Description |
|
|
95
|
+
|---------|-------------|
|
|
96
|
+
| `/rtk` | Open settings modal |
|
|
97
|
+
| `/rtk show` | Display current configuration and runtime status |
|
|
98
|
+
| `/rtk path` | Show config file path |
|
|
99
|
+
| `/rtk verify` | Check if `rtk` binary is available |
|
|
100
|
+
| `/rtk stats` | Show output compaction metrics for current session |
|
|
101
|
+
| `/rtk clear-stats` | Reset compaction metrics |
|
|
102
|
+
| `/rtk reset` | Reset all settings to defaults |
|
|
103
|
+
| `/rtk help` | Display usage help |
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
Configuration is stored at:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
~/.pi/agent/extensions/pi-rtk-optimizer/config.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A starter template is included at `config/config.example.json`.
|
|
114
|
+
|
|
115
|
+
### Configuration Options
|
|
116
|
+
|
|
117
|
+
#### Top-Level Settings
|
|
118
|
+
|
|
119
|
+
| Option | Type | Default | Description |
|
|
120
|
+
|--------|------|---------|-------------|
|
|
121
|
+
| `enabled` | boolean | `true` | Master switch for all extension features |
|
|
122
|
+
| `mode` | string | `"rewrite"` | `"rewrite"` (auto-rewrite) or `"suggest"` (notify only) |
|
|
123
|
+
| `guardWhenRtkMissing` | boolean | `true` | Run original commands when rtk binary unavailable |
|
|
124
|
+
| `showRewriteNotifications` | boolean | `true` | Show rewrite notices in TUI |
|
|
125
|
+
|
|
126
|
+
#### Rewrite Category Toggles
|
|
127
|
+
|
|
128
|
+
| Option | Default | Commands Affected |
|
|
129
|
+
|--------|---------|-------------------|
|
|
130
|
+
| `rewriteGitGithub` | `true` | `git`, `gh` |
|
|
131
|
+
| `rewriteFilesystem` | `true` | `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc` |
|
|
132
|
+
| `rewriteRust` | `true` | `cargo` |
|
|
133
|
+
| `rewriteJavaScript` | `true` | `vitest`, `npm`, `yarn`, `pnpm`, `bun` |
|
|
134
|
+
| `rewritePython` | `true` | `pytest`, `python`, `pip`, `uv` |
|
|
135
|
+
| `rewriteGo` | `true` | `go` |
|
|
136
|
+
| `rewriteContainers` | `true` | `docker`, `docker-compose`, `podman` |
|
|
137
|
+
| `rewriteNetwork` | `true` | `curl`, `wget` |
|
|
138
|
+
| `rewritePackageManagers` | `true` | `apt`, `brew`, `dnf`, `pacman`, `yum` |
|
|
139
|
+
|
|
140
|
+
#### Output Compaction Settings
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Description |
|
|
143
|
+
|--------|------|---------|-------------|
|
|
144
|
+
| `outputCompaction.enabled` | boolean | `true` | Enable output compaction pipeline |
|
|
145
|
+
| `outputCompaction.stripAnsi` | boolean | `true` | Remove ANSI escape codes |
|
|
146
|
+
| `outputCompaction.sourceCodeFilteringEnabled` | boolean | `true` | Enable source code filtering for `read` output |
|
|
147
|
+
| `outputCompaction.preserveExactSkillReads` | boolean | `false` | Keep reads under Pi skill directories exact, bypassing read compaction |
|
|
148
|
+
| `outputCompaction.sourceCodeFiltering` | string | `"minimal"` | Filter level: `"none"`, `"minimal"`, `"aggressive"` |
|
|
149
|
+
| `outputCompaction.aggregateTestOutput` | boolean | `true` | Summarize test runner output |
|
|
150
|
+
| `outputCompaction.filterBuildOutput` | boolean | `true` | Filter build/compile output |
|
|
151
|
+
| `outputCompaction.compactGitOutput` | boolean | `true` | Compact git command output |
|
|
152
|
+
| `outputCompaction.aggregateLinterOutput` | boolean | `true` | Summarize linter output |
|
|
153
|
+
| `outputCompaction.groupSearchOutput` | boolean | `true` | Group search results by file |
|
|
154
|
+
| `outputCompaction.trackSavings` | boolean | `true` | Track compaction metrics |
|
|
155
|
+
|
|
156
|
+
#### Truncation Settings
|
|
157
|
+
|
|
158
|
+
| Option | Type | Default | Range | Description |
|
|
159
|
+
|--------|------|---------|-------|-------------|
|
|
160
|
+
| `outputCompaction.smartTruncate.enabled` | boolean | `true` | — | Enable smart line-based truncation |
|
|
161
|
+
| `outputCompaction.smartTruncate.maxLines` | number | `220` | 40–4000 | Maximum lines after smart truncation |
|
|
162
|
+
| `outputCompaction.truncate.enabled` | boolean | `true` | — | Enable hard character truncation |
|
|
163
|
+
| `outputCompaction.truncate.maxChars` | number | `12000` | 1000–200000 | Maximum characters in final output |
|
|
164
|
+
|
|
165
|
+
### Source Code Filtering Levels
|
|
166
|
+
|
|
167
|
+
| Level | Behavior |
|
|
168
|
+
|-------|----------|
|
|
169
|
+
| `none` | No filtering applied |
|
|
170
|
+
| `minimal` | Removes non-doc comments, collapses blank lines |
|
|
171
|
+
| `aggressive` | Also removes imports, keeps only signatures and key logic |
|
|
172
|
+
|
|
173
|
+
> **Note:** If file edits fail because "old text does not match," disable source filtering via `/rtk`, re-read the file, apply the edit, then re-enable filtering.
|
|
174
|
+
|
|
175
|
+
### Example Configuration
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"enabled": true,
|
|
180
|
+
"mode": "rewrite",
|
|
181
|
+
"guardWhenRtkMissing": true,
|
|
182
|
+
"showRewriteNotifications": true,
|
|
183
|
+
"rewriteGitGithub": true,
|
|
184
|
+
"rewriteFilesystem": true,
|
|
185
|
+
"rewriteRust": true,
|
|
186
|
+
"rewriteJavaScript": true,
|
|
187
|
+
"rewritePython": true,
|
|
188
|
+
"rewriteGo": true,
|
|
189
|
+
"rewriteContainers": true,
|
|
190
|
+
"rewriteNetwork": true,
|
|
191
|
+
"rewritePackageManagers": true,
|
|
192
|
+
"outputCompaction": {
|
|
193
|
+
"enabled": true,
|
|
194
|
+
"stripAnsi": true,
|
|
195
|
+
"sourceCodeFilteringEnabled": true,
|
|
196
|
+
"preserveExactSkillReads": false,
|
|
197
|
+
"sourceCodeFiltering": "minimal",
|
|
198
|
+
"aggregateTestOutput": true,
|
|
199
|
+
"filterBuildOutput": true,
|
|
200
|
+
"compactGitOutput": true,
|
|
201
|
+
"aggregateLinterOutput": true,
|
|
202
|
+
"groupSearchOutput": true,
|
|
203
|
+
"trackSavings": true,
|
|
204
|
+
"smartTruncate": {
|
|
205
|
+
"enabled": true,
|
|
206
|
+
"maxLines": 220
|
|
207
|
+
},
|
|
208
|
+
"truncate": {
|
|
209
|
+
"enabled": true,
|
|
210
|
+
"maxChars": 12000
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Technical Details
|
|
217
|
+
|
|
218
|
+
### Architecture
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
index.ts # Pi auto-discovery entrypoint
|
|
222
|
+
src/
|
|
223
|
+
├── index.ts # Extension bootstrap and event wiring
|
|
224
|
+
├── config-store.ts # Config load/save with normalization
|
|
225
|
+
├── config-modal.ts # TUI settings modal and /rtk handler
|
|
226
|
+
├── command-rewriter.ts # Command tokenization and rewrite logic
|
|
227
|
+
├── rewrite-bypass.ts # Rewrite safety bypass rules for interactive/structured commands
|
|
228
|
+
├── rewrite-rules.ts # Rewrite rule catalog
|
|
229
|
+
├── runtime-guard.ts # Runtime availability guard helpers for rewrite mode
|
|
230
|
+
├── output-compactor.ts # Tool result compaction pipeline
|
|
231
|
+
├── output-metrics.ts # Savings tracking and reporting
|
|
232
|
+
├── command-completions.ts # /rtk subcommand completions
|
|
233
|
+
├── windows-command-helpers.ts # Windows bash compatibility
|
|
234
|
+
└── techniques/ # Compaction technique implementations
|
|
235
|
+
├── ansi.ts # ANSI code stripping
|
|
236
|
+
├── build.ts # Build output filtering
|
|
237
|
+
├── test-output.ts # Test output aggregation
|
|
238
|
+
├── linter.ts # Linter output aggregation
|
|
239
|
+
├── git.ts # Git output compaction
|
|
240
|
+
├── search.ts # Search result grouping
|
|
241
|
+
├── source.ts # Source code filtering
|
|
242
|
+
└── truncate.ts # Smart and hard truncation
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Event Hooks
|
|
246
|
+
|
|
247
|
+
The extension hooks into Pi's event system:
|
|
248
|
+
|
|
249
|
+
- **`beforeToolCall`** — Rewrites bash commands to rtk equivalents
|
|
250
|
+
- **`afterToolResult`** — Compacts tool output before context consumption
|
|
251
|
+
- **`command`** — Handles `/rtk` command and subcommands
|
|
252
|
+
|
|
253
|
+
### Windows Compatibility
|
|
254
|
+
|
|
255
|
+
Automatic fixes applied on Windows:
|
|
256
|
+
|
|
257
|
+
- `cd /d <path>` → `cd "<normalized-path>"` (converts backslashes)
|
|
258
|
+
- Prepends `PYTHONIOENCODING=utf-8` for Python commands
|
|
259
|
+
|
|
260
|
+
### Dependencies
|
|
261
|
+
|
|
262
|
+
- **Peer dependencies:** `@mariozechner/pi-coding-agent`, `@mariozechner/pi-tui`
|
|
263
|
+
- **Runtime:** Node.js ≥20, optional `rtk` binary for command rewriting
|
|
264
|
+
|
|
265
|
+
## Development
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Build
|
|
269
|
+
npm run build
|
|
270
|
+
|
|
271
|
+
# Full typecheck
|
|
272
|
+
npm run typecheck
|
|
273
|
+
|
|
274
|
+
# Run tests
|
|
275
|
+
npm run test
|
|
276
|
+
|
|
277
|
+
# Full verification
|
|
278
|
+
npm run check
|
|
279
|
+
|
|
280
|
+
# Bundle sanity check
|
|
281
|
+
npm run build:check
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Credits
|
|
285
|
+
|
|
286
|
+
Inspired by:
|
|
287
|
+
- [mcowger/pi-rtk](https://github.com/mcowger/pi-rtk)
|
|
288
|
+
- [rtk-ai/rtk](https://github.com/rtk-ai/rtk)
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
[MIT](LICENSE) © MasuRii
|