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