pi-rtk-optimizer 0.5.4 → 0.6.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 CHANGED
@@ -7,15 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ## [0.5.4] - 2026-04-22
10
+ ## [0.6.0] - 2026-04-27
11
11
 
12
- ### Fixed
13
- - Respected `PI_CODING_AGENT_DIR` when resolving the global extension config directory and preserved exact skill reads under the configured global Pi skills path.
12
+ ### Changed
13
+ - **Breaking:** Command rewriting now delegates rewrite decisions to the installed `rtk rewrite` command, making RTK the source of truth for command support, shell parsing, bypasses, and compound-command behavior instead of the extension's local rewrite rule tables.
14
+
15
+ ### Removed
16
+ - **Breaking:** Removed the rewrite category configuration surface (`rewriteGitGithub`, `rewriteFilesystem`, `rewriteRust`, `rewriteJavaScript`, `rewritePython`, `rewriteGo`, `rewriteContainers`, `rewriteNetwork`, and `rewritePackageManagers`) from configuration normalization, examples, settings UI, and documentation. Configure rewrite policy in RTK itself instead of this extension.
17
+
18
+ ## [0.5.5] - 2026-04-24
14
19
 
15
20
  ### Changed
16
- - Updated README installation/configuration guidance and the settings modal description to document configurable global Pi paths.
17
- - Removed session-switch lifecycle reinitialization from the extension runtime.
18
- - Updated `@mariozechner/pi-coding-agent` and `@mariozechner/pi-tui` peer dependencies to ^0.68.1.
21
+ - Config path resolution now uses Pi's `getAgentDir()` API so `PI_CODING_AGENT_DIR` is respected for extension config paths (thanks to @tynanbe for PR #3).
22
+ - Global skill-read preservation paths now resolve through Pi's agent directory so `PI_CODING_AGENT_DIR` is respected (thanks to @tynanbe for PR #3).
23
+ - Source-filter troubleshooting note injection now only runs when output compaction, source filtering, and read truncation safeguards are active (thanks to @philipbjorge for PR #4).
24
+ - Updated `@mariozechner/pi-coding-agent` and `@mariozechner/pi-tui` peer dependencies to ^0.70.0.
25
+ - Clarified README and settings modal copy for global extension/config paths, skill directory paths, source-filter note behavior, architecture, and event hooks.
26
+
27
+ ### Removed
28
+ - Removed the unused local asset directory.
29
+ - Removed the `session_switch` event refresh handler.
19
30
 
20
31
  ## [0.5.3] - 2026-04-01
21
32
 
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # pi-rtk-optimizer
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/pi-rtk-optimizer?style=flat-square)](https://www.npmjs.com/package/pi-rtk-optimizer) [![License](https://img.shields.io/github/license/MasuRii/pi-rtk-optimizer?style=flat-square)](LICENSE)
4
+
3
5
  > RTK command rewriting and tool output compaction extension for the Pi coding agent.
4
6
 
5
7
  <img width="1360" height="752" alt="image" src="https://github.com/user-attachments/assets/f4536889-62ec-429a-984e-dc0de9f1f709" />
@@ -12,19 +14,9 @@
12
14
  ### Command Rewriting
13
15
 
14
16
  - **Automatic rewriting** or **suggestion-only** mode for common development workflows
15
- - Supported command categories:
16
- - **Git/GitHub** `git`, `gh` commands
17
- - **Filesystem** `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc`, `bash`, `cmd`, `powershell`
18
- - **Rust** — `cargo` commands
19
- - **JavaScript** — `vitest`, `npm`, `yarn`, `pnpm`, `bun` commands
20
- - **Python** — `pytest`, `python`, `pip`, `uv` commands
21
- - **Go** — `go` commands
22
- - **Containers** — `docker`, `docker-compose`, `podman` commands
23
- - **Network** — `curl`, `wget` commands
24
- - **Package Managers** — `apt`, `brew`, `dnf`, `pacman`, `yum` commands
25
- - Runtime guard when `rtk` binary is unavailable (falls back to original commands only in rewrite mode)
26
- - Safe rewrite bypasses for structured `gh` output commands and non-interactive container shell sessions
27
- - Improved command parsing for `sed`, shell separators, and `pnpm dlx` proxy rewrites
17
+ - Delegates bash command rewrite decisions to the installed `rtk rewrite` command, keeping RTK as the source of truth for supported commands, shell parsing, bypasses, and compound-command behavior
18
+ - Runtime guard when `rtk` binary is unavailable (raw commands run unchanged and repeated missing-binary rewrite probes are avoided)
19
+ - Pi-specific shell safety fixups for rewritten commands on Windows
28
20
 
29
21
  ### Output Compaction Pipeline
30
22
 
@@ -60,8 +52,9 @@ Multi-stage pipeline to reduce token consumption:
60
52
  Place this folder in one of the following locations:
61
53
 
62
54
  ```text
63
- ~/.pi/agent/extensions/pi-rtk-optimizer # Global default (when PI_CODING_AGENT_DIR is unset)
64
- .pi/extensions/pi-rtk-optimizer # Project-specific
55
+ ~/.pi/agent/extensions/pi-rtk-optimizer # Global default (when PI_CODING_AGENT_DIR is unset)
56
+ $PI_CODING_AGENT_DIR/extensions/pi-rtk-optimizer # Global when PI_CODING_AGENT_DIR is set
57
+ .pi/extensions/pi-rtk-optimizer # Project-specific
65
58
  ```
66
59
 
67
60
  Pi auto-discovers extensions in these paths on startup.
@@ -125,19 +118,11 @@ A starter template is included at `config/config.example.json`.
125
118
  | `guardWhenRtkMissing` | boolean | `true` | Run original commands when rtk binary unavailable |
126
119
  | `showRewriteNotifications` | boolean | `true` | Show rewrite notices in TUI |
127
120
 
128
- #### Rewrite Category Toggles
121
+ #### Rewrite Source
122
+
123
+ Bash command support is intentionally resolved by the installed `rtk` binary through `rtk rewrite`. The extension does not maintain duplicate rewrite rules or category classifiers; update/configure RTK itself for command support policy.
129
124
 
130
- | Option | Default | Commands Affected |
131
- |--------|---------|-------------------|
132
- | `rewriteGitGithub` | `true` | `git`, `gh` |
133
- | `rewriteFilesystem` | `true` | `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc` |
134
- | `rewriteRust` | `true` | `cargo` |
135
- | `rewriteJavaScript` | `true` | `vitest`, `npm`, `yarn`, `pnpm`, `bun` |
136
- | `rewritePython` | `true` | `pytest`, `python`, `pip`, `uv` |
137
- | `rewriteGo` | `true` | `go` |
138
- | `rewriteContainers` | `true` | `docker`, `docker-compose`, `podman` |
139
- | `rewriteNetwork` | `true` | `curl`, `wget` |
140
- | `rewritePackageManagers` | `true` | `apt`, `brew`, `dnf`, `pacman`, `yum` |
125
+ > **Breaking in 0.6.0:** Rewrite category toggles (`rewriteGitGithub`, `rewriteFilesystem`, `rewriteRust`, `rewriteJavaScript`, `rewritePython`, `rewriteGo`, `rewriteContainers`, `rewriteNetwork`, and `rewritePackageManagers`) were removed from the extension config surface. Existing rewrite policy should be configured in RTK because the extension now delegates rewrite ownership to `rtk rewrite`.
141
126
 
142
127
  #### Output Compaction Settings
143
128
 
@@ -146,7 +131,7 @@ A starter template is included at `config/config.example.json`.
146
131
  | `outputCompaction.enabled` | boolean | `true` | Enable output compaction pipeline |
147
132
  | `outputCompaction.stripAnsi` | boolean | `true` | Remove ANSI escape codes |
148
133
  | `outputCompaction.sourceCodeFilteringEnabled` | boolean | `true` | Enable source code filtering for `read` output |
149
- | `outputCompaction.preserveExactSkillReads` | boolean | `false` | Keep reads under Pi skill directories exact, bypassing read compaction |
134
+ | `outputCompaction.preserveExactSkillReads` | boolean | `false` | Keep reads under configured Pi/global/project skill directories exact, bypassing read compaction |
150
135
  | `outputCompaction.sourceCodeFiltering` | string | `"minimal"` | Filter level: `"none"`, `"minimal"`, `"aggressive"` |
151
136
  | `outputCompaction.aggregateTestOutput` | boolean | `true` | Summarize test runner output |
152
137
  | `outputCompaction.filterBuildOutput` | boolean | `true` | Filter build/compile output |
@@ -155,6 +140,8 @@ A starter template is included at `config/config.example.json`.
155
140
  | `outputCompaction.groupSearchOutput` | boolean | `true` | Group search results by file |
156
141
  | `outputCompaction.trackSavings` | boolean | `true` | Track compaction metrics |
157
142
 
143
+ Skill-read preservation covers the global Pi skills directory (`~/.pi/agent/skills` by default, or `$PI_CODING_AGENT_DIR/skills` when set), `~/.agents/skills`, project `.pi/skills`, and ancestor `.agents/skills` directories.
144
+
158
145
  #### Truncation Settings
159
146
 
160
147
  | Option | Type | Default | Range | Description |
@@ -172,7 +159,7 @@ A starter template is included at `config/config.example.json`.
172
159
  | `minimal` | Removes non-doc comments, collapses blank lines |
173
160
  | `aggressive` | Also removes imports, keeps only signatures and key logic |
174
161
 
175
- > **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.
162
+ > **Note:** When source filtering and read truncation safeguards are active, Pi injects a troubleshooting note for repeated file-edit mismatches. If edits fail because "old text does not match," disable source filtering via `/rtk`, re-read the file, apply the edit, then re-enable filtering.
176
163
 
177
164
  ### Example Configuration
178
165
 
@@ -182,15 +169,6 @@ A starter template is included at `config/config.example.json`.
182
169
  "mode": "rewrite",
183
170
  "guardWhenRtkMissing": true,
184
171
  "showRewriteNotifications": true,
185
- "rewriteGitGithub": true,
186
- "rewriteFilesystem": true,
187
- "rewriteRust": true,
188
- "rewriteJavaScript": true,
189
- "rewritePython": true,
190
- "rewriteGo": true,
191
- "rewriteContainers": true,
192
- "rewriteNetwork": true,
193
- "rewritePackageManagers": true,
194
172
  "outputCompaction": {
195
173
  "enabled": true,
196
174
  "stripAnsi": true,
@@ -225,15 +203,19 @@ src/
225
203
  ├── index.ts # Extension bootstrap and event wiring
226
204
  ├── config-store.ts # Config load/save with normalization
227
205
  ├── config-modal.ts # TUI settings modal and /rtk handler
228
- ├── command-rewriter.ts # Command tokenization and rewrite logic
229
- ├── rewrite-bypass.ts # Rewrite safety bypass rules for interactive/structured commands
230
- ├── rewrite-rules.ts # Rewrite rule catalog
231
- ├── runtime-guard.ts # Runtime availability guard helpers for rewrite mode
232
- ├── output-compactor.ts # Tool result compaction pipeline
233
- ├── output-metrics.ts # Savings tracking and reporting
234
- ├── command-completions.ts # /rtk subcommand completions
206
+ ├── command-rewriter.ts # Command tokenization and rewrite logic
207
+ ├── rewrite-bypass.ts # Rewrite safety bypass rules for interactive/structured commands
208
+ ├── rewrite-rules.ts # Rewrite rule catalog
209
+ ├── rewrite-pipeline-safety.ts # Shell-safety fixups for rewritten commands
210
+ ├── rtk-command-environment.ts # RTK_DB_PATH scoping for rewritten commands
211
+ ├── shell-env-prefix.ts # Environment assignment parsing helpers
212
+ ├── runtime-guard.ts # Runtime availability guard helpers for rewrite mode
213
+ ├── output-compactor.ts # Tool result compaction pipeline
214
+ ├── output-metrics.ts # Savings tracking and reporting
215
+ ├── tool-execution-sanitizer.ts # Streaming bash execution output sanitizer
216
+ ├── command-completions.ts # /rtk subcommand completions
235
217
  ├── windows-command-helpers.ts # Windows bash compatibility
236
- └── techniques/ # Compaction technique implementations
218
+ └── techniques/ # Compaction technique implementations
237
219
  ├── ansi.ts # ANSI code stripping
238
220
  ├── build.ts # Build output filtering
239
221
  ├── test-output.ts # Test output aggregation
@@ -248,9 +230,12 @@ src/
248
230
 
249
231
  The extension hooks into Pi's event system:
250
232
 
251
- - **`beforeToolCall`** — Rewrites bash commands to rtk equivalents
252
- - **`afterToolResult`** — Compacts tool output before context consumption
253
- - **`command`** Handles `/rtk` command and subcommands
233
+ - **`tool_call`** — Rewrites bash commands to rtk equivalents or emits suggestions
234
+ - **`tool_result`** — Compacts completed tool output before context consumption
235
+ - **`tool_execution_start` / `tool_execution_update` / `tool_execution_end`** Tracks and sanitizes streamed bash output
236
+ - **`before_agent_start`** — Conditionally injects source-filter troubleshooting guidance
237
+ - **`session_start` / `agent_end`** — Refreshes config and clears in-session tracking state
238
+ - **Registered `/rtk` command** — Handles settings, status, verification, stats, and reset subcommands
254
239
 
255
240
  ### Windows Compatibility
256
241
 
@@ -3,15 +3,6 @@
3
3
  "mode": "rewrite",
4
4
  "guardWhenRtkMissing": true,
5
5
  "showRewriteNotifications": true,
6
- "rewriteGitGithub": true,
7
- "rewriteFilesystem": true,
8
- "rewriteRust": true,
9
- "rewriteJavaScript": true,
10
- "rewritePython": true,
11
- "rewriteGo": true,
12
- "rewriteContainers": true,
13
- "rewriteNetwork": true,
14
- "rewritePackageManagers": true,
15
6
  "outputCompaction": {
16
7
  "enabled": true,
17
8
  "stripAnsi": true,
package/package.json CHANGED
@@ -1,64 +1,64 @@
1
- {
2
- "name": "pi-rtk-optimizer",
3
- "version": "0.5.4",
4
- "description": "Pi extension that optimizes RTK command rewriting and tool output compaction for the coding agent.",
5
- "type": "module",
6
- "main": "./index.ts",
7
- "exports": {
8
- ".": "./index.ts"
9
- },
10
- "files": [
11
- "index.ts",
12
- "src",
13
- "config/config.example.json",
14
- "README.md",
15
- "CHANGELOG.md",
16
- "LICENSE"
17
- ],
18
- "scripts": {
19
- "build": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json --noCheck",
20
- "lint": "npm run build",
21
- "typecheck": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json",
22
- "test": "bun ./src/output-compactor-test.ts && bun ./src/command-rewriter-test.ts && bun ./src/runtime-guard-test.ts && bun ./src/additional-coverage-test.ts && bun ./src/config-modal-test.ts && bun ./src/index-test.ts",
23
- "check": "npm run lint && npm run typecheck && npm run test",
24
- "build:check": "bunx esbuild ./index.ts --bundle --platform=node --format=esm --outfile=./.pi-rtk-optimizer-check.mjs --external:@mariozechner/pi-coding-agent --external:@mariozechner/pi-tui && bun -e \"import { unlinkSync } from 'node:fs'; unlinkSync('./.pi-rtk-optimizer-check.mjs');\""
25
- },
26
- "keywords": [
27
- "pi-package",
28
- "pi",
29
- "pi-extension",
30
- "pi-coding-agent",
31
- "coding-agent",
32
- "rtk",
33
- "token-optimization",
34
- "tool-compaction",
35
- "output-compaction",
36
- "command-rewrite",
37
- "optimization"
38
- ],
39
- "author": "MasuRii",
40
- "license": "MIT",
41
- "repository": {
42
- "type": "git",
43
- "url": "git+https://github.com/MasuRii/pi-rtk-optimizer.git"
44
- },
45
- "bugs": {
46
- "url": "https://github.com/MasuRii/pi-rtk-optimizer/issues"
47
- },
48
- "homepage": "https://github.com/MasuRii/pi-rtk-optimizer#readme",
49
- "engines": {
50
- "node": ">=20"
51
- },
52
- "publishConfig": {
53
- "access": "public"
54
- },
55
- "pi": {
56
- "extensions": [
57
- "./index.ts"
58
- ]
59
- },
60
- "peerDependencies": {
61
- "@mariozechner/pi-coding-agent": "^0.68.1",
62
- "@mariozechner/pi-tui": "^0.68.1"
63
- }
64
- }
1
+ {
2
+ "name": "pi-rtk-optimizer",
3
+ "version": "0.6.0",
4
+ "description": "Pi extension that optimizes RTK command rewriting and tool output compaction for the coding agent.",
5
+ "type": "module",
6
+ "main": "./index.ts",
7
+ "exports": {
8
+ ".": "./index.ts"
9
+ },
10
+ "files": [
11
+ "index.ts",
12
+ "src",
13
+ "config/config.example.json",
14
+ "README.md",
15
+ "CHANGELOG.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "build": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json --noCheck",
20
+ "lint": "npm run build",
21
+ "typecheck": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json",
22
+ "test": "bun ./src/output-compactor-test.ts && bun ./src/command-rewriter-test.ts && bun ./src/runtime-guard-test.ts && bun ./src/additional-coverage-test.ts && bun ./src/config-modal-test.ts && bun ./src/index-test.ts",
23
+ "check": "npm run lint && npm run typecheck && npm run test",
24
+ "build:check": "bunx esbuild ./index.ts --bundle --platform=node --format=esm --outfile=./.pi-rtk-optimizer-check.mjs --external:@mariozechner/pi-coding-agent --external:@mariozechner/pi-tui && bun -e \"import { unlinkSync } from 'node:fs'; unlinkSync('./.pi-rtk-optimizer-check.mjs');\""
25
+ },
26
+ "keywords": [
27
+ "pi-package",
28
+ "pi",
29
+ "pi-extension",
30
+ "pi-coding-agent",
31
+ "coding-agent",
32
+ "rtk",
33
+ "token-optimization",
34
+ "tool-compaction",
35
+ "output-compaction",
36
+ "command-rewrite",
37
+ "optimization"
38
+ ],
39
+ "author": "MasuRii",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/MasuRii/pi-rtk-optimizer.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/MasuRii/pi-rtk-optimizer/issues"
47
+ },
48
+ "homepage": "https://github.com/MasuRii/pi-rtk-optimizer#readme",
49
+ "engines": {
50
+ "node": ">=20"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "pi": {
56
+ "extensions": [
57
+ "./index.ts"
58
+ ]
59
+ },
60
+ "peerDependencies": {
61
+ "@mariozechner/pi-coding-agent": "^0.70.2",
62
+ "@mariozechner/pi-tui": "^0.70.2"
63
+ }
64
+ }
@@ -1,11 +1,20 @@
1
1
  import assert from "node:assert/strict";
2
- import { mock } from "bun:test";
3
2
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { mock } from "bun:test";
4
4
 
5
- const MOCK_AGENT_DIR = "C:/tmp/.pi/agent";
5
+ import { clearOutputMetrics, getOutputMetricsSummary, trackOutputSavings } from "./output-metrics.ts";
6
+ import { runTest } from "./test-helpers.ts";
7
+ import { matchesCommandPatterns, normalizeCommandForDetection } from "./techniques/command-detection.ts";
8
+ import { compactPath } from "./techniques/path-utils.ts";
9
+ import { applyWindowsBashCompatibilityFixes } from "./windows-command-helpers.ts";
10
+ import { applyRewrittenCommandShellSafetyFixups } from "./rewrite-pipeline-safety.ts";
11
+ import { applyRtkCommandEnvironment } from "./rtk-command-environment.ts";
12
+ import { sanitizeStreamingBashExecutionResult } from "./tool-execution-sanitizer.ts";
13
+ import { sanitizeRtkEmojiOutput } from "./techniques/emoji.ts";
14
+ import { stripRtkHookWarnings } from "./techniques/rtk.ts";
6
15
 
7
16
  mock.module("@mariozechner/pi-coding-agent", () => ({
8
- getAgentDir: () => MOCK_AGENT_DIR,
17
+ getAgentDir: () => "/tmp/.pi/agent",
9
18
  }));
10
19
 
11
20
  const {
@@ -15,16 +24,6 @@ const {
15
24
  normalizeRtkIntegrationConfig,
16
25
  saveRtkIntegrationConfig,
17
26
  } = await import("./config-store.ts");
18
- import { clearOutputMetrics, getOutputMetricsSummary, trackOutputSavings } from "./output-metrics.ts";
19
- import { runTest } from "./test-helpers.ts";
20
- import { matchesCommandPatterns, normalizeCommandForDetection } from "./techniques/command-detection.ts";
21
- import { compactPath } from "./techniques/path-utils.ts";
22
- import { applyWindowsBashCompatibilityFixes } from "./windows-command-helpers.ts";
23
- import { applyRewrittenCommandShellSafetyFixups } from "./rewrite-pipeline-safety.ts";
24
- import { applyRtkCommandEnvironment } from "./rtk-command-environment.ts";
25
- import { sanitizeStreamingBashExecutionResult } from "./tool-execution-sanitizer.ts";
26
- import { sanitizeRtkEmojiOutput } from "./techniques/emoji.ts";
27
- import { stripRtkHookWarnings } from "./techniques/rtk.ts";
28
27
 
29
28
  function makeTempConfigPath(): string {
30
29
  return `${getRtkIntegrationConfigPath()}.test-${Date.now()}-${Math.random().toString(16).slice(2)}.json`;
@@ -65,7 +64,7 @@ runTest("config-store normalizes invalid values and clamps numeric ranges", () =
65
64
 
66
65
  assert.equal(normalized.enabled, true);
67
66
  assert.equal(normalized.mode, "rewrite");
68
- assert.equal(normalized.rewriteGitGithub, false);
67
+ assert.equal(Object.hasOwn(normalized, "rewriteGitGithub"), false);
69
68
  assert.equal(normalized.outputCompaction.stripAnsi, false);
70
69
  assert.equal(normalized.outputCompaction.sourceCodeFilteringEnabled, true);
71
70
  assert.equal(normalized.outputCompaction.sourceCodeFiltering, "minimal");