pi-rtk-optimizer 0.3.2 → 0.4.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 +83 -49
- package/README.md +292 -283
- package/config/config.example.json +36 -35
- package/package.json +60 -59
- package/src/additional-coverage-test.ts +197 -0
- package/src/boolean-format.ts +3 -0
- package/src/command-rewriter-test.ts +160 -0
- package/src/command-rewriter.ts +594 -349
- package/src/config-modal-test.ts +168 -0
- package/src/config-modal.ts +613 -600
- package/src/config-store.ts +224 -217
- package/src/index-test.ts +54 -0
- package/src/index.ts +320 -291
- package/src/output-compactor-test.ts +334 -120
- package/src/output-compactor.ts +418 -343
- package/src/record-utils.ts +6 -0
- package/src/rewrite-bypass.ts +332 -0
- package/src/rewrite-pipeline-safety.ts +154 -0
- package/src/rewrite-rules.ts +255 -248
- package/src/runtime-guard-test.ts +42 -0
- package/src/runtime-guard.ts +14 -0
- package/src/techniques/build.ts +155 -155
- package/src/techniques/git.ts +229 -229
- package/src/techniques/index.ts +8 -16
- package/src/techniques/linter.ts +151 -161
- package/src/techniques/path-utils.ts +67 -0
- package/src/techniques/search.ts +67 -76
- package/src/techniques/source.ts +253 -230
- package/src/techniques/test-output.ts +172 -172
- package/src/test-helpers.ts +10 -0
- package/src/types-shims.d.ts +189 -131
- package/src/types.ts +103 -114
- package/src/compat-commands.ts +0 -207
package/src/types.ts
CHANGED
|
@@ -1,114 +1,103 @@
|
|
|
1
|
-
export const RTK_MODES = ["rewrite", "suggest"] as const;
|
|
2
|
-
export const RTK_SOURCE_FILTER_LEVELS = ["none", "minimal", "aggressive"] as const;
|
|
3
|
-
|
|
4
|
-
export type RtkMode = (typeof RTK_MODES)[number];
|
|
5
|
-
export type RtkSourceFilterLevel = (typeof RTK_SOURCE_FILTER_LEVELS)[number];
|
|
6
|
-
|
|
7
|
-
export interface RtkOutputCompactionConfig {
|
|
8
|
-
enabled: boolean;
|
|
9
|
-
stripAnsi: boolean;
|
|
10
|
-
truncate: {
|
|
11
|
-
enabled: boolean;
|
|
12
|
-
maxChars: number;
|
|
13
|
-
};
|
|
14
|
-
sourceCodeFilteringEnabled: boolean;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"files",
|
|
105
|
-
"rust",
|
|
106
|
-
"js",
|
|
107
|
-
"python",
|
|
108
|
-
"go",
|
|
109
|
-
"containers",
|
|
110
|
-
"network",
|
|
111
|
-
"packages",
|
|
112
|
-
] as const;
|
|
113
|
-
|
|
114
|
-
export type RtkCategoryKey = (typeof RTK_CATEGORY_KEYS)[number];
|
|
1
|
+
export const RTK_MODES = ["rewrite", "suggest"] as const;
|
|
2
|
+
export const RTK_SOURCE_FILTER_LEVELS = ["none", "minimal", "aggressive"] as const;
|
|
3
|
+
|
|
4
|
+
export type RtkMode = (typeof RTK_MODES)[number];
|
|
5
|
+
export type RtkSourceFilterLevel = (typeof RTK_SOURCE_FILTER_LEVELS)[number];
|
|
6
|
+
|
|
7
|
+
export interface RtkOutputCompactionConfig {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
stripAnsi: boolean;
|
|
10
|
+
truncate: {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
maxChars: number;
|
|
13
|
+
};
|
|
14
|
+
sourceCodeFilteringEnabled: boolean;
|
|
15
|
+
preserveExactSkillReads: boolean;
|
|
16
|
+
sourceCodeFiltering: RtkSourceFilterLevel;
|
|
17
|
+
smartTruncate: {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
maxLines: number;
|
|
20
|
+
};
|
|
21
|
+
aggregateTestOutput: boolean;
|
|
22
|
+
filterBuildOutput: boolean;
|
|
23
|
+
compactGitOutput: boolean;
|
|
24
|
+
aggregateLinterOutput: boolean;
|
|
25
|
+
groupSearchOutput: boolean;
|
|
26
|
+
trackSavings: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RtkIntegrationConfig {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
mode: RtkMode;
|
|
32
|
+
guardWhenRtkMissing: boolean;
|
|
33
|
+
showRewriteNotifications: boolean;
|
|
34
|
+
rewriteGitGithub: boolean;
|
|
35
|
+
rewriteFilesystem: boolean;
|
|
36
|
+
rewriteRust: boolean;
|
|
37
|
+
rewriteJavaScript: boolean;
|
|
38
|
+
rewritePython: boolean;
|
|
39
|
+
rewriteGo: boolean;
|
|
40
|
+
rewriteContainers: boolean;
|
|
41
|
+
rewriteNetwork: boolean;
|
|
42
|
+
rewritePackageManagers: boolean;
|
|
43
|
+
outputCompaction: RtkOutputCompactionConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const DEFAULT_RTK_INTEGRATION_CONFIG: RtkIntegrationConfig = {
|
|
47
|
+
enabled: true,
|
|
48
|
+
mode: "rewrite",
|
|
49
|
+
guardWhenRtkMissing: true,
|
|
50
|
+
showRewriteNotifications: true,
|
|
51
|
+
rewriteGitGithub: true,
|
|
52
|
+
rewriteFilesystem: true,
|
|
53
|
+
rewriteRust: true,
|
|
54
|
+
rewriteJavaScript: true,
|
|
55
|
+
rewritePython: true,
|
|
56
|
+
rewriteGo: true,
|
|
57
|
+
rewriteContainers: true,
|
|
58
|
+
rewriteNetwork: true,
|
|
59
|
+
rewritePackageManagers: true,
|
|
60
|
+
outputCompaction: {
|
|
61
|
+
enabled: true,
|
|
62
|
+
stripAnsi: true,
|
|
63
|
+
truncate: {
|
|
64
|
+
enabled: true,
|
|
65
|
+
maxChars: 12_000,
|
|
66
|
+
},
|
|
67
|
+
sourceCodeFilteringEnabled: true,
|
|
68
|
+
preserveExactSkillReads: false,
|
|
69
|
+
sourceCodeFiltering: "minimal",
|
|
70
|
+
smartTruncate: {
|
|
71
|
+
enabled: true,
|
|
72
|
+
maxLines: 220,
|
|
73
|
+
},
|
|
74
|
+
aggregateTestOutput: true,
|
|
75
|
+
filterBuildOutput: true,
|
|
76
|
+
compactGitOutput: true,
|
|
77
|
+
aggregateLinterOutput: true,
|
|
78
|
+
groupSearchOutput: true,
|
|
79
|
+
trackSavings: true,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export interface ConfigLoadResult {
|
|
84
|
+
config: RtkIntegrationConfig;
|
|
85
|
+
warning?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ConfigSaveResult {
|
|
89
|
+
success: boolean;
|
|
90
|
+
error?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface EnsureConfigResult {
|
|
94
|
+
created: boolean;
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface RuntimeStatus {
|
|
99
|
+
rtkAvailable: boolean;
|
|
100
|
+
lastCheckedAt?: number;
|
|
101
|
+
lastError?: string;
|
|
102
|
+
}
|
|
103
|
+
|
package/src/compat-commands.ts
DELETED
|
@@ -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
|
-
}
|