pi-rtk-optimizer 0.3.0 → 0.3.1

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