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/config-modal.ts
CHANGED
|
@@ -1,600 +1,613 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
import type { SettingItem } from "@mariozechner/pi-tui";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
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
|
-
config.
|
|
62
|
-
config.
|
|
63
|
-
config.
|
|
64
|
-
config.
|
|
65
|
-
config.
|
|
66
|
-
config.
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
case "
|
|
282
|
-
return { ...config,
|
|
283
|
-
case "
|
|
284
|
-
return { ...config,
|
|
285
|
-
case "
|
|
286
|
-
return {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
...config,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
...config,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return {
|
|
351
|
-
...config,
|
|
352
|
-
outputCompaction: {
|
|
353
|
-
...config.outputCompaction,
|
|
354
|
-
smartTruncate: {
|
|
355
|
-
...config.outputCompaction.smartTruncate,
|
|
356
|
-
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return {
|
|
363
|
-
...config,
|
|
364
|
-
outputCompaction: {
|
|
365
|
-
...config.outputCompaction,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
case "
|
|
414
|
-
return {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
case "
|
|
422
|
-
return { ...config,
|
|
423
|
-
case "
|
|
424
|
-
return { ...config,
|
|
425
|
-
case "
|
|
426
|
-
return { ...config,
|
|
427
|
-
|
|
428
|
-
return config;
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
settingsList.updateValue("
|
|
446
|
-
settingsList.updateValue("
|
|
447
|
-
settingsList.updateValue("
|
|
448
|
-
settingsList.updateValue("
|
|
449
|
-
settingsList.updateValue("
|
|
450
|
-
settingsList.updateValue("
|
|
451
|
-
settingsList.updateValue("
|
|
452
|
-
settingsList.updateValue("
|
|
453
|
-
settingsList.updateValue("
|
|
454
|
-
settingsList.updateValue("
|
|
455
|
-
settingsList.updateValue("
|
|
456
|
-
settingsList.updateValue("
|
|
457
|
-
settingsList.updateValue("
|
|
458
|
-
settingsList.updateValue("
|
|
459
|
-
settingsList.updateValue("
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
)
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (normalized === "
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import type { SettingItem } from "@mariozechner/pi-tui";
|
|
3
|
+
import { toOnOff } from "./boolean-format.js";
|
|
4
|
+
import { ZellijModal, ZellijSettingsModal } from "./zellij-modal.js";
|
|
5
|
+
import { getRtkArgumentCompletions } from "./command-completions.js";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_RTK_INTEGRATION_CONFIG,
|
|
8
|
+
RTK_SOURCE_FILTER_LEVELS,
|
|
9
|
+
type RtkIntegrationConfig,
|
|
10
|
+
type RuntimeStatus,
|
|
11
|
+
} from "./types.js";
|
|
12
|
+
|
|
13
|
+
interface RtkIntegrationController {
|
|
14
|
+
getConfig(): RtkIntegrationConfig;
|
|
15
|
+
setConfig(next: RtkIntegrationConfig, ctx: ExtensionCommandContext): void;
|
|
16
|
+
getConfigPath(): string;
|
|
17
|
+
getRuntimeStatus(): RuntimeStatus;
|
|
18
|
+
refreshRuntimeStatus(): Promise<RuntimeStatus>;
|
|
19
|
+
getMetricsSummary(): string;
|
|
20
|
+
clearMetrics(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface SettingValueSyncTarget {
|
|
24
|
+
updateValue(id: string, value: string): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ON_OFF = ["on", "off"];
|
|
28
|
+
const MODE_VALUES = ["rewrite", "suggest"];
|
|
29
|
+
const SOURCE_FILTER_VALUES = [...RTK_SOURCE_FILTER_LEVELS];
|
|
30
|
+
const TRUNCATE_MAX_CHAR_VALUES = ["4000", "8000", "12000", "20000", "50000", "100000", "200000"];
|
|
31
|
+
const SMART_TRUNCATE_LINE_VALUES = ["40", "80", "120", "160", "220", "320", "500", "1000", "2000", "4000"];
|
|
32
|
+
const RTK_USAGE_TEXT =
|
|
33
|
+
"Usage: /rtk [show|path|verify|stats|clear-stats|reset|help] (or run /rtk with no args to open settings modal)";
|
|
34
|
+
|
|
35
|
+
function parseSourceFilterLevel(
|
|
36
|
+
value: string,
|
|
37
|
+
): RtkIntegrationConfig["outputCompaction"]["sourceCodeFiltering"] | undefined {
|
|
38
|
+
return SOURCE_FILTER_VALUES.includes(value as (typeof SOURCE_FILTER_VALUES)[number])
|
|
39
|
+
? (value as RtkIntegrationConfig["outputCompaction"]["sourceCodeFiltering"])
|
|
40
|
+
: undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseIntegerInRange(value: string, min: number, max: number): number | undefined {
|
|
44
|
+
if (!/^\d+$/.test(value)) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const parsed = Number.parseInt(value, 10);
|
|
49
|
+
if (!Number.isFinite(parsed) || parsed < min || parsed > max) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function summarizeConfig(config: RtkIntegrationConfig, runtimeStatus: RuntimeStatus): string {
|
|
57
|
+
const categories = [
|
|
58
|
+
config.rewriteGitGithub ? "git" : "",
|
|
59
|
+
config.rewriteFilesystem ? "files" : "",
|
|
60
|
+
config.rewriteRust ? "rust" : "",
|
|
61
|
+
config.rewriteJavaScript ? "js" : "",
|
|
62
|
+
config.rewritePython ? "python" : "",
|
|
63
|
+
config.rewriteGo ? "go" : "",
|
|
64
|
+
config.rewriteContainers ? "containers" : "",
|
|
65
|
+
config.rewriteNetwork ? "network" : "",
|
|
66
|
+
config.rewritePackageManagers ? "packages" : "",
|
|
67
|
+
]
|
|
68
|
+
.filter((value) => value.length > 0)
|
|
69
|
+
.join(",");
|
|
70
|
+
|
|
71
|
+
const runtime = runtimeStatus.rtkAvailable
|
|
72
|
+
? "rtk=available"
|
|
73
|
+
: `rtk=missing${runtimeStatus.lastError ? ` (${runtimeStatus.lastError})` : ""}`;
|
|
74
|
+
|
|
75
|
+
return `enabled=${config.enabled}, mode=${config.mode}, rewriteNotice=${config.showRewriteNotifications}, compaction=${config.outputCompaction.enabled}, sourceFilterEnabled=${config.outputCompaction.sourceCodeFilteringEnabled}, preserveSkillReads=${config.outputCompaction.preserveExactSkillReads}, sourceFilter=${config.outputCompaction.sourceCodeFiltering}, categories=[${categories || "none"}], ${runtime}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildSettingItems(config: RtkIntegrationConfig): SettingItem[] {
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
id: "enabled",
|
|
82
|
+
label: "RTK integration enabled",
|
|
83
|
+
description: "Master switch for rewrite, suggestions, and output compaction",
|
|
84
|
+
currentValue: toOnOff(config.enabled),
|
|
85
|
+
values: ON_OFF,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "mode",
|
|
89
|
+
label: "Rewrite mode",
|
|
90
|
+
description: "rewrite = auto-rewrite bash commands, suggest = notify only",
|
|
91
|
+
currentValue: config.mode,
|
|
92
|
+
values: MODE_VALUES,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "showRewriteNotifications",
|
|
96
|
+
label: "Show rewrite notifications",
|
|
97
|
+
description: "Show 'RTK rewrite: old -> new' notice in TUI",
|
|
98
|
+
currentValue: toOnOff(config.showRewriteNotifications),
|
|
99
|
+
values: ON_OFF,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "guardWhenRtkMissing",
|
|
103
|
+
label: "Guard when rtk missing",
|
|
104
|
+
description: "If on, raw commands run unchanged when rtk binary is unavailable",
|
|
105
|
+
currentValue: toOnOff(config.guardWhenRtkMissing),
|
|
106
|
+
values: ON_OFF,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "outputCompactionEnabled",
|
|
110
|
+
label: "Output compaction enabled",
|
|
111
|
+
description: "Compact bash/read/grep tool results to reduce token usage",
|
|
112
|
+
currentValue: toOnOff(config.outputCompaction.enabled),
|
|
113
|
+
values: ON_OFF,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: "outputStripAnsi",
|
|
117
|
+
label: "Strip ANSI in output",
|
|
118
|
+
description: "Remove color/control codes from tool output before further compaction",
|
|
119
|
+
currentValue: toOnOff(config.outputCompaction.stripAnsi),
|
|
120
|
+
values: ON_OFF,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "outputTruncateEnabled",
|
|
124
|
+
label: "Hard truncation enabled",
|
|
125
|
+
description: "Apply max character cap after other compaction techniques",
|
|
126
|
+
currentValue: toOnOff(config.outputCompaction.truncate.enabled),
|
|
127
|
+
values: ON_OFF,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "outputTruncateMaxChars",
|
|
131
|
+
label: "Hard truncation max chars",
|
|
132
|
+
description: "Maximum characters kept when hard truncation is enabled",
|
|
133
|
+
currentValue: String(config.outputCompaction.truncate.maxChars),
|
|
134
|
+
values: TRUNCATE_MAX_CHAR_VALUES,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "outputSourceFilteringEnabled",
|
|
138
|
+
label: "Read source filtering enabled",
|
|
139
|
+
description: "If off, read output skips source-code filtering regardless of selected level",
|
|
140
|
+
currentValue: toOnOff(config.outputCompaction.sourceCodeFilteringEnabled),
|
|
141
|
+
values: ON_OFF,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "outputPreserveExactSkillReads",
|
|
145
|
+
label: "Preserve exact skill reads",
|
|
146
|
+
description: "If on, read results under ~/.pi/agent/skills, ~/.agents/skills, .pi/skills, and ancestor .agents/skills skip read compaction",
|
|
147
|
+
currentValue: toOnOff(config.outputCompaction.preserveExactSkillReads),
|
|
148
|
+
values: ON_OFF,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "outputSourceFiltering",
|
|
152
|
+
label: "Read source filtering",
|
|
153
|
+
description: "none|minimal|aggressive for read output compaction",
|
|
154
|
+
currentValue: config.outputCompaction.sourceCodeFiltering,
|
|
155
|
+
values: SOURCE_FILTER_VALUES,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "outputSmartTruncate",
|
|
159
|
+
label: "Read smart truncation",
|
|
160
|
+
description: "Keep signatures/imports when read output has many lines",
|
|
161
|
+
currentValue: toOnOff(config.outputCompaction.smartTruncate.enabled),
|
|
162
|
+
values: ON_OFF,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "outputSmartTruncateMaxLines",
|
|
166
|
+
label: "Read smart truncation max lines",
|
|
167
|
+
description: "Target max lines for smart truncation in read outputs",
|
|
168
|
+
currentValue: String(config.outputCompaction.smartTruncate.maxLines),
|
|
169
|
+
values: SMART_TRUNCATE_LINE_VALUES,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: "outputAggregateTestOutput",
|
|
173
|
+
label: "Aggregate test output",
|
|
174
|
+
description: "Summarize test command output to failures and key totals",
|
|
175
|
+
currentValue: toOnOff(config.outputCompaction.aggregateTestOutput),
|
|
176
|
+
values: ON_OFF,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "outputFilterBuildOutput",
|
|
180
|
+
label: "Filter build output",
|
|
181
|
+
description: "Reduce build noise and keep key error/warning lines",
|
|
182
|
+
currentValue: toOnOff(config.outputCompaction.filterBuildOutput),
|
|
183
|
+
values: ON_OFF,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: "outputCompactGitOutput",
|
|
187
|
+
label: "Compact git output",
|
|
188
|
+
description: "Condense git command output for lower token usage",
|
|
189
|
+
currentValue: toOnOff(config.outputCompaction.compactGitOutput),
|
|
190
|
+
values: ON_OFF,
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "outputAggregateLinterOutput",
|
|
194
|
+
label: "Aggregate linter output",
|
|
195
|
+
description: "Summarize linter output by file and issue type",
|
|
196
|
+
currentValue: toOnOff(config.outputCompaction.aggregateLinterOutput),
|
|
197
|
+
values: ON_OFF,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "outputGroupSearchOutput",
|
|
201
|
+
label: "Group search output",
|
|
202
|
+
description: "Group grep/search matches by file with counts",
|
|
203
|
+
currentValue: toOnOff(config.outputCompaction.groupSearchOutput),
|
|
204
|
+
values: ON_OFF,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "outputTrackSavings",
|
|
208
|
+
label: "Track output savings",
|
|
209
|
+
description: "Collect in-session compaction metrics for /rtk stats",
|
|
210
|
+
currentValue: toOnOff(config.outputCompaction.trackSavings),
|
|
211
|
+
values: ON_OFF,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "rewriteGitGithub",
|
|
215
|
+
label: "Rewrite git / gh",
|
|
216
|
+
description: "git status/log/diff and gh pr/issue/run/api/release",
|
|
217
|
+
currentValue: toOnOff(config.rewriteGitGithub),
|
|
218
|
+
values: ON_OFF,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: "rewriteFilesystem",
|
|
222
|
+
label: "Rewrite filesystem commands",
|
|
223
|
+
description: "cat, head, rg/grep, ls, tree, find, diff",
|
|
224
|
+
currentValue: toOnOff(config.rewriteFilesystem),
|
|
225
|
+
values: ON_OFF,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "rewriteRust",
|
|
229
|
+
label: "Rewrite Rust commands",
|
|
230
|
+
description: "cargo test/build/clippy/check/install/nextest/fmt",
|
|
231
|
+
currentValue: toOnOff(config.rewriteRust),
|
|
232
|
+
values: ON_OFF,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "rewriteJavaScript",
|
|
236
|
+
label: "Rewrite JavaScript/TypeScript",
|
|
237
|
+
description: "vitest, npm/npx/next, tsc, lint, prettier, playwright, prisma",
|
|
238
|
+
currentValue: toOnOff(config.rewriteJavaScript),
|
|
239
|
+
values: ON_OFF,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: "rewritePython",
|
|
243
|
+
label: "Rewrite Python",
|
|
244
|
+
description: "pytest, ruff, pip, uv pip",
|
|
245
|
+
currentValue: toOnOff(config.rewritePython),
|
|
246
|
+
values: ON_OFF,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
id: "rewriteGo",
|
|
250
|
+
label: "Rewrite Go",
|
|
251
|
+
description: "go test/build/vet and golangci-lint",
|
|
252
|
+
currentValue: toOnOff(config.rewriteGo),
|
|
253
|
+
values: ON_OFF,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "rewriteContainers",
|
|
257
|
+
label: "Rewrite containers",
|
|
258
|
+
description: "docker compose/ps/images/logs/run/build/exec and kubectl core ops",
|
|
259
|
+
currentValue: toOnOff(config.rewriteContainers),
|
|
260
|
+
values: ON_OFF,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "rewriteNetwork",
|
|
264
|
+
label: "Rewrite network",
|
|
265
|
+
description: "curl and wget",
|
|
266
|
+
currentValue: toOnOff(config.rewriteNetwork),
|
|
267
|
+
values: ON_OFF,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: "rewritePackageManagers",
|
|
271
|
+
label: "Rewrite package managers",
|
|
272
|
+
description: "pnpm list/ls/outdated/build/typecheck and npm list/outdated",
|
|
273
|
+
currentValue: toOnOff(config.rewritePackageManagers),
|
|
274
|
+
values: ON_OFF,
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function applySetting(config: RtkIntegrationConfig, id: string, value: string): RtkIntegrationConfig {
|
|
280
|
+
switch (id) {
|
|
281
|
+
case "enabled":
|
|
282
|
+
return { ...config, enabled: value === "on" };
|
|
283
|
+
case "mode":
|
|
284
|
+
return { ...config, mode: value === "suggest" ? "suggest" : "rewrite" };
|
|
285
|
+
case "showRewriteNotifications":
|
|
286
|
+
return { ...config, showRewriteNotifications: value === "on" };
|
|
287
|
+
case "guardWhenRtkMissing":
|
|
288
|
+
return { ...config, guardWhenRtkMissing: value === "on" };
|
|
289
|
+
case "outputCompactionEnabled":
|
|
290
|
+
return {
|
|
291
|
+
...config,
|
|
292
|
+
outputCompaction: { ...config.outputCompaction, enabled: value === "on" },
|
|
293
|
+
};
|
|
294
|
+
case "outputStripAnsi":
|
|
295
|
+
return {
|
|
296
|
+
...config,
|
|
297
|
+
outputCompaction: { ...config.outputCompaction, stripAnsi: value === "on" },
|
|
298
|
+
};
|
|
299
|
+
case "outputTruncateEnabled":
|
|
300
|
+
return {
|
|
301
|
+
...config,
|
|
302
|
+
outputCompaction: {
|
|
303
|
+
...config.outputCompaction,
|
|
304
|
+
truncate: {
|
|
305
|
+
...config.outputCompaction.truncate,
|
|
306
|
+
enabled: value === "on",
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
case "outputTruncateMaxChars": {
|
|
311
|
+
const parsed = parseIntegerInRange(value, 1_000, 200_000);
|
|
312
|
+
return {
|
|
313
|
+
...config,
|
|
314
|
+
outputCompaction: {
|
|
315
|
+
...config.outputCompaction,
|
|
316
|
+
truncate: {
|
|
317
|
+
...config.outputCompaction.truncate,
|
|
318
|
+
maxChars: parsed ?? config.outputCompaction.truncate.maxChars,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
case "outputSourceFilteringEnabled":
|
|
324
|
+
return {
|
|
325
|
+
...config,
|
|
326
|
+
outputCompaction: {
|
|
327
|
+
...config.outputCompaction,
|
|
328
|
+
sourceCodeFilteringEnabled: value === "on",
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
case "outputPreserveExactSkillReads":
|
|
332
|
+
return {
|
|
333
|
+
...config,
|
|
334
|
+
outputCompaction: {
|
|
335
|
+
...config.outputCompaction,
|
|
336
|
+
preserveExactSkillReads: value === "on",
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
case "outputSourceFiltering": {
|
|
340
|
+
const parsedValue = parseSourceFilterLevel(value);
|
|
341
|
+
return {
|
|
342
|
+
...config,
|
|
343
|
+
outputCompaction: {
|
|
344
|
+
...config.outputCompaction,
|
|
345
|
+
sourceCodeFiltering: parsedValue ?? config.outputCompaction.sourceCodeFiltering,
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
case "outputSmartTruncate":
|
|
350
|
+
return {
|
|
351
|
+
...config,
|
|
352
|
+
outputCompaction: {
|
|
353
|
+
...config.outputCompaction,
|
|
354
|
+
smartTruncate: {
|
|
355
|
+
...config.outputCompaction.smartTruncate,
|
|
356
|
+
enabled: value === "on",
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
case "outputSmartTruncateMaxLines": {
|
|
361
|
+
const parsed = parseIntegerInRange(value, 40, 4_000);
|
|
362
|
+
return {
|
|
363
|
+
...config,
|
|
364
|
+
outputCompaction: {
|
|
365
|
+
...config.outputCompaction,
|
|
366
|
+
smartTruncate: {
|
|
367
|
+
...config.outputCompaction.smartTruncate,
|
|
368
|
+
maxLines: parsed ?? config.outputCompaction.smartTruncate.maxLines,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
case "outputAggregateTestOutput":
|
|
374
|
+
return {
|
|
375
|
+
...config,
|
|
376
|
+
outputCompaction: {
|
|
377
|
+
...config.outputCompaction,
|
|
378
|
+
aggregateTestOutput: value === "on",
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
case "outputFilterBuildOutput":
|
|
382
|
+
return {
|
|
383
|
+
...config,
|
|
384
|
+
outputCompaction: {
|
|
385
|
+
...config.outputCompaction,
|
|
386
|
+
filterBuildOutput: value === "on",
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
case "outputCompactGitOutput":
|
|
390
|
+
return {
|
|
391
|
+
...config,
|
|
392
|
+
outputCompaction: {
|
|
393
|
+
...config.outputCompaction,
|
|
394
|
+
compactGitOutput: value === "on",
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
case "outputAggregateLinterOutput":
|
|
398
|
+
return {
|
|
399
|
+
...config,
|
|
400
|
+
outputCompaction: {
|
|
401
|
+
...config.outputCompaction,
|
|
402
|
+
aggregateLinterOutput: value === "on",
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
case "outputGroupSearchOutput":
|
|
406
|
+
return {
|
|
407
|
+
...config,
|
|
408
|
+
outputCompaction: {
|
|
409
|
+
...config.outputCompaction,
|
|
410
|
+
groupSearchOutput: value === "on",
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
case "outputTrackSavings":
|
|
414
|
+
return {
|
|
415
|
+
...config,
|
|
416
|
+
outputCompaction: {
|
|
417
|
+
...config.outputCompaction,
|
|
418
|
+
trackSavings: value === "on",
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
case "rewriteGitGithub":
|
|
422
|
+
return { ...config, rewriteGitGithub: value === "on" };
|
|
423
|
+
case "rewriteFilesystem":
|
|
424
|
+
return { ...config, rewriteFilesystem: value === "on" };
|
|
425
|
+
case "rewriteRust":
|
|
426
|
+
return { ...config, rewriteRust: value === "on" };
|
|
427
|
+
case "rewriteJavaScript":
|
|
428
|
+
return { ...config, rewriteJavaScript: value === "on" };
|
|
429
|
+
case "rewritePython":
|
|
430
|
+
return { ...config, rewritePython: value === "on" };
|
|
431
|
+
case "rewriteGo":
|
|
432
|
+
return { ...config, rewriteGo: value === "on" };
|
|
433
|
+
case "rewriteContainers":
|
|
434
|
+
return { ...config, rewriteContainers: value === "on" };
|
|
435
|
+
case "rewriteNetwork":
|
|
436
|
+
return { ...config, rewriteNetwork: value === "on" };
|
|
437
|
+
case "rewritePackageManagers":
|
|
438
|
+
return { ...config, rewritePackageManagers: value === "on" };
|
|
439
|
+
default:
|
|
440
|
+
return config;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function syncSettingValues(settingsList: SettingValueSyncTarget, config: RtkIntegrationConfig): void {
|
|
445
|
+
settingsList.updateValue("enabled", toOnOff(config.enabled));
|
|
446
|
+
settingsList.updateValue("mode", config.mode);
|
|
447
|
+
settingsList.updateValue("showRewriteNotifications", toOnOff(config.showRewriteNotifications));
|
|
448
|
+
settingsList.updateValue("guardWhenRtkMissing", toOnOff(config.guardWhenRtkMissing));
|
|
449
|
+
settingsList.updateValue("outputCompactionEnabled", toOnOff(config.outputCompaction.enabled));
|
|
450
|
+
settingsList.updateValue("outputStripAnsi", toOnOff(config.outputCompaction.stripAnsi));
|
|
451
|
+
settingsList.updateValue("outputTruncateEnabled", toOnOff(config.outputCompaction.truncate.enabled));
|
|
452
|
+
settingsList.updateValue("outputTruncateMaxChars", String(config.outputCompaction.truncate.maxChars));
|
|
453
|
+
settingsList.updateValue("outputSourceFilteringEnabled", toOnOff(config.outputCompaction.sourceCodeFilteringEnabled));
|
|
454
|
+
settingsList.updateValue("outputPreserveExactSkillReads", toOnOff(config.outputCompaction.preserveExactSkillReads));
|
|
455
|
+
settingsList.updateValue("outputSourceFiltering", config.outputCompaction.sourceCodeFiltering);
|
|
456
|
+
settingsList.updateValue("outputSmartTruncate", toOnOff(config.outputCompaction.smartTruncate.enabled));
|
|
457
|
+
settingsList.updateValue("outputSmartTruncateMaxLines", String(config.outputCompaction.smartTruncate.maxLines));
|
|
458
|
+
settingsList.updateValue("outputAggregateTestOutput", toOnOff(config.outputCompaction.aggregateTestOutput));
|
|
459
|
+
settingsList.updateValue("outputFilterBuildOutput", toOnOff(config.outputCompaction.filterBuildOutput));
|
|
460
|
+
settingsList.updateValue("outputCompactGitOutput", toOnOff(config.outputCompaction.compactGitOutput));
|
|
461
|
+
settingsList.updateValue("outputAggregateLinterOutput", toOnOff(config.outputCompaction.aggregateLinterOutput));
|
|
462
|
+
settingsList.updateValue("outputGroupSearchOutput", toOnOff(config.outputCompaction.groupSearchOutput));
|
|
463
|
+
settingsList.updateValue("outputTrackSavings", toOnOff(config.outputCompaction.trackSavings));
|
|
464
|
+
settingsList.updateValue("rewriteGitGithub", toOnOff(config.rewriteGitGithub));
|
|
465
|
+
settingsList.updateValue("rewriteFilesystem", toOnOff(config.rewriteFilesystem));
|
|
466
|
+
settingsList.updateValue("rewriteRust", toOnOff(config.rewriteRust));
|
|
467
|
+
settingsList.updateValue("rewriteJavaScript", toOnOff(config.rewriteJavaScript));
|
|
468
|
+
settingsList.updateValue("rewritePython", toOnOff(config.rewritePython));
|
|
469
|
+
settingsList.updateValue("rewriteGo", toOnOff(config.rewriteGo));
|
|
470
|
+
settingsList.updateValue("rewriteContainers", toOnOff(config.rewriteContainers));
|
|
471
|
+
settingsList.updateValue("rewriteNetwork", toOnOff(config.rewriteNetwork));
|
|
472
|
+
settingsList.updateValue("rewritePackageManagers", toOnOff(config.rewritePackageManagers));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async function openSettingsModal(ctx: ExtensionCommandContext, controller: RtkIntegrationController): Promise<void> {
|
|
476
|
+
const overlayOptions = { anchor: "center" as const, width: 86, maxHeight: "85%" as const, margin: 1 };
|
|
477
|
+
|
|
478
|
+
await ctx.ui.custom<void>(
|
|
479
|
+
(tui, theme, _keybindings, done) => {
|
|
480
|
+
let current = controller.getConfig();
|
|
481
|
+
let settingsModal: ZellijSettingsModal | null = null;
|
|
482
|
+
|
|
483
|
+
settingsModal = new ZellijSettingsModal(
|
|
484
|
+
{
|
|
485
|
+
title: "RTK Integration Settings",
|
|
486
|
+
description: "Bash rewrite + tool output compaction for lower token usage",
|
|
487
|
+
settings: buildSettingItems(current),
|
|
488
|
+
onChange: (id, newValue) => {
|
|
489
|
+
current = applySetting(current, id, newValue);
|
|
490
|
+
controller.setConfig(current, ctx);
|
|
491
|
+
current = controller.getConfig();
|
|
492
|
+
if (settingsModal) {
|
|
493
|
+
syncSettingValues(settingsModal, current);
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
onClose: () => done(),
|
|
497
|
+
helpText: `/rtk show • /rtk verify • /rtk stats • /rtk reset • ${controller.getConfigPath()}`,
|
|
498
|
+
enableSearch: true,
|
|
499
|
+
},
|
|
500
|
+
theme,
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const modal = new ZellijModal(
|
|
504
|
+
settingsModal,
|
|
505
|
+
{
|
|
506
|
+
borderStyle: "rounded",
|
|
507
|
+
titleBar: {
|
|
508
|
+
left: "RTK Integration Settings",
|
|
509
|
+
right: "pi-rtk-optimizer",
|
|
510
|
+
},
|
|
511
|
+
helpUndertitle: {
|
|
512
|
+
text: "Esc: close | ↑↓: navigate | Space: toggle",
|
|
513
|
+
color: "dim",
|
|
514
|
+
},
|
|
515
|
+
overlay: overlayOptions,
|
|
516
|
+
},
|
|
517
|
+
theme,
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
return {
|
|
521
|
+
render(width: number) {
|
|
522
|
+
return modal.renderModal(width).lines;
|
|
523
|
+
},
|
|
524
|
+
invalidate() {
|
|
525
|
+
modal.invalidate();
|
|
526
|
+
},
|
|
527
|
+
handleInput(data: string) {
|
|
528
|
+
modal.handleInput(data);
|
|
529
|
+
tui.requestRender();
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
},
|
|
533
|
+
{ overlay: true, overlayOptions },
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async function handleArgs(
|
|
538
|
+
args: string,
|
|
539
|
+
ctx: ExtensionCommandContext,
|
|
540
|
+
controller: RtkIntegrationController,
|
|
541
|
+
): Promise<boolean> {
|
|
542
|
+
const normalized = (args ?? "").trim().toLowerCase();
|
|
543
|
+
if (!normalized) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (normalized === "help") {
|
|
548
|
+
ctx.ui.notify(RTK_USAGE_TEXT, "info");
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (normalized === "show") {
|
|
553
|
+
ctx.ui.notify(`rtk: ${summarizeConfig(controller.getConfig(), controller.getRuntimeStatus())}`, "info");
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (normalized === "path") {
|
|
558
|
+
ctx.ui.notify(`rtk config: ${controller.getConfigPath()}`, "info");
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (normalized === "verify") {
|
|
563
|
+
const runtimeStatus = await controller.refreshRuntimeStatus();
|
|
564
|
+
if (runtimeStatus.rtkAvailable) {
|
|
565
|
+
ctx.ui.notify("RTK binary is available.", "info");
|
|
566
|
+
} else {
|
|
567
|
+
ctx.ui.notify(
|
|
568
|
+
`RTK binary is not available${runtimeStatus.lastError ? `: ${runtimeStatus.lastError}` : ""}.`,
|
|
569
|
+
"warning",
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (normalized === "stats") {
|
|
576
|
+
ctx.ui.notify(controller.getMetricsSummary(), "info");
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (normalized === "clear-stats") {
|
|
581
|
+
controller.clearMetrics();
|
|
582
|
+
ctx.ui.notify("RTK metrics cleared.", "info");
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (normalized === "reset") {
|
|
587
|
+
controller.setConfig({ ...DEFAULT_RTK_INTEGRATION_CONFIG }, ctx);
|
|
588
|
+
ctx.ui.notify("RTK integration settings reset to defaults.", "info");
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
ctx.ui.notify(RTK_USAGE_TEXT, "warning");
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function registerRtkIntegrationCommand(pi: ExtensionAPI, controller: RtkIntegrationController): void {
|
|
597
|
+
pi.registerCommand("rtk", {
|
|
598
|
+
description: "Configure RTK rewrite and output compaction integration",
|
|
599
|
+
getArgumentCompletions: getRtkArgumentCompletions,
|
|
600
|
+
handler: async (args, ctx) => {
|
|
601
|
+
if (await handleArgs(args, ctx, controller)) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (!ctx.hasUI) {
|
|
606
|
+
ctx.ui.notify("/rtk requires interactive TUI mode.", "warning");
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
await openSettingsModal(ctx, controller);
|
|
611
|
+
},
|
|
612
|
+
});
|
|
613
|
+
}
|