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.
- package/CHANGELOG.md +102 -67
- package/README.md +292 -290
- package/config/config.example.json +36 -35
- package/package.json +4 -4
- package/src/additional-coverage-test.ts +278 -0
- package/src/boolean-format.ts +3 -0
- package/src/command-rewriter-test.ts +160 -120
- package/src/command-rewriter.ts +594 -585
- 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 +410 -289
- package/src/output-compactor-test.ts +500 -158
- package/src/output-compactor.ts +432 -349
- package/src/record-utils.ts +6 -0
- package/src/rewrite-bypass.ts +332 -173
- package/src/rewrite-pipeline-safety.ts +154 -0
- package/src/rewrite-rules.ts +255 -255
- package/src/rtk-command-environment.ts +64 -0
- package/src/runtime-guard-test.ts +42 -50
- package/src/runtime-guard.ts +14 -14
- package/src/techniques/build.ts +155 -155
- package/src/techniques/emoji.ts +91 -0
- package/src/techniques/git.ts +231 -229
- package/src/techniques/index.ts +10 -16
- package/src/techniques/linter.ts +151 -161
- package/src/techniques/path-utils.ts +67 -0
- package/src/techniques/rtk.ts +136 -0
- package/src/techniques/search.ts +67 -76
- package/src/techniques/source.ts +253 -253
- package/src/techniques/test-output.ts +172 -172
- package/src/test-helpers.ts +10 -0
- package/src/tool-execution-sanitizer.ts +69 -0
- package/src/types-shims.d.ts +192 -183
- package/src/types.ts +103 -114
- package/src/zellij-modal.ts +1001 -1001
- package/src/compat-commands.ts +0 -207
package/src/techniques/git.ts
CHANGED
|
@@ -1,229 +1,231 @@
|
|
|
1
|
-
import { matchesCommandPatterns, normalizeCommandForDetection } from "./command-detection.js";
|
|
2
|
-
|
|
3
|
-
const GIT_COMMAND_PATTERNS = [/^git\s+(diff|status|log|show|stash)\b/] as const;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
let
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
result.push(line);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
import { matchesCommandPatterns, normalizeCommandForDetection } from "./command-detection.js";
|
|
2
|
+
|
|
3
|
+
const GIT_COMMAND_PATTERNS = [/^git\s+(diff|status|log|show|stash)\b/] as const;
|
|
4
|
+
const RAW_GIT_DIFF_PATTERN = /^diff --git /m;
|
|
5
|
+
const RAW_GIT_STATUS_PATTERN = /^(?:## |(?:M|A|D|R|C|U|\?| )\S)/m;
|
|
6
|
+
|
|
7
|
+
export function isGitCommand(command: string | undefined | null): boolean {
|
|
8
|
+
return matchesCommandPatterns(command, GIT_COMMAND_PATTERNS);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function compactDiff(output: string, maxLines = 50): string {
|
|
12
|
+
const lines = output.split("\n");
|
|
13
|
+
const result: string[] = [];
|
|
14
|
+
let currentFile = "";
|
|
15
|
+
let added = 0;
|
|
16
|
+
let removed = 0;
|
|
17
|
+
let inHunk = false;
|
|
18
|
+
let hunkLines = 0;
|
|
19
|
+
const maxHunkLines = 10;
|
|
20
|
+
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
if (result.length >= maxLines) {
|
|
23
|
+
result.push("\n... (more changes truncated)");
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (line.startsWith("diff --git")) {
|
|
28
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
29
|
+
result.push(` +${added} -${removed}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const match = line.match(/diff --git a\/(.+) b\/(.+)/);
|
|
33
|
+
currentFile = match?.[2] ?? "unknown";
|
|
34
|
+
result.push(`\n> ${currentFile}`);
|
|
35
|
+
added = 0;
|
|
36
|
+
removed = 0;
|
|
37
|
+
inHunk = false;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (line.startsWith("@@")) {
|
|
42
|
+
inHunk = true;
|
|
43
|
+
hunkLines = 0;
|
|
44
|
+
const hunkInfo = line.match(/@@ .+ @@/)?.[0] ?? "@@";
|
|
45
|
+
result.push(` ${hunkInfo}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!inHunk) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
54
|
+
added++;
|
|
55
|
+
if (hunkLines < maxHunkLines) {
|
|
56
|
+
result.push(` ${line}`);
|
|
57
|
+
hunkLines++;
|
|
58
|
+
}
|
|
59
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
60
|
+
removed++;
|
|
61
|
+
if (hunkLines < maxHunkLines) {
|
|
62
|
+
result.push(` ${line}`);
|
|
63
|
+
hunkLines++;
|
|
64
|
+
}
|
|
65
|
+
} else if (hunkLines < maxHunkLines && !line.startsWith("\\")) {
|
|
66
|
+
if (hunkLines > 0) {
|
|
67
|
+
result.push(` ${line}`);
|
|
68
|
+
hunkLines++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (hunkLines === maxHunkLines) {
|
|
73
|
+
result.push(" ... (truncated)");
|
|
74
|
+
hunkLines++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
79
|
+
result.push(` +${added} -${removed}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return result.join("\n");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface StatusStats {
|
|
86
|
+
staged: number;
|
|
87
|
+
modified: number;
|
|
88
|
+
untracked: number;
|
|
89
|
+
conflicts: number;
|
|
90
|
+
stagedFiles: string[];
|
|
91
|
+
modifiedFiles: string[];
|
|
92
|
+
untrackedFiles: string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function compactStatus(output: string): string {
|
|
96
|
+
const lines = output.split("\n");
|
|
97
|
+
|
|
98
|
+
if (lines.length === 0 || (lines.length === 1 && lines[0]?.trim() === "")) {
|
|
99
|
+
return "Clean working tree";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const stats: StatusStats = {
|
|
103
|
+
staged: 0,
|
|
104
|
+
modified: 0,
|
|
105
|
+
untracked: 0,
|
|
106
|
+
conflicts: 0,
|
|
107
|
+
stagedFiles: [],
|
|
108
|
+
modifiedFiles: [],
|
|
109
|
+
untrackedFiles: [],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
let branchName = "";
|
|
113
|
+
|
|
114
|
+
for (const line of lines) {
|
|
115
|
+
if (line.startsWith("##")) {
|
|
116
|
+
const match = line.match(/## (.+)/);
|
|
117
|
+
if (match?.[1]) {
|
|
118
|
+
branchName = match[1].split("...")[0] ?? match[1];
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (line.length < 3) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const status = line.slice(0, 2);
|
|
128
|
+
const filename = line.slice(3);
|
|
129
|
+
const indexStatus = status[0];
|
|
130
|
+
const worktreeStatus = status[1];
|
|
131
|
+
|
|
132
|
+
if (["M", "A", "D", "R", "C"].includes(indexStatus)) {
|
|
133
|
+
stats.staged++;
|
|
134
|
+
stats.stagedFiles.push(filename);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (indexStatus === "U") {
|
|
138
|
+
stats.conflicts++;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (["M", "D"].includes(worktreeStatus)) {
|
|
142
|
+
stats.modified++;
|
|
143
|
+
stats.modifiedFiles.push(filename);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (status === "??") {
|
|
147
|
+
stats.untracked++;
|
|
148
|
+
stats.untrackedFiles.push(filename);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let result = `Branch: ${branchName}\n`;
|
|
153
|
+
|
|
154
|
+
if (stats.staged > 0) {
|
|
155
|
+
result += `Staged: ${stats.staged} files\n`;
|
|
156
|
+
for (const file of stats.stagedFiles.slice(0, 5)) {
|
|
157
|
+
result += ` ${file}\n`;
|
|
158
|
+
}
|
|
159
|
+
if (stats.staged > 5) {
|
|
160
|
+
result += ` ... +${stats.staged - 5} more\n`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (stats.modified > 0) {
|
|
165
|
+
result += `Modified: ${stats.modified} files\n`;
|
|
166
|
+
for (const file of stats.modifiedFiles.slice(0, 5)) {
|
|
167
|
+
result += ` ${file}\n`;
|
|
168
|
+
}
|
|
169
|
+
if (stats.modified > 5) {
|
|
170
|
+
result += ` ... +${stats.modified - 5} more\n`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (stats.untracked > 0) {
|
|
175
|
+
result += `Untracked: ${stats.untracked} files\n`;
|
|
176
|
+
for (const file of stats.untrackedFiles.slice(0, 3)) {
|
|
177
|
+
result += ` ${file}\n`;
|
|
178
|
+
}
|
|
179
|
+
if (stats.untracked > 3) {
|
|
180
|
+
result += ` ... +${stats.untracked - 3} more\n`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (stats.conflicts > 0) {
|
|
185
|
+
result += `Conflicts: ${stats.conflicts} files\n`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return result.trim();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function compactLog(output: string, limit = 20): string {
|
|
192
|
+
const lines = output.split("\n");
|
|
193
|
+
const result: string[] = [];
|
|
194
|
+
|
|
195
|
+
for (const line of lines.slice(0, limit)) {
|
|
196
|
+
if (line.length > 80) {
|
|
197
|
+
result.push(`${line.slice(0, 77)}...`);
|
|
198
|
+
} else {
|
|
199
|
+
result.push(line);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (lines.length > limit) {
|
|
204
|
+
result.push(`... and ${lines.length - limit} more commits`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return result.join("\n");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function compactGitOutput(output: string, command: string | undefined | null): string | null {
|
|
211
|
+
if (!isGitCommand(command)) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const normalized = normalizeCommandForDetection(command);
|
|
216
|
+
if (!normalized) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (normalized.startsWith("git diff")) {
|
|
221
|
+
return RAW_GIT_DIFF_PATTERN.test(output) ? compactDiff(output) : null;
|
|
222
|
+
}
|
|
223
|
+
if (normalized.startsWith("git status")) {
|
|
224
|
+
return RAW_GIT_STATUS_PATTERN.test(output) ? compactStatus(output) : null;
|
|
225
|
+
}
|
|
226
|
+
if (normalized.startsWith("git log")) {
|
|
227
|
+
return compactLog(output);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return null;
|
|
231
|
+
}
|
package/src/techniques/index.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { truncate } from "./truncate.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
filterSourceCode,
|
|
12
|
-
type Language,
|
|
13
|
-
} from "./source.js";
|
|
14
|
-
export { compactDiff, compactStatus, compactLog, compactGitOutput, isGitCommand } from "./git.js";
|
|
15
|
-
export { groupSearchResults } from "./search.js";
|
|
16
|
-
export { normalizeCommandForDetection, matchesCommandPatterns } from "./command-detection.js";
|
|
1
|
+
export { stripAnsiFast } from "./ansi.js";
|
|
2
|
+
export { truncate } from "./truncate.js";
|
|
3
|
+
export { sanitizeRtkEmojiOutput } from "./emoji.js";
|
|
4
|
+
export { filterBuildOutput } from "./build.js";
|
|
5
|
+
export { aggregateTestOutput } from "./test-output.js";
|
|
6
|
+
export { aggregateLinterOutput } from "./linter.js";
|
|
7
|
+
export { detectLanguage, smartTruncate, filterSourceCode } from "./source.js";
|
|
8
|
+
export { compactGitOutput } from "./git.js";
|
|
9
|
+
export { groupSearchResults } from "./search.js";
|
|
10
|
+
export { stripRtkHookWarnings } from "./rtk.js";
|