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
@@ -1,207 +0,0 @@
1
- import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
2
- import type { RtkIntegrationConfig } from "./types.js";
3
-
4
- interface RtkCompatController {
5
- getConfig(): RtkIntegrationConfig;
6
- setConfig(next: RtkIntegrationConfig, ctx: ExtensionCommandContext): void;
7
- getMetricsSummary(): string;
8
- clearMetrics(): void;
9
- }
10
-
11
- interface BooleanToggleDefinition {
12
- name: string;
13
- description: string;
14
- getValue(config: RtkIntegrationConfig): boolean;
15
- setValue(config: RtkIntegrationConfig, nextValue: boolean): RtkIntegrationConfig;
16
- }
17
-
18
- const BOOLEAN_TOGGLES: BooleanToggleDefinition[] = [
19
- {
20
- name: "ansiStripping",
21
- description: "Toggle ANSI stripping for compacted output",
22
- getValue: (config) => config.outputCompaction.stripAnsi,
23
- setValue: (config, nextValue) => ({
24
- ...config,
25
- outputCompaction: {
26
- ...config.outputCompaction,
27
- stripAnsi: nextValue,
28
- },
29
- }),
30
- },
31
- {
32
- name: "testOutputAggregation",
33
- description: "Toggle test output aggregation",
34
- getValue: (config) => config.outputCompaction.aggregateTestOutput,
35
- setValue: (config, nextValue) => ({
36
- ...config,
37
- outputCompaction: {
38
- ...config.outputCompaction,
39
- aggregateTestOutput: nextValue,
40
- },
41
- }),
42
- },
43
- {
44
- name: "buildOutputFiltering",
45
- description: "Toggle build output filtering",
46
- getValue: (config) => config.outputCompaction.filterBuildOutput,
47
- setValue: (config, nextValue) => ({
48
- ...config,
49
- outputCompaction: {
50
- ...config.outputCompaction,
51
- filterBuildOutput: nextValue,
52
- },
53
- }),
54
- },
55
- {
56
- name: "gitCompaction",
57
- description: "Toggle git output compaction",
58
- getValue: (config) => config.outputCompaction.compactGitOutput,
59
- setValue: (config, nextValue) => ({
60
- ...config,
61
- outputCompaction: {
62
- ...config.outputCompaction,
63
- compactGitOutput: nextValue,
64
- },
65
- }),
66
- },
67
- {
68
- name: "searchResultGrouping",
69
- description: "Toggle grep/search result grouping",
70
- getValue: (config) => config.outputCompaction.groupSearchOutput,
71
- setValue: (config, nextValue) => ({
72
- ...config,
73
- outputCompaction: {
74
- ...config.outputCompaction,
75
- groupSearchOutput: nextValue,
76
- },
77
- }),
78
- },
79
- {
80
- name: "linterAggregation",
81
- description: "Toggle linter output aggregation",
82
- getValue: (config) => config.outputCompaction.aggregateLinterOutput,
83
- setValue: (config, nextValue) => ({
84
- ...config,
85
- outputCompaction: {
86
- ...config.outputCompaction,
87
- aggregateLinterOutput: nextValue,
88
- },
89
- }),
90
- },
91
- {
92
- name: "truncation",
93
- description: "Toggle output truncation",
94
- getValue: (config) => config.outputCompaction.truncate.enabled,
95
- setValue: (config, nextValue) => ({
96
- ...config,
97
- outputCompaction: {
98
- ...config.outputCompaction,
99
- truncate: {
100
- ...config.outputCompaction.truncate,
101
- enabled: nextValue,
102
- },
103
- },
104
- }),
105
- },
106
- {
107
- name: "sourceCodeFiltering",
108
- description: "Toggle source-code filtering for read output",
109
- getValue: (config) => config.outputCompaction.sourceCodeFilteringEnabled,
110
- setValue: (config, nextValue) => ({
111
- ...config,
112
- outputCompaction: {
113
- ...config.outputCompaction,
114
- sourceCodeFilteringEnabled: nextValue,
115
- },
116
- }),
117
- },
118
- {
119
- name: "smartTruncation",
120
- description: "Toggle smart truncation for read output",
121
- getValue: (config) => config.outputCompaction.smartTruncate.enabled,
122
- setValue: (config, nextValue) => ({
123
- ...config,
124
- outputCompaction: {
125
- ...config.outputCompaction,
126
- smartTruncate: {
127
- ...config.outputCompaction.smartTruncate,
128
- enabled: nextValue,
129
- },
130
- },
131
- }),
132
- },
133
- ];
134
-
135
- function toOnOff(value: boolean): string {
136
- return value ? "enabled" : "disabled";
137
- }
138
-
139
- function buildWhatSummary(config: RtkIntegrationConfig): string {
140
- const output = config.outputCompaction;
141
- return [
142
- `RTK enabled: ${config.enabled}`,
143
- `ansiStripping: ${output.stripAnsi}`,
144
- `truncation: enabled=${output.truncate.enabled}, maxChars=${output.truncate.maxChars}`,
145
- `sourceCodeFiltering: enabled=${output.sourceCodeFilteringEnabled}, level=${output.sourceCodeFiltering}`,
146
- `smartTruncation: enabled=${output.smartTruncate.enabled}, maxLines=${output.smartTruncate.maxLines}`,
147
- `testOutputAggregation: ${output.aggregateTestOutput}`,
148
- `buildOutputFiltering: ${output.filterBuildOutput}`,
149
- `gitCompaction: ${output.compactGitOutput}`,
150
- `searchResultGrouping: ${output.groupSearchOutput}`,
151
- `linterAggregation: ${output.aggregateLinterOutput}`,
152
- ].join("\n");
153
- }
154
-
155
- export function registerRtkCompatCommands(pi: ExtensionAPI, controller: RtkCompatController): void {
156
- pi.registerCommand("rtk-stats", {
157
- description: "Show RTK output compaction metrics",
158
- handler: async (_args, ctx) => {
159
- ctx.ui.notify(controller.getMetricsSummary(), "info");
160
- },
161
- });
162
-
163
- pi.registerCommand("rtk-on", {
164
- description: "Enable RTK integration",
165
- handler: async (_args, ctx) => {
166
- const current = controller.getConfig();
167
- controller.setConfig({ ...current, enabled: true }, ctx);
168
- ctx.ui.notify("RTK integration enabled.", "info");
169
- },
170
- });
171
-
172
- pi.registerCommand("rtk-off", {
173
- description: "Disable RTK integration",
174
- handler: async (_args, ctx) => {
175
- const current = controller.getConfig();
176
- controller.setConfig({ ...current, enabled: false }, ctx);
177
- ctx.ui.notify("RTK integration disabled.", "warning");
178
- },
179
- });
180
-
181
- pi.registerCommand("rtk-clear", {
182
- description: "Clear RTK metrics history",
183
- handler: async (_args, ctx) => {
184
- controller.clearMetrics();
185
- ctx.ui.notify("RTK metrics cleared.", "info");
186
- },
187
- });
188
-
189
- pi.registerCommand("rtk-what", {
190
- description: "Show current RTK integration output settings",
191
- handler: async (_args, ctx) => {
192
- ctx.ui.notify(buildWhatSummary(controller.getConfig()), "info");
193
- },
194
- });
195
-
196
- for (const toggle of BOOLEAN_TOGGLES) {
197
- pi.registerCommand(`rtk-toggle-${toggle.name}`, {
198
- description: toggle.description,
199
- handler: async (_args, ctx) => {
200
- const current = controller.getConfig();
201
- const nextValue = !toggle.getValue(current);
202
- controller.setConfig(toggle.setValue(current, nextValue), ctx);
203
- ctx.ui.notify(`RTK ${toggle.name} ${toOnOff(nextValue)}.`, nextValue ? "info" : "warning");
204
- },
205
- });
206
- }
207
- }