@floydous/pi-agent-kernel 0.5.0 → 0.6.1
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/AGENT_KERNEL_SYS_PROMPT.md +20 -6
- package/CHANGELOG.md +69 -0
- package/README.md +23 -20
- package/config.example.toml +1 -0
- package/docs/configuration.md +1 -1
- package/docs/editing-and-verification.md +20 -5
- package/docs/podman-linux-checks.md +24 -0
- package/docs/release-discipline.md +10 -0
- package/docs/retrieval.md +14 -11
- package/grammars/tree-sitter-html.wasm +0 -0
- package/package.json +2 -2
- package/src/config/agent_kernel_command.ts +60 -593
- package/src/config/kernel_config.ts +46 -2
- package/src/editing/patch.ts +48 -21
- package/src/editing/post_edit_verification.ts +8 -4
- package/src/editing/smart_anchor.ts +2 -1
- package/src/editing/syntax-verify.ts +73 -220
- package/src/index.ts +105 -203
- package/src/retrieval/html_chunker.ts +526 -0
- package/src/retrieval/search_bm25.ts +36 -27
- package/src/retrieval/search_chunker.ts +68 -6
- package/src/retrieval/search_config.ts +17 -34
- package/src/retrieval/search_embedder.ts +11 -29
- package/src/retrieval/search_index.ts +307 -145
- package/src/retrieval/search_modal.ts +1247 -222
- package/src/retrieval/tag_extractor.ts +1 -1
- package/src/retrieval/tree_sitter_engine.ts +103 -4
- package/src/retrieval/workspace_walker.ts +72 -0
- package/src/safety/host_environment.ts +190 -0
- package/src/safety/output_clamper.ts +83 -19
- package/src/tools/code_search_output.ts +9 -1
- package/src/tools/code_search_tool.ts +51 -14
- package/src/tools/context.ts +15 -0
- package/src/tools/edit_tool.ts +306 -79
- package/src/tools/read_tool.ts +248 -39
- package/src/tools/stream_reader.ts +206 -0
- package/src/ui/tui_utils.ts +70 -12
|
@@ -1,39 +1,144 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type Focusable, matchesKey, truncateToWidth, visibleWidth } from "../ui/tui_utils";
|
|
2
|
+
import { type Focusable, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../ui/tui_utils";
|
|
3
3
|
import { HybridSearchIndex } from "./search_index";
|
|
4
4
|
import { SearchProfile } from "./search_config";
|
|
5
|
+
import {
|
|
6
|
+
loadKernelConfig,
|
|
7
|
+
saveGlobalKernelConfig,
|
|
8
|
+
saveProjectKernelConfig,
|
|
9
|
+
removeGlobalKernelConfigKey,
|
|
10
|
+
removeProjectKernelConfigKey,
|
|
11
|
+
getGlobalRawConfig,
|
|
12
|
+
getProjectRawConfig,
|
|
13
|
+
mergeDeep,
|
|
14
|
+
type KernelConfig,
|
|
15
|
+
type KernelConfigOverrides,
|
|
16
|
+
} from "../config/kernel_config";
|
|
5
17
|
|
|
6
18
|
export interface ModalResult {
|
|
7
19
|
action: string;
|
|
8
20
|
profile?: SearchProfile;
|
|
9
21
|
reindexed?: boolean;
|
|
22
|
+
excludedPathsChanged?: boolean;
|
|
10
23
|
}
|
|
11
24
|
|
|
12
|
-
export
|
|
25
|
+
export interface ScopeTreeNode {
|
|
26
|
+
id: string; // e.g. "src" or "src/retrieval/search_index.ts"
|
|
27
|
+
name: string; // basename
|
|
28
|
+
relPath: string; // forward-slash relative path
|
|
29
|
+
isDir: boolean;
|
|
30
|
+
depth: number;
|
|
31
|
+
expanded: boolean;
|
|
32
|
+
children: ScopeTreeNode[];
|
|
33
|
+
parent?: ScopeTreeNode;
|
|
34
|
+
fileCount: number;
|
|
35
|
+
chunkCount: number;
|
|
36
|
+
sizeBytes?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface UnifiedModalOptions {
|
|
40
|
+
initialTab?: 0 | 1 | 2; // 0 = Kernel Settings, 1 = Retrieval Engine, 2 = File Index Scope
|
|
41
|
+
cwd?: string;
|
|
42
|
+
deps?: {
|
|
43
|
+
getConfig: (cwd: string) => KernelConfig;
|
|
44
|
+
invalidateConfig: (cwd: string, ctx?: any) => void;
|
|
45
|
+
clearCaches?: () => void;
|
|
46
|
+
getSearchIndex?: (cwd: string) => any;
|
|
47
|
+
triggerBackgroundIndexing?: (index: any, ctx: any, isFullSync?: boolean) => void;
|
|
48
|
+
};
|
|
49
|
+
ctx?: any;
|
|
50
|
+
keybindings?: { matches?: (data: string, keybinding: string) => boolean };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class SearchInput {
|
|
54
|
+
private value = "";
|
|
55
|
+
getValue(): string {
|
|
56
|
+
return this.value;
|
|
57
|
+
}
|
|
58
|
+
setValue(v: string): void {
|
|
59
|
+
this.value = v;
|
|
60
|
+
}
|
|
61
|
+
handleInput(data: string): void {
|
|
62
|
+
if (data === "\x7f" || data === "\b" || /^\x1b\[127(?:;1(?::[12])?)?u$/.test(data)) {
|
|
63
|
+
this.value = this.value.slice(0, -1);
|
|
64
|
+
} else if (matchesKey(data, "space")) {
|
|
65
|
+
this.value += " ";
|
|
66
|
+
} else if (data.length === 1 && data >= " " && data <= "~") {
|
|
67
|
+
this.value += data;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
render(width: number, theme?: any): string[] {
|
|
71
|
+
const label = theme?.fg ? theme.fg("dim", " Filter settings: ") : " Filter settings: ";
|
|
72
|
+
const valText = this.value
|
|
73
|
+
? (theme?.fg ? theme.fg("accent", this.value) : this.value)
|
|
74
|
+
: (theme?.fg ? theme.fg("dim", "(type to filter)") : "(type to filter)");
|
|
75
|
+
return [truncateToWidth(label + valText, width)];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function fuzzyFilter<T>(items: T[], query: string, textFn: (item: T) => string): T[] {
|
|
80
|
+
if (!query) return items;
|
|
81
|
+
const lower = query.toLowerCase();
|
|
82
|
+
return items.filter((item) => textFn(item).toLowerCase().includes(lower));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface CategorizedSettingItem {
|
|
86
|
+
category: string;
|
|
87
|
+
id: string;
|
|
88
|
+
label: string;
|
|
89
|
+
currentValue: string;
|
|
90
|
+
values: string[];
|
|
91
|
+
descriptions: Record<string, string>;
|
|
92
|
+
isGlobal: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class UnifiedControlModal implements Focusable {
|
|
13
96
|
focused = false;
|
|
14
97
|
|
|
15
98
|
private tui: any;
|
|
16
99
|
private index: HybridSearchIndex;
|
|
17
100
|
private theme: Theme;
|
|
18
101
|
private done: (result: ModalResult | undefined) => void;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
102
|
+
private options: UnifiedModalOptions;
|
|
103
|
+
private currentCwd: string;
|
|
104
|
+
|
|
105
|
+
// Active tab: 0 = Kernel Settings, 1 = Retrieval Engine, 2 = File Index Scope
|
|
106
|
+
private activeTab: 0 | 1 | 2 = 0;
|
|
21
107
|
|
|
22
|
-
//
|
|
23
|
-
|
|
108
|
+
// -------------------------------------------------------------------------
|
|
109
|
+
// TAB 0: KERNEL SETTINGS STATE
|
|
110
|
+
// -------------------------------------------------------------------------
|
|
111
|
+
private settingsItems: CategorizedSettingItem[] = [];
|
|
112
|
+
private filteredSettingsItems: CategorizedSettingItem[] = [];
|
|
113
|
+
private settingsSelectedIndex = 0;
|
|
114
|
+
private searchInput: SearchInput;
|
|
115
|
+
private initialSettingStates = new Map<string, { value: string; isGlobal: boolean }>();
|
|
116
|
+
private categoryOrder = [
|
|
117
|
+
"Retrieval & Exploration",
|
|
118
|
+
"Safety & Verification",
|
|
119
|
+
"Editing Engine",
|
|
120
|
+
"System Guidance & UI",
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
// -------------------------------------------------------------------------
|
|
124
|
+
// TAB 1: RETRIEVAL ENGINE STATE
|
|
125
|
+
// -------------------------------------------------------------------------
|
|
126
|
+
private initialProfile: SearchProfile;
|
|
127
|
+
private selectedProfile: SearchProfile;
|
|
128
|
+
private profileSelectedIndex = 0;
|
|
129
|
+
private profileItems: Array<{
|
|
24
130
|
id: string;
|
|
25
131
|
category: "profile" | "action";
|
|
26
132
|
label: string;
|
|
27
133
|
desc: string;
|
|
28
134
|
profile?: SearchProfile;
|
|
29
135
|
}> = [
|
|
30
|
-
// Category: Profiles
|
|
31
136
|
{
|
|
32
137
|
id: "auto",
|
|
33
138
|
category: "profile",
|
|
34
139
|
profile: "auto",
|
|
35
140
|
label: "Auto Detect",
|
|
36
|
-
desc: "Auto-detect Lean (
|
|
141
|
+
desc: "Auto-detect Lean (fewer than 4 CPUs) or Full (4 or more)",
|
|
37
142
|
},
|
|
38
143
|
{
|
|
39
144
|
id: "lean",
|
|
@@ -42,19 +147,12 @@ export class SearchControlModal implements Focusable {
|
|
|
42
147
|
label: "Lean Mode",
|
|
43
148
|
desc: "AST BM25 (0% CPU, 0 MB extra RAM)",
|
|
44
149
|
},
|
|
45
|
-
{
|
|
46
|
-
id: "hybrid",
|
|
47
|
-
category: "profile",
|
|
48
|
-
profile: "hybrid",
|
|
49
|
-
label: "Hybrid Mode",
|
|
50
|
-
desc: "Throttled 256-dim Matryoshka embeddings",
|
|
51
|
-
},
|
|
52
150
|
{
|
|
53
151
|
id: "full",
|
|
54
152
|
category: "profile",
|
|
55
153
|
profile: "full",
|
|
56
154
|
label: "Full Mode",
|
|
57
|
-
desc: "
|
|
155
|
+
desc: "BM25 + 768-dim code embeddings",
|
|
58
156
|
},
|
|
59
157
|
{
|
|
60
158
|
id: "off",
|
|
@@ -63,7 +161,6 @@ export class SearchControlModal implements Focusable {
|
|
|
63
161
|
label: "Disable Engine",
|
|
64
162
|
desc: "Turn off search & free memory",
|
|
65
163
|
},
|
|
66
|
-
// Category: Workspace Actions
|
|
67
164
|
{
|
|
68
165
|
id: "reindex",
|
|
69
166
|
category: "action",
|
|
@@ -74,284 +171,1212 @@ export class SearchControlModal implements Focusable {
|
|
|
74
171
|
id: "close",
|
|
75
172
|
category: "action",
|
|
76
173
|
label: "Close Panel",
|
|
77
|
-
desc: "Dismiss this dialog",
|
|
174
|
+
desc: "Dismiss this dialog and apply changes",
|
|
78
175
|
},
|
|
79
176
|
];
|
|
80
177
|
|
|
178
|
+
// -------------------------------------------------------------------------
|
|
179
|
+
// TAB 2: FILE INDEX SCOPE STATE
|
|
180
|
+
// -------------------------------------------------------------------------
|
|
181
|
+
private treeRoots: ScopeTreeNode[] = [];
|
|
182
|
+
private treeCursorIndex = 0;
|
|
183
|
+
private treeScrollOffset = 0;
|
|
184
|
+
private excludedPaths: Set<string>;
|
|
185
|
+
private initialExcludedPaths: Set<string>;
|
|
186
|
+
|
|
81
187
|
constructor(
|
|
82
188
|
tui: any,
|
|
83
189
|
index: HybridSearchIndex,
|
|
84
190
|
theme: Theme,
|
|
85
|
-
done: (result: ModalResult | undefined) => void
|
|
191
|
+
done: (result: ModalResult | undefined) => void,
|
|
192
|
+
options: UnifiedModalOptions = {},
|
|
86
193
|
) {
|
|
87
194
|
this.tui = tui;
|
|
88
195
|
this.index = index;
|
|
89
196
|
this.theme = theme;
|
|
90
197
|
this.done = done;
|
|
91
|
-
this.
|
|
198
|
+
this.options = options;
|
|
199
|
+
this.currentCwd = options.cwd || (index?.getCwd ? index.getCwd() : process.cwd());
|
|
200
|
+
|
|
201
|
+
// Tab selection: defaults to options.initialTab if provided,
|
|
202
|
+
// or 1 if invoked as legacy SearchControlModal without options.
|
|
203
|
+
if (options.initialTab !== undefined) {
|
|
204
|
+
this.activeTab = options.initialTab;
|
|
205
|
+
} else {
|
|
206
|
+
this.activeTab = 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Initial profile setup
|
|
210
|
+
this.initialProfile = index?.getProfile ? index.getProfile() : "lean";
|
|
211
|
+
this.selectedProfile = this.initialProfile === "hybrid" ? "full" : this.initialProfile;
|
|
212
|
+
const pIdx = this.profileItems.findIndex((item) => item.profile === this.selectedProfile);
|
|
213
|
+
if (pIdx >= 0) this.profileSelectedIndex = pIdx;
|
|
214
|
+
|
|
215
|
+
// Excluded paths setup
|
|
216
|
+
this.excludedPaths = new Set(index?.getExcludedPaths ? index.getExcludedPaths() : []);
|
|
217
|
+
this.initialExcludedPaths = new Set(this.excludedPaths);
|
|
218
|
+
|
|
219
|
+
// Initialize Tab 0 Settings
|
|
220
|
+
this.searchInput = new SearchInput();
|
|
221
|
+
this.initSettingsTab();
|
|
222
|
+
|
|
223
|
+
// Initialize Tab 2 Scope Tree
|
|
224
|
+
this.buildScopeTree();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// =========================================================================
|
|
228
|
+
// TAB 0: KERNEL SETTINGS LOGIC
|
|
229
|
+
// =========================================================================
|
|
230
|
+
private initSettingsTab(): void {
|
|
231
|
+
const currentConfig = this.options.deps?.getConfig
|
|
232
|
+
? this.options.deps.getConfig(this.currentCwd)
|
|
233
|
+
: loadKernelConfig(this.currentCwd);
|
|
234
|
+
|
|
235
|
+
const globalRaw = getGlobalRawConfig();
|
|
236
|
+
const projectTrusted = this.options.ctx?.isProjectTrusted?.() !== false;
|
|
237
|
+
const projectRaw = projectTrusted ? getProjectRawConfig(this.currentCwd) : {};
|
|
238
|
+
const isOverriddenByProject = (section: string, key: string): boolean =>
|
|
239
|
+
projectRaw[section]?.[key] !== undefined;
|
|
240
|
+
const checkIsGlobal = (id: string): boolean => {
|
|
241
|
+
if (id === "profile") return !isOverriddenByProject("retrieval", "default_profile") && globalRaw.retrieval?.default_profile !== undefined;
|
|
242
|
+
if (id === "epistemic") return !isOverriddenByProject("safety", "enable_epistemic_guard") && globalRaw.safety?.enable_epistemic_guard !== undefined;
|
|
243
|
+
if (id === "max_lines") return !isOverriddenByProject("safety", "max_lines") && globalRaw.safety?.max_lines !== undefined;
|
|
244
|
+
if (id === "editing") return !isOverriddenByProject("editing", "mode") && globalRaw.editing?.mode !== undefined;
|
|
245
|
+
if (id === "read_mode") return !isOverriddenByProject("editing", "read_mode") && globalRaw.editing?.read_mode !== undefined;
|
|
246
|
+
if (id === "normalize_dots") return !isOverriddenByProject("editing", "normalize_fullwidth_dots") && globalRaw.editing?.normalize_fullwidth_dots !== undefined;
|
|
247
|
+
if (id === "guidance") return !isOverriddenByProject("instructions", "enabled") && globalRaw.instructions?.enabled !== undefined;
|
|
248
|
+
if (id === "host_environment") return !isOverriddenByProject("instructions", "host_environment") && globalRaw.instructions?.host_environment !== undefined;
|
|
249
|
+
if (id === "pi_docs") return !isOverriddenByProject("instructions", "pi_docs") && globalRaw.instructions?.pi_docs !== undefined;
|
|
250
|
+
if (id === "footer") return !isOverriddenByProject("ui", "enable_pastel_footer") && globalRaw.ui?.enable_pastel_footer !== undefined;
|
|
251
|
+
return false;
|
|
252
|
+
};
|
|
92
253
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
254
|
+
const normalizedProfile = currentConfig.retrieval.default_profile === "hybrid"
|
|
255
|
+
? "full"
|
|
256
|
+
: currentConfig.retrieval.default_profile;
|
|
257
|
+
if (!this.index?.getProfile) {
|
|
258
|
+
this.initialProfile = normalizedProfile;
|
|
259
|
+
this.selectedProfile = normalizedProfile;
|
|
260
|
+
const pIdx = this.profileItems.findIndex((item) => item.profile === this.selectedProfile);
|
|
261
|
+
if (pIdx >= 0) this.profileSelectedIndex = pIdx;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
this.settingsItems = [
|
|
265
|
+
{
|
|
266
|
+
category: "Retrieval & Exploration",
|
|
267
|
+
id: "profile",
|
|
268
|
+
label: "Retrieval Engine Profile",
|
|
269
|
+
currentValue: normalizedProfile,
|
|
270
|
+
values: ["auto", "lean", "full", "off"],
|
|
271
|
+
isGlobal: checkIsGlobal("profile"),
|
|
272
|
+
descriptions: {
|
|
273
|
+
auto: "Auto profile: Selects lean below 4 CPU cores and full otherwise.",
|
|
274
|
+
lean: "Lean profile: BM25 keyword index + AST code chunking. Zero RAM overhead, sub-millisecond retrieval.",
|
|
275
|
+
full: "Full profile: BM25 keyword index fused with 768d gte-modernbert-base code embeddings (~147 MB model).",
|
|
276
|
+
hybrid: "Hybrid: alias of the full profile.",
|
|
277
|
+
off: "Off profile: Retrieval subsystem disabled. code_search returns an error.",
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
category: "Safety & Verification",
|
|
282
|
+
id: "epistemic",
|
|
283
|
+
label: "Epistemic Guard (Read-before-write)",
|
|
284
|
+
currentValue: currentConfig.safety.enable_epistemic_guard ? "enabled" : "disabled",
|
|
285
|
+
values: ["enabled", "disabled"],
|
|
286
|
+
isGlobal: checkIsGlobal("epistemic"),
|
|
287
|
+
descriptions: {
|
|
288
|
+
enabled: "Epistemic Guard active: Enforces strict read-before-write validation, preventing hallucinated edits.",
|
|
289
|
+
disabled: "Epistemic Guard inactive: Allows unconstrained edits without prior read operations.",
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
category: "Safety & Verification",
|
|
294
|
+
id: "max_lines",
|
|
295
|
+
label: "Output Clamping Line Limit",
|
|
296
|
+
currentValue: `${currentConfig.safety.max_lines} lines`,
|
|
297
|
+
values: ["40 lines", "100 lines", "200 lines"],
|
|
298
|
+
isGlobal: checkIsGlobal("max_lines"),
|
|
299
|
+
descriptions: {
|
|
300
|
+
"40 lines": "40 lines maximum: Compact output windowing, best for low-context models.",
|
|
301
|
+
"100 lines": "100 lines maximum (recommended default): Balanced diagnostic context with spillover logging.",
|
|
302
|
+
"200 lines": "200 lines maximum: Expansive terminal output for deep test traces and large outputs.",
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
category: "Editing Engine",
|
|
307
|
+
id: "editing",
|
|
308
|
+
label: "Editing Mode (Smart Anchors)",
|
|
309
|
+
currentValue: currentConfig.editing.mode === "smart_anchor" ? "smart_anchor" : "standard",
|
|
310
|
+
values: ["smart_anchor", "standard"],
|
|
311
|
+
isGlobal: checkIsGlobal("editing"),
|
|
312
|
+
descriptions: {
|
|
313
|
+
smart_anchor: "Smart Anchors: syntax validation, lexical delimiter balancing, and line-hint disambiguation.",
|
|
314
|
+
standard: "Standard editing: exact string replacement with delimiter auto-healing disabled.",
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
category: "Editing Engine",
|
|
319
|
+
id: "read_mode",
|
|
320
|
+
label: "Reading Anchor Protocol",
|
|
321
|
+
currentValue: currentConfig.editing.read_mode,
|
|
322
|
+
values: ["plain", "anchored", "auto"],
|
|
323
|
+
isGlobal: checkIsGlobal("read_mode"),
|
|
324
|
+
descriptions: {
|
|
325
|
+
plain: "Plain text reads: Clean, unanchored reading protocol. Reduces token consumption by ~84%.",
|
|
326
|
+
anchored: "Anchored reads: Injects LINE#HASH prefixes on every line for strict positional pinning.",
|
|
327
|
+
auto: "Adaptive reading: Defaults to clean plain text, automatically falling back to anchored reads when resolving ambiguous edit targets.",
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
category: "Editing Engine",
|
|
332
|
+
id: "normalize_dots",
|
|
333
|
+
label: "Fullwidth Dot Normalization",
|
|
334
|
+
currentValue: currentConfig.editing.normalize_fullwidth_dots !== false ? "enabled" : "disabled",
|
|
335
|
+
values: ["enabled", "disabled"],
|
|
336
|
+
isGlobal: checkIsGlobal("normalize_dots"),
|
|
337
|
+
descriptions: {
|
|
338
|
+
enabled: "Fullwidth dot normalization enabled: Converts Unicode fullwidth full stop (U+FF0E '.') to ASCII '.' in edit operations.",
|
|
339
|
+
disabled: "Fullwidth dot normalization disabled: Preserves Unicode fullwidth full stop verbatim.",
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
category: "System Guidance & UI",
|
|
344
|
+
id: "guidance",
|
|
345
|
+
label: "Agent Guidance Prompt",
|
|
346
|
+
currentValue: currentConfig.instructions.enabled ? "enabled" : "disabled",
|
|
347
|
+
values: ["enabled", "disabled"],
|
|
348
|
+
isGlobal: checkIsGlobal("guidance"),
|
|
349
|
+
descriptions: {
|
|
350
|
+
enabled: "Kernel guidance active: Injects empirical tool discipline, grounding rules, and search strategies into the system prompt.",
|
|
351
|
+
disabled: "Kernel guidance inactive: Omits kernel prompt injection, running with default model prompt.",
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
category: "System Guidance & UI",
|
|
356
|
+
id: "host_environment",
|
|
357
|
+
label: "Host Environment Info",
|
|
358
|
+
currentValue: currentConfig.instructions.host_environment !== false ? "enabled" : "disabled",
|
|
359
|
+
values: ["enabled", "disabled"],
|
|
360
|
+
isGlobal: checkIsGlobal("host_environment"),
|
|
361
|
+
descriptions: {
|
|
362
|
+
enabled: "Host environment active: Injects factual host OS, shell, line ending policy, and toolchain versions into system prompt.",
|
|
363
|
+
disabled: "Host environment inactive: Omits host platform and toolchain probing from system prompt.",
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
category: "System Guidance & UI",
|
|
368
|
+
id: "pi_docs",
|
|
369
|
+
label: "Pi Docs System Guidance (pi-docs)",
|
|
370
|
+
currentValue: currentConfig.instructions.pi_docs ? "enabled" : "disabled",
|
|
371
|
+
values: ["enabled", "disabled"],
|
|
372
|
+
isGlobal: checkIsGlobal("pi_docs"),
|
|
373
|
+
descriptions: {
|
|
374
|
+
enabled: "Pi docs included: Injects documentation guidance for Pi extensions, tools, and theme authoring.",
|
|
375
|
+
disabled: "Pi docs omitted: Strips the Pi documentation block to optimize prompt cache hit rate and token consumption.",
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
category: "System Guidance & UI",
|
|
380
|
+
id: "footer",
|
|
381
|
+
label: "Pastel Status Footer",
|
|
382
|
+
currentValue: currentConfig.ui.enable_pastel_footer ? "enabled" : "disabled",
|
|
383
|
+
values: ["enabled", "disabled"],
|
|
384
|
+
isGlobal: checkIsGlobal("footer"),
|
|
385
|
+
descriptions: {
|
|
386
|
+
enabled: "Pastel footer active: Displays terminal statusline at bottom showing active model, search index, and memory.",
|
|
387
|
+
disabled: "Pastel footer inactive: Disables bottom statusline for an uncluttered minimal workspace.",
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
];
|
|
391
|
+
|
|
392
|
+
this.filteredSettingsItems = this.settingsItems;
|
|
393
|
+
for (const item of this.settingsItems) {
|
|
394
|
+
this.initialSettingStates.set(item.id, {
|
|
395
|
+
value: item.currentValue,
|
|
396
|
+
isGlobal: Boolean(item.isGlobal),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private applySettingsFilter(query: string): void {
|
|
402
|
+
if (query) {
|
|
403
|
+
const matches = fuzzyFilter(
|
|
404
|
+
this.settingsItems,
|
|
405
|
+
query,
|
|
406
|
+
(item: CategorizedSettingItem) => {
|
|
407
|
+
const descAll = item.descriptions ? Object.values(item.descriptions).join(" ") : "";
|
|
408
|
+
return `${item.category} ${item.label} ${descAll} ${item.id}`;
|
|
409
|
+
},
|
|
410
|
+
);
|
|
411
|
+
const catGroups = new Map<string, CategorizedSettingItem[]>();
|
|
412
|
+
for (const item of matches) {
|
|
413
|
+
const list = catGroups.get(item.category) || [];
|
|
414
|
+
list.push(item);
|
|
415
|
+
catGroups.set(item.category, list);
|
|
416
|
+
}
|
|
417
|
+
const result: CategorizedSettingItem[] = [];
|
|
418
|
+
for (const cat of this.categoryOrder) {
|
|
419
|
+
const list = catGroups.get(cat);
|
|
420
|
+
if (list) result.push(...list);
|
|
421
|
+
}
|
|
422
|
+
this.filteredSettingsItems = result;
|
|
423
|
+
} else {
|
|
424
|
+
this.filteredSettingsItems = this.settingsItems;
|
|
425
|
+
}
|
|
426
|
+
this.settingsSelectedIndex = 0;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
private syncProfileSelection(profile: SearchProfile): void {
|
|
430
|
+
const normalized = profile === "hybrid" ? "full" : profile;
|
|
431
|
+
this.selectedProfile = normalized;
|
|
432
|
+
const pIdx = this.profileItems.findIndex((pi) => pi.profile === normalized);
|
|
433
|
+
if (pIdx >= 0) this.profileSelectedIndex = pIdx;
|
|
434
|
+
const profileSetting = this.settingsItems.find((s) => s.id === "profile");
|
|
435
|
+
if (profileSetting) {
|
|
436
|
+
profileSetting.currentValue = normalized;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private activateSettingItem(): void {
|
|
441
|
+
const item = this.filteredSettingsItems[this.settingsSelectedIndex];
|
|
442
|
+
if (!item || !item.values || item.values.length === 0) return;
|
|
443
|
+
const curIdx = item.values.indexOf(item.currentValue);
|
|
444
|
+
const nextIdx = (curIdx + 1) % item.values.length;
|
|
445
|
+
item.currentValue = item.values[nextIdx];
|
|
446
|
+
|
|
447
|
+
// If profile setting was cycled in Tab 0, keep Tab 1 in sync
|
|
448
|
+
if (item.id === "profile") {
|
|
449
|
+
this.syncProfileSelection(item.currentValue as SearchProfile);
|
|
450
|
+
}
|
|
97
451
|
}
|
|
98
452
|
|
|
453
|
+
private toggleGlobalSetting(): void {
|
|
454
|
+
const item = this.filteredSettingsItems[this.settingsSelectedIndex];
|
|
455
|
+
if (!item) return;
|
|
456
|
+
item.isGlobal = !item.isGlobal;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private applySettingsChanges(): boolean {
|
|
460
|
+
let hasChanges = false;
|
|
461
|
+
const globalUpdates: KernelConfigOverrides = {};
|
|
462
|
+
const projectUpdates: KernelConfigOverrides = {};
|
|
463
|
+
const revertedGlobals: Array<{ section: string; key: string }> = [];
|
|
464
|
+
const revertedProjects: Array<{ section: string; key: string }> = [];
|
|
465
|
+
|
|
466
|
+
const createPatchForSetting = (id: string, value: string): { patch: KernelConfigOverrides } => {
|
|
467
|
+
const patch: KernelConfigOverrides = {};
|
|
468
|
+
if (id === "profile") {
|
|
469
|
+
patch.retrieval = { default_profile: value as "auto" | "lean" | "hybrid" | "full" | "off" };
|
|
470
|
+
} else if (id === "epistemic") {
|
|
471
|
+
patch.safety = { enable_epistemic_guard: value === "enabled" };
|
|
472
|
+
} else if (id === "editing") {
|
|
473
|
+
patch.editing = { mode: value as "smart_anchor" | "standard" };
|
|
474
|
+
} else if (id === "read_mode") {
|
|
475
|
+
patch.editing = { read_mode: value as "auto" | "plain" | "anchored" };
|
|
476
|
+
} else if (id === "normalize_dots") {
|
|
477
|
+
patch.editing = { normalize_fullwidth_dots: value === "enabled" };
|
|
478
|
+
} else if (id === "guidance") {
|
|
479
|
+
patch.instructions = { enabled: value === "enabled" };
|
|
480
|
+
} else if (id === "host_environment") {
|
|
481
|
+
patch.instructions = { host_environment: value === "enabled" };
|
|
482
|
+
} else if (id === "pi_docs") {
|
|
483
|
+
patch.instructions = { pi_docs: value === "enabled" };
|
|
484
|
+
} else if (id === "footer") {
|
|
485
|
+
patch.ui = { enable_pastel_footer: value === "enabled" };
|
|
486
|
+
} else if (id === "max_lines") {
|
|
487
|
+
const num = parseInt(value, 10);
|
|
488
|
+
if (Number.isSafeInteger(num)) {
|
|
489
|
+
patch.safety = { max_lines: num };
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return { patch };
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const getSettingSectionAndKey = (id: string): { section: string; key: string } | null => {
|
|
496
|
+
switch (id) {
|
|
497
|
+
case "profile": return { section: "retrieval", key: "default_profile" };
|
|
498
|
+
case "epistemic": return { section: "safety", key: "enable_epistemic_guard" };
|
|
499
|
+
case "max_lines": return { section: "safety", key: "max_lines" };
|
|
500
|
+
case "editing": return { section: "editing", key: "mode" };
|
|
501
|
+
case "read_mode": return { section: "editing", key: "read_mode" };
|
|
502
|
+
case "normalize_dots": return { section: "editing", key: "normalize_fullwidth_dots" };
|
|
503
|
+
case "guidance": return { section: "instructions", key: "enabled" };
|
|
504
|
+
case "host_environment": return { section: "instructions", key: "host_environment" };
|
|
505
|
+
case "pi_docs": return { section: "instructions", key: "pi_docs" };
|
|
506
|
+
case "footer": return { section: "ui", key: "enable_pastel_footer" };
|
|
507
|
+
default: return null;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
for (const item of this.settingsItems) {
|
|
512
|
+
const initial = this.initialSettingStates.get(item.id);
|
|
513
|
+
if (!initial) continue;
|
|
514
|
+
|
|
515
|
+
const valueChanged = item.currentValue !== initial.value;
|
|
516
|
+
const scopeChanged = Boolean(item.isGlobal) !== Boolean(initial.isGlobal);
|
|
517
|
+
|
|
518
|
+
if (valueChanged || scopeChanged) {
|
|
519
|
+
hasChanges = true;
|
|
520
|
+
const { patch } = createPatchForSetting(item.id, item.currentValue);
|
|
521
|
+
|
|
522
|
+
if (item.isGlobal) {
|
|
523
|
+
mergeDeep(globalUpdates, patch);
|
|
524
|
+
if (!initial.isGlobal) {
|
|
525
|
+
const meta = getSettingSectionAndKey(item.id);
|
|
526
|
+
if (meta) revertedProjects.push(meta);
|
|
527
|
+
}
|
|
528
|
+
} else {
|
|
529
|
+
if (initial.isGlobal) {
|
|
530
|
+
const meta = getSettingSectionAndKey(item.id);
|
|
531
|
+
if (meta) revertedGlobals.push(meta);
|
|
532
|
+
}
|
|
533
|
+
mergeDeep(projectUpdates, patch);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (hasChanges) {
|
|
539
|
+
try {
|
|
540
|
+
if (Object.keys(globalUpdates).length > 0) {
|
|
541
|
+
saveGlobalKernelConfig(globalUpdates);
|
|
542
|
+
}
|
|
543
|
+
if (Object.keys(projectUpdates).length > 0) {
|
|
544
|
+
saveProjectKernelConfig(this.currentCwd, projectUpdates);
|
|
545
|
+
}
|
|
546
|
+
for (const { section, key } of revertedGlobals) {
|
|
547
|
+
removeGlobalKernelConfigKey(section, key);
|
|
548
|
+
}
|
|
549
|
+
for (const { section, key } of revertedProjects) {
|
|
550
|
+
removeProjectKernelConfigKey(this.currentCwd, section, key);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
this.options.deps?.invalidateConfig?.(this.currentCwd, this.options.ctx);
|
|
554
|
+
this.options.deps?.clearCaches?.();
|
|
555
|
+
this.options.ctx?.ui?.notify?.("Applied Agent Kernel configuration changes.", "info");
|
|
556
|
+
} catch (error) {
|
|
557
|
+
console.error("[agent-kernel] Configuration apply failed:", error);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return hasChanges;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// =========================================================================
|
|
564
|
+
// TAB 2: FILE INDEX SCOPE LOGIC
|
|
565
|
+
// =========================================================================
|
|
566
|
+
private buildScopeTree(): void {
|
|
567
|
+
const files = this.index?.getIndexableFiles ? this.index.getIndexableFiles() : [];
|
|
568
|
+
|
|
569
|
+
for (const relPath of files) {
|
|
570
|
+
const normPath = relPath.replace(/\\/g, "/");
|
|
571
|
+
const parts = normPath.split("/");
|
|
572
|
+
let currentChildren = this.treeRoots;
|
|
573
|
+
let currentParent: ScopeTreeNode | undefined = undefined;
|
|
574
|
+
let currentAccum = "";
|
|
575
|
+
|
|
576
|
+
for (let i = 0; i < parts.length; i++) {
|
|
577
|
+
const part = parts[i];
|
|
578
|
+
const isLast = i === parts.length - 1;
|
|
579
|
+
currentAccum = currentAccum ? `${currentAccum}/${part}` : part;
|
|
580
|
+
|
|
581
|
+
if (isLast) {
|
|
582
|
+
const chunkCount = this.index?.getChunkCountForFile ? this.index.getChunkCountForFile(normPath) : 1;
|
|
583
|
+
const fileNode: ScopeTreeNode = {
|
|
584
|
+
id: normPath,
|
|
585
|
+
name: part,
|
|
586
|
+
relPath: normPath,
|
|
587
|
+
isDir: false,
|
|
588
|
+
depth: i,
|
|
589
|
+
expanded: false,
|
|
590
|
+
children: [],
|
|
591
|
+
parent: currentParent,
|
|
592
|
+
fileCount: 1,
|
|
593
|
+
chunkCount,
|
|
594
|
+
};
|
|
595
|
+
currentChildren.push(fileNode);
|
|
596
|
+
} else {
|
|
597
|
+
let dirNode = currentChildren.find((c) => c.isDir && c.name === part);
|
|
598
|
+
if (!dirNode) {
|
|
599
|
+
dirNode = {
|
|
600
|
+
id: currentAccum,
|
|
601
|
+
name: part,
|
|
602
|
+
relPath: currentAccum,
|
|
603
|
+
isDir: true,
|
|
604
|
+
depth: i,
|
|
605
|
+
expanded: i === 0,
|
|
606
|
+
children: [],
|
|
607
|
+
parent: currentParent,
|
|
608
|
+
fileCount: 0,
|
|
609
|
+
chunkCount: 0,
|
|
610
|
+
};
|
|
611
|
+
currentChildren.push(dirNode);
|
|
612
|
+
}
|
|
613
|
+
currentParent = dirNode;
|
|
614
|
+
currentChildren = dirNode.children;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const aggregateCounts = (nodes: ScopeTreeNode[]): { files: number; chunks: number } => {
|
|
620
|
+
let totalFiles = 0;
|
|
621
|
+
let totalChunks = 0;
|
|
622
|
+
for (const node of nodes) {
|
|
623
|
+
if (node.isDir) {
|
|
624
|
+
const sub = aggregateCounts(node.children);
|
|
625
|
+
node.fileCount = sub.files;
|
|
626
|
+
node.chunkCount = sub.chunks;
|
|
627
|
+
totalFiles += sub.files;
|
|
628
|
+
totalChunks += sub.chunks;
|
|
629
|
+
} else {
|
|
630
|
+
totalFiles += 1;
|
|
631
|
+
totalChunks += node.chunkCount;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
nodes.sort((a, b) => {
|
|
635
|
+
if (a.isDir !== b.isDir) return a.isDir ? -1 : 1;
|
|
636
|
+
return a.name.localeCompare(b.name);
|
|
637
|
+
});
|
|
638
|
+
return { files: totalFiles, chunks: totalChunks };
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
aggregateCounts(this.treeRoots);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
private isPathExcluded(relPath: string): boolean {
|
|
645
|
+
const norm = relPath.replace(/\\/g, "/").replace(/^(\.\/)+/, "").replace(/^\/+|\/+$/g, "");
|
|
646
|
+
for (const p of this.excludedPaths) {
|
|
647
|
+
const cleanP = p.replace(/\\/g, "/").replace(/^(\.\/)+/, "").replace(/^\/+|\/+$/g, "");
|
|
648
|
+
if (!cleanP) continue;
|
|
649
|
+
if (norm === cleanP || norm.startsWith(cleanP + "/")) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
private getFolderSelectionState(node: ScopeTreeNode): "all" | "some" | "none" {
|
|
657
|
+
let total = 0;
|
|
658
|
+
let selected = 0;
|
|
659
|
+
|
|
660
|
+
const check = (n: ScopeTreeNode) => {
|
|
661
|
+
for (const child of n.children) {
|
|
662
|
+
if (child.isDir) {
|
|
663
|
+
check(child);
|
|
664
|
+
} else {
|
|
665
|
+
total++;
|
|
666
|
+
if (!this.isPathExcluded(child.relPath)) {
|
|
667
|
+
selected++;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
check(node);
|
|
673
|
+
|
|
674
|
+
if (total === 0) return "all";
|
|
675
|
+
if (selected === total) return "all";
|
|
676
|
+
if (selected === 0) return "none";
|
|
677
|
+
return "some";
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
private unexcludeNode(node: ScopeTreeNode): void {
|
|
681
|
+
this.excludedPaths.delete(node.relPath);
|
|
682
|
+
|
|
683
|
+
const clearChildren = (n: ScopeTreeNode) => {
|
|
684
|
+
for (const c of n.children) {
|
|
685
|
+
this.excludedPaths.delete(c.relPath);
|
|
686
|
+
if (c.isDir) clearChildren(c);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
if (node.isDir) clearChildren(node);
|
|
690
|
+
|
|
691
|
+
let p = node.parent;
|
|
692
|
+
while (p) {
|
|
693
|
+
if (this.excludedPaths.has(p.relPath)) {
|
|
694
|
+
this.excludedPaths.delete(p.relPath);
|
|
695
|
+
const excludeSubtreeExcept = (dir: ScopeTreeNode, targetPath: string) => {
|
|
696
|
+
for (const c of dir.children) {
|
|
697
|
+
if (c.relPath === targetPath) continue;
|
|
698
|
+
if (c.isDir) {
|
|
699
|
+
if (targetPath.startsWith(c.relPath + "/")) {
|
|
700
|
+
excludeSubtreeExcept(c, targetPath);
|
|
701
|
+
} else {
|
|
702
|
+
this.excludedPaths.add(c.relPath);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
this.excludedPaths.add(c.relPath);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
excludeSubtreeExcept(p, node.relPath);
|
|
710
|
+
}
|
|
711
|
+
p = p.parent;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
private toggleNodeSelection(node: ScopeTreeNode): void {
|
|
716
|
+
if (!node.isDir) {
|
|
717
|
+
const isExcluded = this.isPathExcluded(node.relPath);
|
|
718
|
+
if (isExcluded) {
|
|
719
|
+
this.unexcludeNode(node);
|
|
720
|
+
} else {
|
|
721
|
+
this.excludedPaths.add(node.relPath);
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
const state = this.getFolderSelectionState(node);
|
|
725
|
+
if (state === "all") {
|
|
726
|
+
this.excludedPaths.add(node.relPath);
|
|
727
|
+
const clearSub = (dir: ScopeTreeNode) => {
|
|
728
|
+
for (const c of dir.children) {
|
|
729
|
+
this.excludedPaths.delete(c.relPath);
|
|
730
|
+
if (c.isDir) clearSub(c);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
clearSub(node);
|
|
734
|
+
} else {
|
|
735
|
+
this.unexcludeNode(node);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
this.tui?.requestRender?.();
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
private getVisibleTreeNodes(): ScopeTreeNode[] {
|
|
742
|
+
const visible: ScopeTreeNode[] = [];
|
|
743
|
+
const traverse = (nodes: ScopeTreeNode[]) => {
|
|
744
|
+
for (const node of nodes) {
|
|
745
|
+
visible.push(node);
|
|
746
|
+
if (node.isDir && node.expanded) {
|
|
747
|
+
traverse(node.children);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
traverse(this.treeRoots);
|
|
752
|
+
return visible;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
private hasExcludedPathsChanged(): boolean {
|
|
756
|
+
if (this.excludedPaths.size !== this.initialExcludedPaths.size) return true;
|
|
757
|
+
for (const p of this.excludedPaths) {
|
|
758
|
+
if (!this.initialExcludedPaths.has(p)) return true;
|
|
759
|
+
}
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private matchesBinding(data: string, keybinding: string, fallbackKey: string): boolean {
|
|
764
|
+
return Boolean(this.options.keybindings?.matches?.(data, keybinding)) || matchesKey(data, fallbackKey);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// =========================================================================
|
|
768
|
+
// KEYBOARD INPUT DISPATCHER
|
|
769
|
+
// =========================================================================
|
|
99
770
|
async handleInput(data: string): Promise<void> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
771
|
+
// Universal dismiss on Esc / q
|
|
772
|
+
if (
|
|
773
|
+
this.matchesBinding(data, "tui.select.cancel", "escape") ||
|
|
774
|
+
matchesKey(data, "q") ||
|
|
775
|
+
matchesKey(data, "ctrl+c")
|
|
776
|
+
) {
|
|
777
|
+
this.finishModal("close");
|
|
104
778
|
return;
|
|
105
779
|
}
|
|
106
780
|
|
|
107
|
-
|
|
108
|
-
|
|
781
|
+
// Universal Tab switching: 0 -> 1 -> 2 -> 0
|
|
782
|
+
if (matchesKey(data, "tab")) {
|
|
783
|
+
this.activeTab = ((this.activeTab + 1) % 3) as 0 | 1 | 2;
|
|
784
|
+
this.tui?.requestRender?.();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (data === "1") {
|
|
788
|
+
this.activeTab = 0;
|
|
789
|
+
this.tui?.requestRender?.();
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
if (data === "2") {
|
|
793
|
+
this.activeTab = 1;
|
|
794
|
+
this.tui?.requestRender?.();
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
if (data === "3") {
|
|
798
|
+
this.activeTab = 2;
|
|
109
799
|
this.tui?.requestRender?.();
|
|
110
800
|
return;
|
|
111
801
|
}
|
|
112
802
|
|
|
113
|
-
|
|
114
|
-
|
|
803
|
+
// ------------------ DISPATCH: TAB 0 (KERNEL SETTINGS) ------------------
|
|
804
|
+
if (this.activeTab === 0) {
|
|
805
|
+
if (data === "G" || data === "\x07") {
|
|
806
|
+
this.toggleGlobalSetting();
|
|
807
|
+
this.tui?.requestRender?.();
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
if (
|
|
811
|
+
this.matchesBinding(data, "tui.select.confirm", "return") ||
|
|
812
|
+
(matchesKey(data, "space") && this.searchInput.getValue().length === 0)
|
|
813
|
+
) {
|
|
814
|
+
this.activateSettingItem();
|
|
815
|
+
this.tui?.requestRender?.();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (this.matchesBinding(data, "tui.select.up", "up") || matchesKey(data, "k")) {
|
|
819
|
+
if (this.filteredSettingsItems.length > 0) {
|
|
820
|
+
this.settingsSelectedIndex =
|
|
821
|
+
this.settingsSelectedIndex === 0
|
|
822
|
+
? this.filteredSettingsItems.length - 1
|
|
823
|
+
: this.settingsSelectedIndex - 1;
|
|
824
|
+
this.tui?.requestRender?.();
|
|
825
|
+
}
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (this.matchesBinding(data, "tui.select.down", "down") || matchesKey(data, "j")) {
|
|
829
|
+
if (this.filteredSettingsItems.length > 0) {
|
|
830
|
+
this.settingsSelectedIndex =
|
|
831
|
+
this.settingsSelectedIndex === this.filteredSettingsItems.length - 1
|
|
832
|
+
? 0
|
|
833
|
+
: this.settingsSelectedIndex + 1;
|
|
834
|
+
this.tui?.requestRender?.();
|
|
835
|
+
}
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// Forward typing to search bar
|
|
840
|
+
this.searchInput.handleInput(data);
|
|
841
|
+
this.applySettingsFilter(this.searchInput.getValue());
|
|
115
842
|
this.tui?.requestRender?.();
|
|
116
843
|
return;
|
|
117
844
|
}
|
|
118
845
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
846
|
+
// ------------------ DISPATCH: TAB 1 (RETRIEVAL ENGINE) ------------------
|
|
847
|
+
if (this.activeTab === 1) {
|
|
848
|
+
if (matchesKey(data, "left") || matchesKey(data, "h")) {
|
|
849
|
+
this.activeTab = 0;
|
|
850
|
+
this.tui?.requestRender?.();
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
if (matchesKey(data, "right") || matchesKey(data, "l")) {
|
|
854
|
+
this.activeTab = 2;
|
|
855
|
+
this.tui?.requestRender?.();
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (this.matchesBinding(data, "tui.select.up", "up") || matchesKey(data, "k")) {
|
|
860
|
+
this.profileSelectedIndex =
|
|
861
|
+
(this.profileSelectedIndex - 1 + this.profileItems.length) % this.profileItems.length;
|
|
862
|
+
this.tui?.requestRender?.();
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
122
865
|
|
|
123
|
-
if (
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
this.done({ action: "select", profile: item.profile, reindexed: changed });
|
|
866
|
+
if (this.matchesBinding(data, "tui.select.down", "down") || matchesKey(data, "j")) {
|
|
867
|
+
this.profileSelectedIndex = (this.profileSelectedIndex + 1) % this.profileItems.length;
|
|
868
|
+
this.tui?.requestRender?.();
|
|
127
869
|
return;
|
|
128
870
|
}
|
|
129
871
|
|
|
130
|
-
if (
|
|
131
|
-
const
|
|
132
|
-
|
|
872
|
+
if (this.matchesBinding(data, "tui.select.confirm", "return") || matchesKey(data, "space")) {
|
|
873
|
+
const item = this.profileItems[this.profileSelectedIndex];
|
|
874
|
+
if (!item) return;
|
|
875
|
+
|
|
876
|
+
if (item.category === "profile" && item.profile) {
|
|
877
|
+
this.syncProfileSelection(item.profile);
|
|
878
|
+
this.tui?.requestRender?.();
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
if (item.id === "reindex") {
|
|
883
|
+
this.finishModal("reindex");
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
if (item.id === "close") {
|
|
888
|
+
this.finishModal("close");
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// ------------------ DISPATCH: TAB 2 (FILE INDEX SCOPE) ------------------
|
|
896
|
+
const visibleNodes = this.getVisibleTreeNodes();
|
|
897
|
+
if (visibleNodes.length === 0) {
|
|
898
|
+
if (matchesKey(data, "left") || matchesKey(data, "h")) {
|
|
899
|
+
this.activeTab = 1;
|
|
900
|
+
this.tui?.requestRender?.();
|
|
901
|
+
}
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
if (this.treeCursorIndex >= visibleNodes.length) {
|
|
906
|
+
this.treeCursorIndex = Math.max(0, visibleNodes.length - 1);
|
|
907
|
+
}
|
|
908
|
+
const currentNode = visibleNodes[this.treeCursorIndex];
|
|
909
|
+
|
|
910
|
+
if (this.matchesBinding(data, "tui.select.up", "up") || matchesKey(data, "k")) {
|
|
911
|
+
this.treeCursorIndex = Math.max(0, this.treeCursorIndex - 1);
|
|
912
|
+
this.tui?.requestRender?.();
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (this.matchesBinding(data, "tui.select.down", "down") || matchesKey(data, "j")) {
|
|
917
|
+
this.treeCursorIndex = Math.min(visibleNodes.length - 1, this.treeCursorIndex + 1);
|
|
918
|
+
this.tui?.requestRender?.();
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
if (matchesKey(data, "left") || matchesKey(data, "h")) {
|
|
923
|
+
if (currentNode && currentNode.isDir && currentNode.expanded) {
|
|
924
|
+
currentNode.expanded = false;
|
|
925
|
+
this.tui?.requestRender?.();
|
|
133
926
|
return;
|
|
134
927
|
}
|
|
928
|
+
if (currentNode && currentNode.parent) {
|
|
929
|
+
const parentIdx = visibleNodes.findIndex((n) => n.id === currentNode.parent?.id);
|
|
930
|
+
if (parentIdx >= 0) {
|
|
931
|
+
this.treeCursorIndex = parentIdx;
|
|
932
|
+
this.tui?.requestRender?.();
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
this.activeTab = 1;
|
|
937
|
+
this.tui?.requestRender?.();
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
135
940
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.
|
|
941
|
+
if (matchesKey(data, "right") || matchesKey(data, "l")) {
|
|
942
|
+
if (currentNode && currentNode.isDir && !currentNode.expanded) {
|
|
943
|
+
currentNode.expanded = true;
|
|
944
|
+
this.tui?.requestRender?.();
|
|
140
945
|
return;
|
|
141
946
|
}
|
|
142
947
|
}
|
|
948
|
+
|
|
949
|
+
if (matchesKey(data, "space") || data === "x" || data === "X") {
|
|
950
|
+
if (currentNode) {
|
|
951
|
+
this.toggleNodeSelection(currentNode);
|
|
952
|
+
}
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
if (this.matchesBinding(data, "tui.select.confirm", "return")) {
|
|
957
|
+
if (currentNode) {
|
|
958
|
+
if (currentNode.isDir) {
|
|
959
|
+
currentNode.expanded = !currentNode.expanded;
|
|
960
|
+
this.tui?.requestRender?.();
|
|
961
|
+
} else {
|
|
962
|
+
this.toggleNodeSelection(currentNode);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
private finishModal(action: "select" | "reindex" | "close"): void {
|
|
969
|
+
// 1. Commit any changes from Tab 0 & Tab 1 (profile selection is synchronized into Tab 0)
|
|
970
|
+
this.applySettingsChanges();
|
|
971
|
+
|
|
972
|
+
const initialNormalized = this.initialProfile === "hybrid" ? "full" : this.initialProfile;
|
|
973
|
+
const profileChanged = this.selectedProfile !== initialNormalized;
|
|
974
|
+
if (profileChanged && !this.options.deps?.invalidateConfig) {
|
|
975
|
+
this.index?.setProfile?.(this.selectedProfile);
|
|
976
|
+
}
|
|
977
|
+
const currentProfile = this.index?.getProfile ? this.index.getProfile() : this.selectedProfile;
|
|
978
|
+
|
|
979
|
+
// 2. Commit any changes from Tab 2 Scope
|
|
980
|
+
const hasScopeChanges = this.hasExcludedPathsChanged();
|
|
981
|
+
if (hasScopeChanges) {
|
|
982
|
+
if (this.index?.setExcludedPaths) {
|
|
983
|
+
this.index.setExcludedPaths(this.excludedPaths);
|
|
984
|
+
}
|
|
985
|
+
try {
|
|
986
|
+
saveProjectKernelConfig(this.currentCwd, {
|
|
987
|
+
retrieval: { excluded_paths: Array.from(this.excludedPaths) },
|
|
988
|
+
});
|
|
989
|
+
this.options.deps?.invalidateConfig?.(this.currentCwd, this.options.ctx);
|
|
990
|
+
} catch (error) {
|
|
991
|
+
console.error("[agent-kernel] Failed to save excluded paths to project config:", error);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
this.done({
|
|
996
|
+
action,
|
|
997
|
+
profile: this.selectedProfile || currentProfile,
|
|
998
|
+
reindexed: action === "reindex" || profileChanged,
|
|
999
|
+
excludedPathsChanged: hasScopeChanges,
|
|
1000
|
+
});
|
|
143
1001
|
}
|
|
144
1002
|
|
|
1003
|
+
invalidate(): void {}
|
|
1004
|
+
|
|
1005
|
+
// =========================================================================
|
|
1006
|
+
// RENDER DISPATCHER
|
|
1007
|
+
// =========================================================================
|
|
145
1008
|
render(width: number): string[] {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
1009
|
+
const lines: string[] = [];
|
|
1010
|
+
const borderColor = (s: string) => (this.theme?.fg ? this.theme.fg("border", s) : `\x1b[38;5;240m${s}\x1b[0m`);
|
|
1011
|
+
|
|
1012
|
+
// Top dynamic border
|
|
1013
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
1014
|
+
lines.push("");
|
|
1015
|
+
|
|
1016
|
+
// Tab Bar Header (3 Tabs)
|
|
1017
|
+
const tab0Active = this.activeTab === 0;
|
|
1018
|
+
const tab1Active = this.activeTab === 1;
|
|
1019
|
+
const tab2Active = this.activeTab === 2;
|
|
1020
|
+
|
|
1021
|
+
const tab0Text = "Kernel Settings";
|
|
1022
|
+
const tab1Text = "Retrieval Engine";
|
|
1023
|
+
const tab2Text = "File Index Scope";
|
|
1024
|
+
|
|
1025
|
+
const tab0Rendered = tab0Active
|
|
1026
|
+
? (this.theme?.fg ? this.theme.fg("accent", this.theme.bold(tab0Text)) : `\x1b[1;36m${tab0Text}\x1b[0m`)
|
|
1027
|
+
: (this.theme?.fg ? this.theme.fg("muted", tab0Text) : `\x1b[90m${tab0Text}\x1b[0m`);
|
|
1028
|
+
|
|
1029
|
+
const tab1Rendered = tab1Active
|
|
1030
|
+
? (this.theme?.fg ? this.theme.fg("accent", this.theme.bold(tab1Text)) : `\x1b[1;36m${tab1Text}\x1b[0m`)
|
|
1031
|
+
: (this.theme?.fg ? this.theme.fg("muted", tab1Text) : `\x1b[90m${tab1Text}\x1b[0m`);
|
|
1032
|
+
|
|
1033
|
+
const tab2Rendered = tab2Active
|
|
1034
|
+
? (this.theme?.fg ? this.theme.fg("accent", this.theme.bold(tab2Text)) : `\x1b[1;36m${tab2Text}\x1b[0m`)
|
|
1035
|
+
: (this.theme?.fg ? this.theme.fg("muted", tab2Text) : `\x1b[90m${tab2Text}\x1b[0m`);
|
|
1036
|
+
|
|
1037
|
+
const tabSep = this.theme?.fg ? this.theme.fg("dim", " │ ") : " │ ";
|
|
1038
|
+
lines.push(` ${tab0Rendered}${tabSep}${tab1Rendered}${tabSep}${tab2Rendered}`);
|
|
1039
|
+
lines.push("");
|
|
1040
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
148
1041
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
1042
|
+
// ------------------ RENDER: TAB 0 (KERNEL SETTINGS) ------------------
|
|
1043
|
+
if (this.activeTab === 0) {
|
|
1044
|
+
lines.push(...this.searchInput.render(width, this.theme));
|
|
1045
|
+
lines.push("");
|
|
1046
|
+
|
|
1047
|
+
if (this.filteredSettingsItems.length === 0) {
|
|
1048
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", " No matching settings") : " No matching settings");
|
|
1049
|
+
lines.push("");
|
|
1050
|
+
lines.push(
|
|
1051
|
+
this.theme?.fg
|
|
1052
|
+
? this.theme.fg("dim", " Type to search · Enter/Space to cycle · Esc to cancel")
|
|
1053
|
+
: " Type to search · Enter/Space to cycle · Esc to cancel",
|
|
1054
|
+
);
|
|
1055
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
1056
|
+
return lines;
|
|
153
1057
|
}
|
|
154
|
-
return s + " ".repeat(Math.max(0, len - vis));
|
|
155
|
-
};
|
|
156
1058
|
|
|
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
|
-
|
|
1059
|
+
const maxLabelWidth = Math.min(
|
|
1060
|
+
38,
|
|
1061
|
+
Math.max(...this.filteredSettingsItems.map((i) => visibleWidth(i.label))),
|
|
1062
|
+
);
|
|
1063
|
+
let currentCat: string | null = null;
|
|
1064
|
+
|
|
1065
|
+
for (let i = 0; i < this.filteredSettingsItems.length; i++) {
|
|
1066
|
+
const item = this.filteredSettingsItems[i];
|
|
1067
|
+
if (item.category !== currentCat) {
|
|
1068
|
+
currentCat = item.category;
|
|
1069
|
+
if (lines.length > 5) lines.push("");
|
|
1070
|
+
const catHeader = this.theme?.fg
|
|
1071
|
+
? this.theme.fg("accent", this.theme.bold(`[${currentCat}]`))
|
|
1072
|
+
: `\x1b[1;34m[${currentCat}]\x1b[0m`;
|
|
1073
|
+
lines.push(` ${catHeader}`);
|
|
1074
|
+
}
|
|
1075
|
+
const isSelected = i === this.settingsSelectedIndex;
|
|
1076
|
+
const cursor = isSelected
|
|
1077
|
+
? (this.theme?.fg ? ` ${this.theme.fg("accent", "→ ")}` : " \x1b[36m→ \x1b[0m")
|
|
1078
|
+
: " ";
|
|
1079
|
+
const labelPadded =
|
|
1080
|
+
item.label + " ".repeat(Math.max(0, maxLabelWidth - visibleWidth(item.label)));
|
|
1081
|
+
const labelText = isSelected
|
|
1082
|
+
? (this.theme?.fg ? this.theme.fg("accent", labelPadded) : `\x1b[36m${labelPadded}\x1b[0m`)
|
|
1083
|
+
: labelPadded;
|
|
1084
|
+
|
|
1085
|
+
const separator = " ";
|
|
1086
|
+
const prefixWidth = visibleWidth(cursor);
|
|
1087
|
+
const usedWidth = prefixWidth + maxLabelWidth + visibleWidth(separator);
|
|
1088
|
+
const valueMaxWidth = Math.max(10, width - usedWidth - 2);
|
|
1089
|
+
const truncatedVal = truncateToWidth(item.currentValue, valueMaxWidth, "");
|
|
1090
|
+
|
|
1091
|
+
let valueText: string;
|
|
1092
|
+
if (item.isGlobal) {
|
|
1093
|
+
const yellowStr = this.theme?.fg
|
|
1094
|
+
? this.theme.fg("warning", truncatedVal)
|
|
1095
|
+
: `\x1b[33m${truncatedVal}\x1b[0m`;
|
|
1096
|
+
valueText = isSelected
|
|
1097
|
+
? (this.theme?.fg ? this.theme.bold(yellowStr) : `\x1b[1;33m${truncatedVal}\x1b[0m`)
|
|
1098
|
+
: yellowStr;
|
|
1099
|
+
} else {
|
|
1100
|
+
valueText = isSelected
|
|
1101
|
+
? (this.theme?.fg ? this.theme.fg("accent", truncatedVal) : `\x1b[36m${truncatedVal}\x1b[0m`)
|
|
1102
|
+
: (this.theme?.fg ? this.theme.fg("muted", truncatedVal) : `\x1b[90m${truncatedVal}\x1b[0m`);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
lines.push(truncateToWidth(cursor + labelText + separator + valueText, width));
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
const selectedItem = this.filteredSettingsItems[this.settingsSelectedIndex];
|
|
1109
|
+
const currentDesc = selectedItem?.descriptions?.[selectedItem.currentValue] || "";
|
|
1110
|
+
if (currentDesc) {
|
|
1111
|
+
lines.push("");
|
|
1112
|
+
const wrapped = wrapTextWithAnsi(currentDesc, width - 6);
|
|
1113
|
+
for (const line of wrapped) {
|
|
1114
|
+
lines.push(this.theme?.fg ? ` ${this.theme.fg("dim", line)}` : ` \x1b[2m${line}\x1b[0m`);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
lines.push("");
|
|
1119
|
+
const hintText = " Type search · Enter/Space cycle · G toggle global · Tab next tab · Esc close & apply";
|
|
1120
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", hintText) : `\x1b[2m${hintText}\x1b[0m`);
|
|
1121
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
1122
|
+
return lines;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// ------------------ RENDER: TAB 1 (RETRIEVAL ENGINE) ------------------
|
|
1126
|
+
if (this.activeTab === 1) {
|
|
1127
|
+
const status = this.index?.getStatus ? this.index.getStatus() : {
|
|
1128
|
+
engineState: "ready",
|
|
1129
|
+
pipelineDesc: "BM25",
|
|
1130
|
+
effectiveProfile: "lean",
|
|
1131
|
+
chunkCount: 0,
|
|
1132
|
+
fileCount: 0,
|
|
1133
|
+
vectorCount: 0,
|
|
1134
|
+
rssMemoryMB: 0,
|
|
1135
|
+
hardwareInfo: "",
|
|
1136
|
+
isModelCached: false,
|
|
1137
|
+
modelStatus: "ready",
|
|
1138
|
+
};
|
|
1139
|
+
const currentProfile = this.selectedProfile;
|
|
1140
|
+
|
|
1141
|
+
const title = this.theme?.fg
|
|
1142
|
+
? this.theme.fg("accent", this.theme.bold("Codebase Retrieval Engine"))
|
|
1143
|
+
: "\x1b[1;36mCodebase Retrieval Engine\x1b[0m";
|
|
1144
|
+
lines.push(` ${title}`);
|
|
1145
|
+
|
|
1146
|
+
const statusParts = [
|
|
1147
|
+
`Status: ${status.engineState}`,
|
|
1148
|
+
`Active: ${status.effectiveProfile.toUpperCase()}`,
|
|
1149
|
+
`${status.chunkCount} chunks in ${status.fileCount} files`,
|
|
1150
|
+
];
|
|
1151
|
+
if (status.vectorCount > 0) statusParts.push(`${status.vectorCount} vectors`);
|
|
1152
|
+
statusParts.push(`RSS ${status.rssMemoryMB} MB`);
|
|
1153
|
+
const statusSummary = statusParts.join(" · ");
|
|
1154
|
+
lines.push(this.theme?.fg ? ` ${this.theme.fg("muted", statusSummary)}` : ` \x1b[90m${statusSummary}\x1b[0m`);
|
|
1155
|
+
lines.push("");
|
|
1156
|
+
|
|
1157
|
+
let currentCat: string | null = null;
|
|
1158
|
+
const maxLabelWidth = 22;
|
|
1159
|
+
|
|
1160
|
+
for (let i = 0; i < this.profileItems.length; i++) {
|
|
1161
|
+
const item = this.profileItems[i];
|
|
1162
|
+
const catLabel = item.category === "profile" ? "Engine Profiles" : "Workspace Actions";
|
|
1163
|
+
if (catLabel !== currentCat) {
|
|
1164
|
+
currentCat = catLabel;
|
|
1165
|
+
if (lines.length > 7) lines.push("");
|
|
1166
|
+
const catHeader = this.theme?.fg
|
|
1167
|
+
? this.theme.fg("accent", this.theme.bold(`[${currentCat}]`))
|
|
1168
|
+
: `\x1b[1;34m[${currentCat}]\x1b[0m`;
|
|
1169
|
+
lines.push(` ${catHeader}`);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
const isSelected = i === this.profileSelectedIndex;
|
|
1173
|
+
const isCurrentProfile =
|
|
1174
|
+
item.category === "profile" &&
|
|
1175
|
+
item.profile === (currentProfile === "hybrid" ? "full" : currentProfile);
|
|
1176
|
+
|
|
1177
|
+
const cursor = isSelected
|
|
1178
|
+
? (this.theme?.fg ? ` ${this.theme.fg("accent", "→ ")}` : " \x1b[36m→ \x1b[0m")
|
|
1179
|
+
: " ";
|
|
1180
|
+
|
|
1181
|
+
let indicator = " ";
|
|
1182
|
+
if (item.category === "profile") {
|
|
1183
|
+
indicator = isCurrentProfile
|
|
1184
|
+
? (this.theme?.fg ? this.theme.fg("accent", "◉") : "\x1b[36m◉\x1b[0m")
|
|
1185
|
+
: (this.theme?.fg ? this.theme.fg("muted", "○") : "\x1b[90m○\x1b[0m");
|
|
1186
|
+
} else {
|
|
1187
|
+
indicator = item.id === "reindex"
|
|
1188
|
+
? (this.theme?.fg ? this.theme.fg("accent", "↺") : "\x1b[36m↺\x1b[0m")
|
|
1189
|
+
: (this.theme?.fg ? this.theme.fg("dim", "✕") : "\x1b[2m✕\x1b[0m");
|
|
251
1190
|
}
|
|
252
1191
|
|
|
1192
|
+
const labelPadded = item.label + " ".repeat(Math.max(0, maxLabelWidth - visibleWidth(item.label)));
|
|
1193
|
+
const labelText = isSelected
|
|
1194
|
+
? (this.theme?.fg ? this.theme.fg("accent", labelPadded) : `\x1b[36m${labelPadded}\x1b[0m`)
|
|
1195
|
+
: labelPadded;
|
|
1196
|
+
|
|
253
1197
|
let descExtra = "";
|
|
254
|
-
if (item.profile === "
|
|
1198
|
+
if (item.profile === "full") {
|
|
255
1199
|
if (!status.isModelCached) {
|
|
256
|
-
descExtra = ` ${
|
|
1200
|
+
descExtra = this.theme?.fg ? ` ${this.theme.fg("warning", "(~147 MB download)")}` : " (~147 MB download)";
|
|
257
1201
|
} else {
|
|
258
|
-
descExtra = ` ${
|
|
1202
|
+
descExtra = this.theme?.fg ? ` ${this.theme.fg("success", "(ready)")}` : " (ready)";
|
|
259
1203
|
}
|
|
260
1204
|
}
|
|
261
1205
|
|
|
262
|
-
const
|
|
263
|
-
const
|
|
1206
|
+
const descStr = `${item.desc}${descExtra}`;
|
|
1207
|
+
const descText = this.theme?.fg ? this.theme.fg("dim", descStr) : `\x1b[2m${descStr}\x1b[0m`;
|
|
264
1208
|
|
|
265
|
-
|
|
1209
|
+
const lineContent = `${cursor}${indicator} ${labelText} ${descText}`;
|
|
1210
|
+
lines.push(truncateToWidth(lineContent, width));
|
|
266
1211
|
}
|
|
267
|
-
}
|
|
268
1212
|
|
|
269
|
-
|
|
270
|
-
|
|
1213
|
+
const selected = this.profileItems[this.profileSelectedIndex];
|
|
1214
|
+
if (selected) {
|
|
1215
|
+
lines.push("");
|
|
1216
|
+
let detailText = selected.desc;
|
|
1217
|
+
if (selected.id === "auto") {
|
|
1218
|
+
detailText = `Auto-detect: selects Lean on machines with < 4 CPUs, or Full on machines with >= 4 CPUs (detected: ${status.hardwareInfo}).`;
|
|
1219
|
+
} else if (selected.id === "lean") {
|
|
1220
|
+
detailText = "Lean mode: fast AST BM25 lexical keyword search. Uses 0% CPU background overhead and 0 MB extra RAM.";
|
|
1221
|
+
} else if (selected.id === "full") {
|
|
1222
|
+
detailText = `Full mode: hybrid AST BM25 + 768-dim vector embeddings (Alibaba-NLP/gte-modernbert-base). Model status: ${status.modelStatus}.`;
|
|
1223
|
+
} else if (selected.id === "off") {
|
|
1224
|
+
detailText = "Disable engine: unloads code search index and embeddings from memory, removing code_search from active tools.";
|
|
1225
|
+
} else if (selected.id === "reindex") {
|
|
1226
|
+
detailText = "Re-index workspace: clears cached AST chunks and vector embeddings, rescanning all workspace source files.";
|
|
1227
|
+
} else if (selected.id === "close") {
|
|
1228
|
+
detailText = "Close panel: dismisses this settings dialog without making further changes.";
|
|
1229
|
+
}
|
|
271
1230
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const cursor = isSelected ? `${fgTitle} > ` : " ";
|
|
278
|
-
const bullet = `${fgDim}[-]`;
|
|
1231
|
+
const wrapped = wrapTextWithAnsi(detailText, width - 6);
|
|
1232
|
+
for (const w of wrapped) {
|
|
1233
|
+
lines.push(this.theme?.fg ? ` ${this.theme.fg("dim", w)}` : ` \x1b[2m${w}\x1b[0m`);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
279
1236
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
1237
|
+
lines.push("");
|
|
1238
|
+
const hintText = " ↑/↓: navigate · Enter/Space: select · Tab: next tab · Esc: close & apply";
|
|
1239
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", hintText) : `\x1b[2m${hintText}\x1b[0m`);
|
|
1240
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
1241
|
+
return lines;
|
|
1242
|
+
}
|
|
283
1243
|
|
|
284
|
-
|
|
285
|
-
|
|
1244
|
+
// ------------------ RENDER: TAB 2 (FILE INDEX SCOPE) ------------------
|
|
1245
|
+
const visibleNodes = this.getVisibleTreeNodes();
|
|
286
1246
|
|
|
287
|
-
|
|
288
|
-
|
|
1247
|
+
let totalIndexedFiles = 0;
|
|
1248
|
+
let totalIndexedChunks = 0;
|
|
1249
|
+
for (const root of this.treeRoots) {
|
|
1250
|
+
const countActive = (n: ScopeTreeNode) => {
|
|
1251
|
+
for (const c of n.children) {
|
|
1252
|
+
if (c.isDir) {
|
|
1253
|
+
countActive(c);
|
|
1254
|
+
} else if (!this.isPathExcluded(c.relPath)) {
|
|
1255
|
+
totalIndexedFiles++;
|
|
1256
|
+
totalIndexedChunks += c.chunkCount;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
countActive(root);
|
|
289
1261
|
}
|
|
290
1262
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
);
|
|
297
|
-
cardLines.push(bgCard + fgBorder + `╰${"─".repeat(innerW)}╯` + reset);
|
|
1263
|
+
const scopeHeader = this.theme?.fg
|
|
1264
|
+
? this.theme.fg("accent", this.theme.bold("Workspace Index Scope"))
|
|
1265
|
+
: "\x1b[1;36mWorkspace Index Scope\x1b[0m";
|
|
1266
|
+
const scopeStats = `${totalIndexedFiles} files selected · ${totalIndexedChunks} chunks indexed`;
|
|
1267
|
+
lines.push(` ${scopeHeader} ${this.theme?.fg ? this.theme.fg("muted", `(${scopeStats})`) : `(${scopeStats})`}`);
|
|
1268
|
+
lines.push("");
|
|
298
1269
|
|
|
299
|
-
|
|
300
|
-
|
|
1270
|
+
if (visibleNodes.length === 0) {
|
|
1271
|
+
lines.push(this.theme?.fg ? this.theme.fg("muted", " No indexable source code files found in workspace.") : " No indexable source code files found in workspace.");
|
|
1272
|
+
} else {
|
|
1273
|
+
if (this.treeCursorIndex >= visibleNodes.length) {
|
|
1274
|
+
this.treeCursorIndex = Math.max(0, visibleNodes.length - 1);
|
|
1275
|
+
}
|
|
1276
|
+
const maxVisibleRows = 10;
|
|
1277
|
+
if (this.treeCursorIndex < this.treeScrollOffset) {
|
|
1278
|
+
this.treeScrollOffset = this.treeCursorIndex;
|
|
1279
|
+
} else if (this.treeCursorIndex >= this.treeScrollOffset + maxVisibleRows) {
|
|
1280
|
+
this.treeScrollOffset = Math.max(0, this.treeCursorIndex - maxVisibleRows + 1);
|
|
1281
|
+
}
|
|
301
1282
|
|
|
302
|
-
|
|
303
|
-
const leftPad = Math.max(0, Math.floor((width - cardWidth) / 2));
|
|
304
|
-
const rightPad = Math.max(0, width - cardWidth - leftPad);
|
|
1283
|
+
const visibleSlice = visibleNodes.slice(this.treeScrollOffset, this.treeScrollOffset + maxVisibleRows);
|
|
305
1284
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
1285
|
+
if (this.treeScrollOffset > 0) {
|
|
1286
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", ` ▲ +${this.treeScrollOffset} more above`) : ` ▲ +${this.treeScrollOffset} more above`);
|
|
1287
|
+
}
|
|
309
1288
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
};
|
|
1289
|
+
for (let i = 0; i < visibleSlice.length; i++) {
|
|
1290
|
+
const node = visibleSlice[i];
|
|
1291
|
+
const absoluteIndex = this.treeScrollOffset + i;
|
|
1292
|
+
const isCursor = absoluteIndex === this.treeCursorIndex;
|
|
315
1293
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
scrim(left) +
|
|
320
|
-
"\x1b[48;5;232m\x1b[38;5;233m" +
|
|
321
|
-
"▀".repeat(card) +
|
|
322
|
-
reset +
|
|
323
|
-
scrim(right)
|
|
324
|
-
);
|
|
325
|
-
};
|
|
1294
|
+
const cursor = isCursor
|
|
1295
|
+
? (this.theme?.fg ? ` ${this.theme.fg("accent", "→ ")}` : " \x1b[36m→ \x1b[0m")
|
|
1296
|
+
: " ";
|
|
326
1297
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
1298
|
+
let checkbox = "□ ";
|
|
1299
|
+
if (!node.isDir) {
|
|
1300
|
+
const isExcluded = this.isPathExcluded(node.relPath);
|
|
1301
|
+
checkbox = isExcluded
|
|
1302
|
+
? (this.theme?.fg ? `${this.theme.fg("muted", "□")} ` : "□ ")
|
|
1303
|
+
: (this.theme?.fg ? `${this.theme.fg("accent", "■")} ` : "■ ");
|
|
1304
|
+
} else {
|
|
1305
|
+
const state = this.getFolderSelectionState(node);
|
|
1306
|
+
if (state === "all") {
|
|
1307
|
+
checkbox = this.theme?.fg ? `${this.theme.fg("accent", "■")} ` : "■ ";
|
|
1308
|
+
} else if (state === "some") {
|
|
1309
|
+
checkbox = this.theme?.fg ? `${this.theme.fg("warning", "◪")} ` : "◪ ";
|
|
1310
|
+
} else {
|
|
1311
|
+
checkbox = this.theme?.fg ? `${this.theme.fg("muted", "□")} ` : "□ ";
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
330
1314
|
|
|
331
|
-
|
|
1315
|
+
const expandGlyph = node.isDir
|
|
1316
|
+
? (node.expanded ? "▾ " : "▸ ")
|
|
1317
|
+
: " ";
|
|
332
1318
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
1319
|
+
const indent = " ".repeat(node.depth);
|
|
1320
|
+
const nameStr = node.isDir ? `${node.name}/` : node.name;
|
|
1321
|
+
const labelText = isCursor
|
|
1322
|
+
? (this.theme?.fg ? this.theme.fg("accent", nameStr) : `\x1b[36m${nameStr}\x1b[0m`)
|
|
1323
|
+
: (node.isDir ? (this.theme?.fg ? this.theme.bold(nameStr) : nameStr) : nameStr);
|
|
1324
|
+
|
|
1325
|
+
let badgeStr = "";
|
|
1326
|
+
if (node.isDir) {
|
|
1327
|
+
badgeStr = `(${node.chunkCount} chunks · ${node.fileCount} files)`;
|
|
1328
|
+
} else {
|
|
1329
|
+
badgeStr = `(${node.chunkCount} chunk${node.chunkCount === 1 ? "" : "s"})`;
|
|
1330
|
+
}
|
|
1331
|
+
const badgeText = this.theme?.fg ? this.theme.fg("dim", badgeStr) : `\x1b[2m${badgeStr}\x1b[0m`;
|
|
1332
|
+
|
|
1333
|
+
const rowLine = `${cursor}${checkbox} ${indent}${expandGlyph}${labelText} ${badgeText}`;
|
|
1334
|
+
lines.push(truncateToWidth(rowLine, width));
|
|
1335
|
+
}
|
|
337
1336
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
1337
|
+
const remainingBelow = visibleNodes.length - (this.treeScrollOffset + visibleSlice.length);
|
|
1338
|
+
if (remainingBelow > 0) {
|
|
1339
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", ` ▼ +${remainingBelow} more below`) : ` ▼ +${remainingBelow} more below`);
|
|
1340
|
+
}
|
|
342
1341
|
}
|
|
343
1342
|
|
|
344
|
-
|
|
345
|
-
|
|
1343
|
+
const currentNode = visibleNodes[this.treeCursorIndex];
|
|
1344
|
+
if (currentNode) {
|
|
1345
|
+
lines.push("");
|
|
1346
|
+
if (!currentNode.isDir) {
|
|
1347
|
+
const isExcluded = this.isPathExcluded(currentNode.relPath);
|
|
1348
|
+
const statusTag = isExcluded
|
|
1349
|
+
? (this.theme?.fg ? this.theme.fg("warning", "EXCLUDED") : "EXCLUDED")
|
|
1350
|
+
: (this.theme?.fg ? this.theme.fg("success", "INDEXED") : "INDEXED");
|
|
1351
|
+
|
|
1352
|
+
const previewTitle = this.theme?.fg
|
|
1353
|
+
? this.theme.fg("accent", `Preview: ${currentNode.relPath}`)
|
|
1354
|
+
: `Preview: ${currentNode.relPath}`;
|
|
1355
|
+
lines.push(` ${previewTitle} ${this.theme?.fg ? this.theme.fg("dim", `[${statusTag}]`) : `[${statusTag}]`}`);
|
|
346
1356
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
1357
|
+
const previewDetail = `Will produce ${currentNode.chunkCount} code chunk(s) (functions, classes, semantic AST blocks)`;
|
|
1358
|
+
lines.push(this.theme?.fg ? ` ${this.theme.fg("dim", previewDetail)}` : ` \x1b[2m${previewDetail}\x1b[0m`);
|
|
1359
|
+
} else {
|
|
1360
|
+
const state = this.getFolderSelectionState(currentNode);
|
|
1361
|
+
const stateText = state === "all" ? "ALL INCLUDED" : state === "some" ? "PARTIALLY INCLUDED" : "ALL EXCLUDED";
|
|
1362
|
+
const previewTitle = this.theme?.fg
|
|
1363
|
+
? this.theme.fg("accent", `Preview Folder: ${currentNode.relPath}/`)
|
|
1364
|
+
: `Preview Folder: ${currentNode.relPath}/`;
|
|
1365
|
+
lines.push(` ${previewTitle} ${this.theme?.fg ? this.theme.fg("dim", `[${stateText}]`) : `[${stateText}]`}`);
|
|
1366
|
+
|
|
1367
|
+
const previewDetail = `Contains ${currentNode.fileCount} code file(s) across this directory tree (${currentNode.chunkCount} total chunks)`;
|
|
1368
|
+
lines.push(this.theme?.fg ? ` ${this.theme.fg("dim", previewDetail)}` : ` \x1b[2m${previewDetail}\x1b[0m`);
|
|
1369
|
+
}
|
|
350
1370
|
}
|
|
351
1371
|
|
|
352
|
-
|
|
353
|
-
|
|
1372
|
+
lines.push("");
|
|
1373
|
+
const hintText = " ↑/↓: navigate · Space: toggle [x] · Enter/→: expand · Tab: next tab · Esc: close & apply";
|
|
1374
|
+
lines.push(this.theme?.fg ? this.theme.fg("dim", hintText) : `\x1b[2m${hintText}\x1b[0m`);
|
|
1375
|
+
lines.push(borderColor("─".repeat(Math.max(1, width))));
|
|
354
1376
|
|
|
355
|
-
|
|
356
|
-
|
|
1377
|
+
return lines;
|
|
1378
|
+
}
|
|
357
1379
|
}
|
|
1380
|
+
|
|
1381
|
+
// Backwards-compatible export alias for any legacy callers
|
|
1382
|
+
export { UnifiedControlModal as SearchControlModal };
|