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.
Files changed (38) hide show
  1. package/CHANGELOG.md +102 -67
  2. package/README.md +292 -290
  3. package/config/config.example.json +36 -35
  4. package/package.json +4 -4
  5. package/src/additional-coverage-test.ts +278 -0
  6. package/src/boolean-format.ts +3 -0
  7. package/src/command-rewriter-test.ts +160 -120
  8. package/src/command-rewriter.ts +594 -585
  9. package/src/config-modal-test.ts +168 -0
  10. package/src/config-modal.ts +613 -600
  11. package/src/config-store.ts +224 -217
  12. package/src/index-test.ts +54 -0
  13. package/src/index.ts +410 -289
  14. package/src/output-compactor-test.ts +500 -158
  15. package/src/output-compactor.ts +432 -349
  16. package/src/record-utils.ts +6 -0
  17. package/src/rewrite-bypass.ts +332 -173
  18. package/src/rewrite-pipeline-safety.ts +154 -0
  19. package/src/rewrite-rules.ts +255 -255
  20. package/src/rtk-command-environment.ts +64 -0
  21. package/src/runtime-guard-test.ts +42 -50
  22. package/src/runtime-guard.ts +14 -14
  23. package/src/techniques/build.ts +155 -155
  24. package/src/techniques/emoji.ts +91 -0
  25. package/src/techniques/git.ts +231 -229
  26. package/src/techniques/index.ts +10 -16
  27. package/src/techniques/linter.ts +151 -161
  28. package/src/techniques/path-utils.ts +67 -0
  29. package/src/techniques/rtk.ts +136 -0
  30. package/src/techniques/search.ts +67 -76
  31. package/src/techniques/source.ts +253 -253
  32. package/src/techniques/test-output.ts +172 -172
  33. package/src/test-helpers.ts +10 -0
  34. package/src/tool-execution-sanitizer.ts +69 -0
  35. package/src/types-shims.d.ts +192 -183
  36. package/src/types.ts +103 -114
  37. package/src/zellij-modal.ts +1001 -1001
  38. 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
