pi-rtk-optimizer 0.5.5 → 0.7.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 +17 -0
- package/README.md +20 -41
- package/config/config.example.json +6 -12
- package/package.json +64 -64
- package/src/additional-coverage-test.ts +48 -6
- package/src/command-rewriter-test.ts +118 -160
- package/src/command-rewriter.ts +43 -594
- package/src/config-modal-test.ts +2 -0
- package/src/config-modal.ts +17 -105
- package/src/config-store.ts +32 -29
- package/src/index-test.ts +31 -2
- package/src/index.ts +8 -7
- package/src/output-compactor-test.ts +45 -2
- package/src/output-compactor.ts +4 -0
- package/src/rewrite-pipeline-safety.ts +23 -2
- package/src/rtk-command-environment.ts +69 -64
- package/src/rtk-rewrite-provider.ts +90 -0
- package/src/runtime-guard-test.ts +4 -3
- package/src/runtime-guard.ts +1 -1
- package/src/types.ts +9 -21
- package/src/rewrite-bypass.ts +0 -332
- package/src/rewrite-rules.ts +0 -255
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-04-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Added opt-in `readCompaction` controls for `read` output so lossy source filtering and smart truncation stay disabled unless explicitly enabled.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Updated README and example configuration defaults for safer read-compaction behavior and troubleshooting guidance.
|
|
17
|
+
- Updated `@mariozechner/pi-coding-agent` and `@mariozechner/pi-tui` peer dependencies to ^0.70.6.
|
|
18
|
+
|
|
19
|
+
## [0.6.0] - 2026-04-27
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- **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.
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
- **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.
|
|
26
|
+
|
|
10
27
|
## [0.5.5] - 2026-04-24
|
|
11
28
|
|
|
12
29
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# pi-rtk-optimizer
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/pi-rtk-optimizer) [](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
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
|
@@ -126,19 +118,11 @@ A starter template is included at `config/config.example.json`.
|
|
|
126
118
|
| `guardWhenRtkMissing` | boolean | `true` | Run original commands when rtk binary unavailable |
|
|
127
119
|
| `showRewriteNotifications` | boolean | `true` | Show rewrite notices in TUI |
|
|
128
120
|
|
|
129
|
-
#### Rewrite
|
|
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.
|
|
130
124
|
|
|
131
|
-
|
|
132
|
-
|--------|---------|-------------------|
|
|
133
|
-
| `rewriteGitGithub` | `true` | `git`, `gh` |
|
|
134
|
-
| `rewriteFilesystem` | `true` | `cat`, `head`, `tail`, `grep`, `rg`, `ls`, `tree`, `find`, `diff`, `wc` |
|
|
135
|
-
| `rewriteRust` | `true` | `cargo` |
|
|
136
|
-
| `rewriteJavaScript` | `true` | `vitest`, `npm`, `yarn`, `pnpm`, `bun` |
|
|
137
|
-
| `rewritePython` | `true` | `pytest`, `python`, `pip`, `uv` |
|
|
138
|
-
| `rewriteGo` | `true` | `go` |
|
|
139
|
-
| `rewriteContainers` | `true` | `docker`, `docker-compose`, `podman` |
|
|
140
|
-
| `rewriteNetwork` | `true` | `curl`, `wget` |
|
|
141
|
-
| `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`.
|
|
142
126
|
|
|
143
127
|
#### Output Compaction Settings
|
|
144
128
|
|
|
@@ -146,9 +130,10 @@ A starter template is included at `config/config.example.json`.
|
|
|
146
130
|
|--------|------|---------|-------------|
|
|
147
131
|
| `outputCompaction.enabled` | boolean | `true` | Enable output compaction pipeline |
|
|
148
132
|
| `outputCompaction.stripAnsi` | boolean | `true` | Remove ANSI escape codes |
|
|
149
|
-
| `outputCompaction.
|
|
133
|
+
| `outputCompaction.readCompaction.enabled` | boolean | `false` | Enable lossy compaction for `read` output; defaults off so code reads stay exact |
|
|
134
|
+
| `outputCompaction.sourceCodeFilteringEnabled` | boolean | `false` | Enable source code filtering for `read` output when read compaction is enabled |
|
|
150
135
|
| `outputCompaction.preserveExactSkillReads` | boolean | `false` | Keep reads under configured Pi/global/project skill directories exact, bypassing read compaction |
|
|
151
|
-
| `outputCompaction.sourceCodeFiltering` | string | `"
|
|
136
|
+
| `outputCompaction.sourceCodeFiltering` | string | `"none"` | Filter level: `"none"`, `"minimal"`, `"aggressive"` |
|
|
152
137
|
| `outputCompaction.aggregateTestOutput` | boolean | `true` | Summarize test runner output |
|
|
153
138
|
| `outputCompaction.filterBuildOutput` | boolean | `true` | Filter build/compile output |
|
|
154
139
|
| `outputCompaction.compactGitOutput` | boolean | `true` | Compact git command output |
|
|
@@ -162,7 +147,7 @@ Skill-read preservation covers the global Pi skills directory (`~/.pi/agent/skil
|
|
|
162
147
|
|
|
163
148
|
| Option | Type | Default | Range | Description |
|
|
164
149
|
|--------|------|---------|-------|-------------|
|
|
165
|
-
| `outputCompaction.smartTruncate.enabled` | boolean | `
|
|
150
|
+
| `outputCompaction.smartTruncate.enabled` | boolean | `false` | — | Enable smart line-based truncation for read output when read compaction is enabled |
|
|
166
151
|
| `outputCompaction.smartTruncate.maxLines` | number | `220` | 40–4000 | Maximum lines after smart truncation |
|
|
167
152
|
| `outputCompaction.truncate.enabled` | boolean | `true` | — | Enable hard character truncation |
|
|
168
153
|
| `outputCompaction.truncate.maxChars` | number | `12000` | 1000–200000 | Maximum characters in final output |
|
|
@@ -175,7 +160,7 @@ Skill-read preservation covers the global Pi skills directory (`~/.pi/agent/skil
|
|
|
175
160
|
| `minimal` | Removes non-doc comments, collapses blank lines |
|
|
176
161
|
| `aggressive` | Also removes imports, keeps only signatures and key logic |
|
|
177
162
|
|
|
178
|
-
> **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
|
|
163
|
+
> **Note:** When read compaction, 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 read compaction via `/rtk`, re-read the file, apply the edit, then re-enable compaction.
|
|
179
164
|
|
|
180
165
|
### Example Configuration
|
|
181
166
|
|
|
@@ -185,21 +170,15 @@ Skill-read preservation covers the global Pi skills directory (`~/.pi/agent/skil
|
|
|
185
170
|
"mode": "rewrite",
|
|
186
171
|
"guardWhenRtkMissing": true,
|
|
187
172
|
"showRewriteNotifications": true,
|
|
188
|
-
"rewriteGitGithub": true,
|
|
189
|
-
"rewriteFilesystem": true,
|
|
190
|
-
"rewriteRust": true,
|
|
191
|
-
"rewriteJavaScript": true,
|
|
192
|
-
"rewritePython": true,
|
|
193
|
-
"rewriteGo": true,
|
|
194
|
-
"rewriteContainers": true,
|
|
195
|
-
"rewriteNetwork": true,
|
|
196
|
-
"rewritePackageManagers": true,
|
|
197
173
|
"outputCompaction": {
|
|
198
174
|
"enabled": true,
|
|
199
175
|
"stripAnsi": true,
|
|
200
|
-
"
|
|
176
|
+
"readCompaction": {
|
|
177
|
+
"enabled": false
|
|
178
|
+
},
|
|
179
|
+
"sourceCodeFilteringEnabled": false,
|
|
201
180
|
"preserveExactSkillReads": false,
|
|
202
|
-
"sourceCodeFiltering": "
|
|
181
|
+
"sourceCodeFiltering": "none",
|
|
203
182
|
"aggregateTestOutput": true,
|
|
204
183
|
"filterBuildOutput": true,
|
|
205
184
|
"compactGitOutput": true,
|
|
@@ -207,7 +186,7 @@ Skill-read preservation covers the global Pi skills directory (`~/.pi/agent/skil
|
|
|
207
186
|
"groupSearchOutput": true,
|
|
208
187
|
"trackSavings": true,
|
|
209
188
|
"smartTruncate": {
|
|
210
|
-
"enabled":
|
|
189
|
+
"enabled": false,
|
|
211
190
|
"maxLines": 220
|
|
212
191
|
},
|
|
213
192
|
"truncate": {
|
|
@@ -3,27 +3,21 @@
|
|
|
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,
|
|
18
|
-
"
|
|
9
|
+
"readCompaction": {
|
|
10
|
+
"enabled": false
|
|
11
|
+
},
|
|
12
|
+
"sourceCodeFilteringEnabled": false,
|
|
19
13
|
"preserveExactSkillReads": false,
|
|
20
14
|
"truncate": {
|
|
21
15
|
"enabled": true,
|
|
22
16
|
"maxChars": 12000
|
|
23
17
|
},
|
|
24
|
-
"sourceCodeFiltering": "
|
|
18
|
+
"sourceCodeFiltering": "none",
|
|
25
19
|
"smartTruncate": {
|
|
26
|
-
"enabled":
|
|
20
|
+
"enabled": false,
|
|
27
21
|
"maxLines": 220
|
|
28
22
|
},
|
|
29
23
|
"aggregateTestOutput": true,
|
package/package.json
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pi-rtk-optimizer",
|
|
3
|
-
"version": "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.
|
|
62
|
-
"@mariozechner/pi-tui": "^0.70.
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-rtk-optimizer",
|
|
3
|
+
"version": "0.7.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.6",
|
|
62
|
+
"@mariozechner/pi-tui": "^0.70.6"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -64,8 +64,9 @@ runTest("config-store normalizes invalid values and clamps numeric ranges", () =
|
|
|
64
64
|
|
|
65
65
|
assert.equal(normalized.enabled, true);
|
|
66
66
|
assert.equal(normalized.mode, "rewrite");
|
|
67
|
-
assert.equal(normalized
|
|
67
|
+
assert.equal(Object.hasOwn(normalized, "rewriteGitGithub"), false);
|
|
68
68
|
assert.equal(normalized.outputCompaction.stripAnsi, false);
|
|
69
|
+
assert.equal(normalized.outputCompaction.readCompaction.enabled, true);
|
|
69
70
|
assert.equal(normalized.outputCompaction.sourceCodeFilteringEnabled, true);
|
|
70
71
|
assert.equal(normalized.outputCompaction.sourceCodeFiltering, "minimal");
|
|
71
72
|
assert.equal(normalized.outputCompaction.truncate.maxChars, 1_000);
|
|
@@ -73,18 +74,32 @@ runTest("config-store normalizes invalid values and clamps numeric ranges", () =
|
|
|
73
74
|
assert.equal(normalized.outputCompaction.trackSavings, false);
|
|
74
75
|
});
|
|
75
76
|
|
|
77
|
+
runTest("config-store uses safer read defaults when readCompaction is explicit", () => {
|
|
78
|
+
const normalized = normalizeRtkIntegrationConfig({
|
|
79
|
+
outputCompaction: {
|
|
80
|
+
readCompaction: { enabled: false },
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
assert.equal(normalized.outputCompaction.readCompaction.enabled, false);
|
|
85
|
+
assert.equal(normalized.outputCompaction.sourceCodeFilteringEnabled, false);
|
|
86
|
+
assert.equal(normalized.outputCompaction.sourceCodeFiltering, "none");
|
|
87
|
+
assert.equal(normalized.outputCompaction.smartTruncate.enabled, false);
|
|
88
|
+
});
|
|
89
|
+
|
|
76
90
|
runTest("config-store can ensure, save, and reload isolated config files", () => {
|
|
77
91
|
const tempPath = makeTempConfigPath();
|
|
78
92
|
cleanupFile(tempPath);
|
|
79
93
|
|
|
80
94
|
try {
|
|
81
95
|
const ensured = ensureConfigExists(tempPath);
|
|
82
|
-
assert.equal(ensured.
|
|
96
|
+
assert.equal(ensured.error, undefined);
|
|
83
97
|
assert.equal(existsSync(tempPath), true);
|
|
84
98
|
|
|
85
99
|
const defaultLoad = loadRtkIntegrationConfig(tempPath);
|
|
86
100
|
assert.equal(defaultLoad.warning, undefined);
|
|
87
101
|
assert.equal(defaultLoad.config.mode, "rewrite");
|
|
102
|
+
assert.equal(defaultLoad.config.outputCompaction.readCompaction.enabled, false);
|
|
88
103
|
|
|
89
104
|
const saved = saveRtkIntegrationConfig(
|
|
90
105
|
{
|
|
@@ -153,6 +168,14 @@ runTest("command detection ignores env prefixes, blank lines, and chained suffix
|
|
|
153
168
|
assert.equal(matchesCommandPatterns("echo hello", [/^bun test/]), false);
|
|
154
169
|
});
|
|
155
170
|
|
|
171
|
+
runTest("RTK command environment preserves explicit leading RTK_DB_PATH overrides", () => {
|
|
172
|
+
const command = 'RTK_DB_PATH="/custom/history.db" rtk git diff';
|
|
173
|
+
assert.equal(applyRtkCommandEnvironment(command), command);
|
|
174
|
+
|
|
175
|
+
const exportedCommand = 'export RTK_DB_PATH="/custom/history.db"; rtk git diff';
|
|
176
|
+
assert.equal(applyRtkCommandEnvironment(exportedCommand), exportedCommand);
|
|
177
|
+
});
|
|
178
|
+
|
|
156
179
|
runTest("path compaction preserves the tail and handles Windows separators", () => {
|
|
157
180
|
const unixPath = "/Users/example/projects/pi-rtk-optimizer/src/techniques/path-utils.ts";
|
|
158
181
|
const compactUnixPath = compactPath(unixPath, 28);
|
|
@@ -204,21 +227,21 @@ runTest("rewrite pipeline safety buffers rewritten Windows producer commands", (
|
|
|
204
227
|
assert.equal(applyRewrittenCommandShellSafetyFixups("git diff | grep TODO"), "git diff | grep TODO");
|
|
205
228
|
});
|
|
206
229
|
|
|
207
|
-
runTest("rewrite pipeline safety keeps RTK_DB_PATH
|
|
230
|
+
runTest("rewrite pipeline safety keeps exported RTK_DB_PATH on rewritten producer commands", () => {
|
|
208
231
|
const rewritten = applyRewrittenCommandShellSafetyFixups(
|
|
209
232
|
applyRtkCommandEnvironment("rtk git diff agent/extensions/pi-multi-auth/account-manager.ts | head -200"),
|
|
210
233
|
);
|
|
211
234
|
|
|
212
235
|
if (process.platform === "win32") {
|
|
213
|
-
assert.ok(rewritten.startsWith("
|
|
236
|
+
assert.ok(rewritten.startsWith("export RTK_DB_PATH="));
|
|
214
237
|
assert.equal(rewritten.startsWith("RTK_DB_PATH="), false);
|
|
215
|
-
assert.ok(rewritten.includes("
|
|
238
|
+
assert.ok(rewritten.includes("; {"));
|
|
216
239
|
assert.ok(
|
|
217
240
|
rewritten.includes('rtk git diff agent/extensions/pi-multi-auth/account-manager.ts > "$__pi_rtk_pipe_tmp"'),
|
|
218
241
|
);
|
|
219
242
|
assert.ok(rewritten.includes('(head -200) < "$__pi_rtk_pipe_tmp"'));
|
|
220
243
|
} else {
|
|
221
|
-
assert.ok(rewritten.startsWith("RTK_DB_PATH="));
|
|
244
|
+
assert.ok(rewritten.startsWith("export RTK_DB_PATH="));
|
|
222
245
|
assert.equal(
|
|
223
246
|
rewritten,
|
|
224
247
|
applyRtkCommandEnvironment("rtk git diff agent/extensions/pi-multi-auth/account-manager.ts | head -200"),
|
|
@@ -226,6 +249,25 @@ runTest("rewrite pipeline safety keeps RTK_DB_PATH scoped to rewritten producer
|
|
|
226
249
|
}
|
|
227
250
|
});
|
|
228
251
|
|
|
252
|
+
runTest("rewrite pipeline safety buffers explicit RTK_DB_PATH export preludes", () => {
|
|
253
|
+
const command = 'export RTK_DB_PATH="/custom/history.db"; rtk git diff | head -200';
|
|
254
|
+
const rewritten = applyRewrittenCommandShellSafetyFixups(command);
|
|
255
|
+
|
|
256
|
+
if (process.platform === "win32") {
|
|
257
|
+
assert.ok(rewritten.startsWith('export RTK_DB_PATH="/custom/history.db"; {'));
|
|
258
|
+
assert.ok(rewritten.includes('rtk git diff > "$__pi_rtk_pipe_tmp"'));
|
|
259
|
+
assert.ok(rewritten.includes('(head -200) < "$__pi_rtk_pipe_tmp"'));
|
|
260
|
+
} else {
|
|
261
|
+
assert.equal(rewritten, command);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
runTest("RTK command environment uses export prelude for shell compound commands", () => {
|
|
266
|
+
const rewritten = applyRtkCommandEnvironment('for d in a b; do echo "$d"; done');
|
|
267
|
+
assert.ok(/^export RTK_DB_PATH=/.test(rewritten));
|
|
268
|
+
assert.ok(/; for d in a b; do echo "\$d"; done$/.test(rewritten));
|
|
269
|
+
});
|
|
270
|
+
|
|
229
271
|
runTest("stripRtkHookWarnings handles bare, prefixed, and already-sanitized hook notices", () => {
|
|
230
272
|
assert.equal(
|
|
231
273
|
stripRtkHookWarnings("No hook installed — run `rtk init -g` for automatic token savings\n\nready\n", null),
|