- ![background](https://raw.githubusercontent.com/MasuRii/pi-rtk-optimizer/main/asset/pi-rtk-optimizer-background.png)
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.sourceCodeFiltering` | string | `"minimal"` | Filter level: `"none"`, `"minimal"`, `"aggressive"` |
148
- | `outputCompaction.aggregateTestOutput` | boolean | `true` | Summarize test runner output |
149
- | `outputCompaction.filterBuildOutput` | boolean | `true` | Filter build/compile output |
150
- | `outputCompaction.compactGitOutput` | boolean | `true` | Compact git command output |
151
- | `outputCompaction.aggregateLinterOutput` | boolean | `true` | Summarize linter output |
152
- | `outputCompaction.groupSearchOutput` | boolean | `true` | Group search results by file |
153
- | `outputCompaction.trackSavings` | boolean | `true` | Track compaction metrics |
154
-
155
- #### Truncation Settings
156
-
157
- | Option | Type | Default | Range | Description |
158
- |--------|------|---------|-------|-------------|
159
- | `outputCompaction.smartTruncate.enabled` | boolean | `true` | — | Enable smart line-based truncation |
160
- | `outputCompaction.smartTruncate.maxLines` | number | `220` | 40–4000 | Maximum lines after smart truncation |
161
- | `outputCompaction.truncate.enabled` | boolean | `true` | | Enable hard character truncation |
162
- | `outputCompaction.truncate.maxChars` | number | `12000` | 1000–200000 | Maximum characters in final output |
163
-
164
- ### Source Code Filtering Levels
165
-
166
- | Level | Behavior |
167
- |-------|----------|
168
- | `none` | No filtering applied |
169
- | `minimal` | Removes non-doc comments, collapses blank lines |
170
- | `aggressive` | Also removes imports, keeps only signatures and key logic |
171
-
172
- > **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.
173
-
174
- ### Example Configuration
175
-
176
- ```json
177
- {
178
- "enabled": true,
179
- "mode": "rewrite",
180
- "guardWhenRtkMissing": true,
181
- "showRewriteNotifications": true,
182
- "rewriteGitGithub": true,
183
- "rewriteFilesystem": true,
184
- "rewriteRust": true,
185
- "rewriteJavaScript": true,
186
- "rewritePython": true,
187
- "rewriteGo": true,
188
- "rewriteContainers": true,
189
- "rewriteNetwork": true,
190
- "rewritePackageManagers": true,
191
- "outputCompaction": {
192
- "enabled": true,
193
- "stripAnsi": true,
194
- "sourceCodeFilteringEnabled": true,
195
- "sourceCodeFiltering": "minimal",
196
- "aggregateTestOutput": true,
197
- "filterBuildOutput": true,
198
- "compactGitOutput": true,
199
- "aggregateLinterOutput": true,
200
- "groupSearchOutput": true,
201
- "trackSavings": true,
202
- "smartTruncate": {
203
- "enabled": true,
204
- "maxLines": 220
205
- },
206
- "truncate": {
207
- "enabled": true,
208
- "maxChars": 12000
209
- }
210
- }
211
- }
212
- ```
213
-
214
- ## Technical Details
215
-
216
- ### Architecture
217
-
218
- ```
219
- index.ts # Pi auto-discovery entrypoint
220
- src/
221
- ├── index.ts # Extension bootstrap and event wiring
222
- ├── config-store.ts # Config load/save with normalization
223
- ├── config-modal.ts # TUI settings modal and /rtk handler
224
- ├── command-rewriter.ts # Command tokenization and rewrite logic
225
- ├── rewrite-bypass.ts # Rewrite safety bypass rules for interactive/structured commands
226
- ├── rewrite-rules.ts # Rewrite rule catalog
227
- ├── runtime-guard.ts # Runtime availability guard helpers for rewrite mode
228
- ├── output-compactor.ts # Tool result compaction pipeline
229
- ├── output-metrics.ts # Savings tracking and reporting
230
- ├── command-completions.ts # /rtk subcommand completions
231
- ├── windows-command-helpers.ts # Windows bash compatibility
232
- └── techniques/ # Compaction technique implementations
233
- ├── ansi.ts # ANSI code stripping
234
- ├── build.ts # Build output filtering
235
- ├── test-output.ts # Test output aggregation
236
- ├── linter.ts # Linter output aggregation
237
- ├── git.ts # Git output compaction
238
- ├── search.ts # Search result grouping
239
- ├── source.ts # Source code filtering
240
- └── truncate.ts # Smart and hard truncation
241
- ```
242
-
243
- ### Event Hooks
244
-
245
- The extension hooks into Pi's event system:
246
-
247
- - **`beforeToolCall`** Rewrites bash commands to rtk equivalents
248
- - **`afterToolResult`** — Compacts tool output before context consumption
249
- - **`command`** — Handles `/rtk` command and subcommands
250
-
251
- ### Windows Compatibility
252
-
253
- Automatic fixes applied on Windows:
254
-
255
- - `cd /d <path>` → `cd "<normalized-path>"` (converts backslashes)
256
- - Prepends `PYTHONIOENCODING=utf-8` for Python commands
257
-
258
- ### Dependencies
259
-
260
- - **Peer dependencies:** `@mariozechner/pi-coding-agent`, `@mariozechner/pi-tui`
261
- - **Runtime:** Node.js ≥20, optional `rtk` binary for command rewriting
262
-
263
- ## Development
264
-
265
- ```bash
266
- # Build
267
- npm run build
268
-
269
- # Full typecheck
270
- npm run typecheck
271
-
272
- # Run tests
273
- npm run test
274
-
275
- # Full verification
276
- npm run check
277
-
278
- # Bundle sanity check
279
- npm run build:check
280
- ```
281
-
282
- ## Credits
283
-
284
- Inspired by:
285
- - [mcowger/pi-rtk](https://github.com/mcowger/pi-rtk)
286
- - [rtk-ai/rtk](https://github.com/rtk-ai/rtk)
287
-
288
- ## License
289
-
290
- [MIT](LICENSE) © MasuRii
1
+ # pi-rtk-optimizer
2
+
3
+ > RTK command rewriting and tool output compaction extension for the Pi coding agent.
4
+
5
+ ![background](https://raw.githubusercontent.com/MasuRii/pi-rtk-optimizer/main/asset/pi-rtk-optimizer-background.png)
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