JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feature:/config支持交互面板
openJiuwen-bota09f3085cc83
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.tsindex 8c14528f4c..073c223112 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts@@ -407,45 +407,69 @@ export function createConfigCommand(): SlashCommand {},{name: "list",- description: "List all configurable items",+ description: "Interactive configuration editor",kind: CommandKind.BUILT_IN,takesArgs: false,action: async (ctx) => {- let payload: Record<string, unknown> & { schema?: ConfigItemSchema[] };- try {- payload = await ctx.request<Record<string, unknown> & { schema?: ConfigItemSchema[] }>(- "config.get",- {},- );- } catch (error) {- const message = error instanceof Error ? error.message : String(error);- ctx.addItem(addError(ctx.sessionId, `failed to load config: ${message}`));- return;- }- const schemaList = payload.schema ?? [];- const groups = groupConfigSchemaByGroup(schemaList);- const items: Array<{ label: string; value?: string; description?: string }> = [];- for (const [groupName, schemas] of Object.entries(groups)) {- items.push({ label: `── ${groupName} ──`, description: "" });- for (const schema of schemas) {- const currentValue = String(payload[schema.key] ?? "");+ if (ctx.enterConfigEditor) {+ let payload: Record<string, unknown> & { schema?: ConfigItemSchema[] };+ try {+ payload = await ctx.request<Record<string, unknown> & { schema?: ConfigItemSchema[] }>(+ "config.get",+ {},+ );+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ ctx.addItem(addError(ctx.sessionId, `failed to load config: ${message}`));+ return;+ }+ const mergedPayload: Record<string, unknown> & { schema?: ConfigItemSchema[] } = {+ ...payload,+ schema: [...(payload.schema ?? []), ...FRONTEND_SCHEMAS],+ };+ for (const schema of FRONTEND_SCHEMAS) {+ if (mergedPayload[schema.key] === undefined) {+ mergedPayload[schema.key] = getFrontendValue(ctx, schema.key);+ }+ }+ ctx.enterConfigEditor(undefined, mergedPayload);+ } else {+ // Fallback: show text-based config list+ let payload: Record<string, unknown> & { schema?: ConfigItemSchema[] };+ try {+ payload = await ctx.request<Record<string, unknown> & { schema?: ConfigItemSchema[] }>(+ "config.get",+ {},+ );+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ ctx.addItem(addError(ctx.sessionId, `failed to load config: ${message}`));+ return;+ }+ const schemaList = payload.schema ?? [];+ const groups = groupConfigSchemaByGroup(schemaList);+ const items: Array<{ label: string; value?: string; description?: string }> = [];+ for (const [groupName, schemas] of Object.entries(groups)) {+ items.push({ label: `── ${groupName} ──`, description: "" });+ for (const schema of schemas) {+ const currentValue = String(payload[schema.key] ?? "");+ items.push({+ label: schema.key,+ value: schema.sensitive ? maskSensitive(currentValue) : currentValue,+ description: schema.description ?? schema.label,+ });+ }+ }+ items.push({ label: "── Theme ──", description: "" });+ for (const schema of FRONTEND_SCHEMAS) {items.push({label: schema.key,- value: schema.sensitive ? maskSensitive(currentValue) : currentValue,+ value: getFrontendValue(ctx, schema.key),description: schema.description ?? schema.label,});}+ ctx.addItem(addInfo(ctx.sessionId, "All config items", "c", { view: "kv", title: "Config Items", items }));}- // Append frontend-only items- items.push({ label: "── Theme ──", description: "" });- for (const schema of FRONTEND_SCHEMAS) {- items.push({- label: schema.key,- value: getFrontendValue(ctx, schema.key),- description: schema.description ?? schema.label,- });- }- ctx.addItem(addInfo(ctx.sessionId, "All config items", "c", { view: "kv", title: "Config Items", items }));},},{@@ -536,7 +560,32 @@ export function createConfigCommand(): SlashCommand {],action: async (ctx, args) => {if (!args.trim()) {- await showConfigOverview(ctx);+ // Open interactive config editor (like /config edit) instead of just showing text+ if (ctx.enterConfigEditor) {+ let payload: Record<string, unknown> & { schema?: ConfigItemSchema[] };+ try {+ payload = await ctx.request<Record<string, unknown> & { schema?: ConfigItemSchema[] }>(+ "config.get",+ {},+ );+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ ctx.addItem(addError(ctx.sessionId, `failed to load config: ${message}`));+ return;+ }+ const mergedPayload: Record<string, unknown> & { schema?: ConfigItemSchema[] } = {+ ...payload,+ schema: [...(payload.schema ?? []), ...FRONTEND_SCHEMAS],+ };+ for (const schema of FRONTEND_SCHEMAS) {+ if (mergedPayload[schema.key] === undefined) {+ mergedPayload[schema.key] = getFrontendValue(ctx, schema.key);+ }+ }+ ctx.enterConfigEditor(undefined, mergedPayload);+ } else {+ await showConfigOverview(ctx);+ }return;}const key = args.trim();diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.tsindex 9af9416976..bcdcb92f55 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts@@ -170,15 +170,18 @@ type McpToolDetailState = {tool: McpToolItem;};-type ConfigEditorPhase = "select_group" | "select_item" | "select_value" | "input_value";+type ConfigEditorPhase = "search_list" | "select_value" | "input_value";type ConfigEditorState = {phase: ConfigEditorPhase;schemaList: ConfigItemSchema[];currentValues: Record<string, string>;- selectedGroup: string | null;selectedKey: string | null;+ searchQuery: string;+ searchMode: boolean; // true=搜索模式(输入字符过滤), false=浏览模式(导航操作)list: SelectList;+ previousPhase: ConfigEditorPhase | null; // select_value/input_value 返回时用+ savedList: SelectList | null; // 进入子面板前保存的扁平列表,返回时恢复};type StatusViewTab = "status" | "usage" | "config";@@ -503,6 +506,71 @@ function filterResumeSessions(sessions: SessionMeta[], query: string): SelectIte.map(sessionToSelectItem);}+function formatConfigValue(schema: ConfigItemSchema, val: string): string {+ if (schema.type === "toggle") {+ return val === "true" ? "已启用" : "已禁用";+ }+ if (schema.sensitive) {+ if (!val) return "(空)";+ return val.length > 8 ? `${val.slice(0, 4)}****${val.slice(-4)}` : "***";+ }+ return val || "(空)";+}++function filterConfigItems(+ schemas: ConfigItemSchema[],+ currentValues: Record<string, string>,+ query: string,+): SelectItem[] {+ const normalizedQuery = query.toLowerCase();++ // 有搜索词时:纯扁平过滤列表+ if (normalizedQuery) {+ return schemas+ .filter((schema) =>+ schema.key.toLowerCase().includes(normalizedQuery) ||+ schema.label.toLowerCase().includes(normalizedQuery) ||+ (schema.description ?? "").toLowerCase().includes(normalizedQuery) ||+ schema.group.toLowerCase().includes(normalizedQuery)+ )+ .map((schema) => {+ const val = currentValues[schema.key] ?? "";+ const displayVal = formatConfigValue(schema, val);+ return {+ value: schema.key,+ label: `${schema.label}: ${displayVal}`,+ description: schema.description ?? schema.label,+ };+ });+ }++ // 无搜索词时:按分组排列,分组间用分隔符+ const groups: Record<string, ConfigItemSchema[]> = {};+ for (const schema of schemas) {+ const group = schema.group || "Other";+ if (!groups[group]) groups[group] = [];+ groups[group].push(schema);+ }+ const items: SelectItem[] = [];+ for (const [groupName, groupSchemas] of Object.entries(groups)) {+ items.push({+ value: `__group_${groupName}__`,+ label: `── ${groupName} ──`,+ description: `${groupSchemas.length} 项`,+ });+ for (const schema of groupSchemas) {+ const val = currentValues[schema.key] ?? "";+ const displayVal = formatConfigValue(schema, val);+ items.push({+ value: schema.key,+ label: ` ${schema.label}: ${displayVal}`,+ description: schema.description ?? schema.label,+ });+ }+ }+ return items;+}+export class AppScreen implements Component, Focusable {private readonly editor: Editor;private readonly unsubscribe: () => void;@@ -973,45 +1041,7 @@ export class AppScreen implements Component, Focusable {if (!snapshot.pendingQuestion && this.statusViewState !== null) {if (this.statusViewState.phase === "config_editor") {- if (this.configEditorState?.phase === "input_value") {- if (matchesKey(data, "escape")) {- if (this.configEditorState.selectedGroup) {- const groupSchemas = this.configEditorState.schemaList.filter(- (s) => s.group === this.configEditorState!.selectedGroup,- );- this.showConfigGroupItems(- this.configEditorState.selectedGroup,- groupSchemas,- this.configEditorState.currentValues,- );- } else {- this.configEditorState = null;- this.statusViewState = {- ...this.statusViewState,- phase: "tab_view",- tab: "config",- list: this.buildStatusViewTabState("config", this.statusViewState.statusPayload, this.statusViewState.configPayload),- };- }- this.tui.requestRender();- return;- }- if (matchesKey(data, "return")) {- const text = this.editor.getText().trim();- if (text && this.configEditorState.selectedKey) {- const key = this.configEditorState.selectedKey;- const schema = this.configEditorState.schemaList.find((s) => s.key === key);- if (schema) {- void this.applyConfigEditorSet(key, text, schema, this.configEditorState.currentValues);- this.editor.setText("");- }- }- return;- }- this.editor.handleInput(data);- } else if (this.configEditorState) {- this.configEditorState.list.handleInput(data);- }+ this.handleConfigEditorInput(data);this.tui.requestRender();return;}@@ -1033,41 +1063,7 @@ export class AppScreen implements Component, Focusable {}if (!snapshot.pendingQuestion && this.configEditorState !== null) {- if (this.configEditorState.phase === "input_value") {- // Handle Esc to cancel input and go back to group selection- if (matchesKey(data, "escape")) {- if (this.configEditorState.selectedGroup) {- const groupSchemas = this.configEditorState.schemaList.filter(- (s) => s.group === this.configEditorState!.selectedGroup,- );- this.showConfigGroupItems(- this.configEditorState.selectedGroup,- groupSchemas,- this.configEditorState.currentValues,- );- } else {- this.configEditorState = null;- this.tui.requestRender();- }- return;- }- // Handle Enter to submit the config value (single-line input)- if (matchesKey(data, "return")) {- const text = this.editor.getText().trim();- if (text && this.configEditorState.selectedKey) {- const key = this.configEditorState.selectedKey;- const schema = this.configEditorState.schemaList.find((s) => s.key === key);- if (schema) {- void this.applyConfigEditorSet(key, text, schema, this.configEditorState.currentValues);- this.editor.setText("");- }- }- return;- }- this.editor.handleInput(data);- } else {- this.configEditorState.list.handleInput(data);- }+ this.handleConfigEditorInput(data);this.tui.requestRender();return;}@@ -1204,10 +1200,12 @@ export class AppScreen implements Component, Focusable {this.editor.borderColor = snapshot.pendingQuestion? palette.border.question: palette.border.panel;- // When in config editor input_value phase, editor is rendered inside buildConfigEditorLines- // to avoid duplicate rendering, don't include editorLines in that case- const isConfigInputValue = this.configEditorState?.phase === "input_value";- const editorLines = isConfigInputValue+ // When config editor is active (any phase), hide the main editor to prevent+ // IME composing text from appearing in the bottom input box instead of the config panel.+ // input_value phase: editor is rendered inside buildConfigEditorLines.+ // search_list/select_value phase: no text input needed in the main editor.+ const isConfigEditorActive = this.configEditorState !== null;+ const editorLines = isConfigEditorActive? []: this.applySlashCommandHint(this.editor.render(width), width);const composerPreviewLines: string[] = [];@@ -1283,20 +1281,23 @@ export class AppScreen implements Component, Focusable {const text = raw.trim();if (!text) return;- const { content, attachments } = this.buildOutgoingMessage(text);-- // Config editor input_value phase: submit the typed value- if (this.configEditorState?.phase === "input_value" && this.configEditorState.selectedKey) {- const key = this.configEditorState.selectedKey;- const schema = this.configEditorState.schemaList.find((s) => s.key === key);- if (schema) {- void this.applyConfigEditorSet(key, text, schema, this.configEditorState.currentValues);+ // When config editor is active (any phase), don't send chat messages+ if (this.configEditorState !== null) {+ if (this.configEditorState.phase === "input_value" && this.configEditorState.selectedKey) {+ const key = this.configEditorState.selectedKey;+ const schema = this.configEditorState.schemaList.find((s) => s.key === key);+ if (schema) {+ void this.applyConfigEditorSetAndStay(key, text, schema, this.configEditorState.currentValues);+ }+ this.editor.setText("");+ this.composerAttachments = [];}- this.editor.setText("");- this.composerAttachments = [];+ // For search_list / select_value phases, just ignore the submitreturn;}+ const { content, attachments } = this.buildOutgoingMessage(text);+if (!content) return;const snapshot = this.state.getSnapshot();@@ -2467,218 +2468,267 @@ export class AppScreen implements Component, Focusable {};}+ private handleConfigEditorInput(data: string): void {+ if (!this.configEditorState) return;+ const state = this.configEditorState;++ // ── search_list phase ──+ if (state.phase === "search_list") {+ if (state.searchMode) {+ // Search mode: intercept printable chars, backspace, ESC+ const printableChar = this.getPrintableChar(data);+ if (printableChar !== undefined) {+ const newQuery = state.searchQuery + printableChar;+ this.updateConfigSearchQuery(newQuery);+ } else if (matchesKey(data, "backspace")) {+ const newQuery = state.searchQuery.slice(0, -1);+ this.updateConfigSearchQuery(newQuery);+ } else if (matchesKey(data, "escape")) {+ // Layered ESC: clear search query first, then exit search mode+ if (state.searchQuery) {+ this.updateConfigSearchQuery("");+ this.configEditorState = { ...this.configEditorState!, searchMode: false };+ } else {+ this.configEditorState = { ...this.configEditorState!, searchMode: false };+ }+ } else if (matchesKey(data, "return") || matchesKey(data, "space")) {+ const selectedItem = state.list.getSelectedItem();+ if (selectedItem) {+ if (selectedItem.value.startsWith("__group_")) return;+ const schema = state.schemaList.find((s) => s.key === selectedItem.value);+ if (schema) {+ this.handleConfigItemSelectionFromFlatList(schema);+ }+ }+ } else if (matchesKey(data, "up") || matchesKey(data, "down")) {+ state.list.handleInput(data);+ }+ } else {+ // Browse mode: navigation + actions+ const printableChar = this.getPrintableChar(data);+ if (data === "/" || printableChar !== undefined) {+ // Re-enter search mode+ const initialChar = data === "/" ? "" : (printableChar ?? "");+ this.configEditorState = { ...this.configEditorState!, searchMode: true };+ this.updateConfigSearchQuery(initialChar);+ } else if (matchesKey(data, "escape")) {+ this.closeConfigEditor();+ } else if (matchesKey(data, "return") || matchesKey(data, "space")) {+ const selectedItem = state.list.getSelectedItem();+ if (selectedItem) {+ if (selectedItem.value.startsWith("__group_")) return;+ const schema = state.schemaList.find((s) => s.key === selectedItem.value);+ if (schema) {+ this.handleConfigItemSelectionFromFlatList(schema);+ }+ }+ } else {+ state.list.handleInput(data);+ }+ }+ return;+ }++ // ── select_value phase ──+ if (state.phase === "select_value") {+ if (matchesKey(data, "escape")) {+ // Return to search_list with saved list+ const savedList = state.savedList;+ this.configEditorState = {+ ...state,+ phase: state.previousPhase ?? "search_list",+ selectedKey: null,+ previousPhase: null,+ savedList: null,+ list: savedList ?? state.list,+ };+ // If no savedList, rebuild the flat list+ if (!savedList) {+ this.refreshConfigEditorList();+ }+ return;+ }+ // Delegate to list for navigation + selection+ state.list.handleInput(data);+ return;+ }++ // ── input_value phase ──+ if (state.phase === "input_value") {+ if (matchesKey(data, "escape")) {+ // Return to search_list with saved list+ const savedList = state.savedList;+ this.configEditorState = {+ ...state,+ phase: state.previousPhase ?? "search_list",+ selectedKey: null,+ previousPhase: null,+ savedList: null,+ list: savedList ?? state.list,+ };+ if (!savedList) {+ this.refreshConfigEditorList();+ }+ this.editor.setText("");+ return;+ }+ if (matchesKey(data, "return")) {+ const text = this.editor.getText().trim();+ if (text && state.selectedKey) {+ const key = state.selectedKey;+ const schema = state.schemaList.find((s) => s.key === key);+ if (schema) {+ void this.applyConfigEditorSetAndStay(key, text, schema, state.currentValues);+ }+ this.editor.setText("");+ }+ return;+ }+ this.editor.handleInput(data);+ return;+ }+ }+private buildConfigEditorLines(width: number): string[] {if (!this.configEditorState) {return [];}const state = this.configEditorState;- const title =- state.phase === "select_group"- ? "Configuration Editor"- : state.phase === "select_item"- ? state.selectedGroup ?? "Config"- : state.phase === "select_value"- ? `Select value for "${state.selectedKey}"`- : `Enter new value for "${state.selectedKey}"`;- const hint =- state.phase === "input_value"- ? "Enter value · Esc back"- : "↑/↓ choose · Enter confirm · Esc cancel";-- const lines: string[] = [- padToWidth(palette.status.warning(title), width),- ];+ const blank = ""; // Spacer line for visual breathing room- if (- (state.phase === "select_value" || state.phase === "input_value") &&- state.selectedKey- ) {+ const lines: string[] = [];++ // Title line+ if (state.phase === "search_list") {+ lines.push(padToWidth(palette.status.warning("配置编辑器"), width));+ } else if (state.phase === "select_value") {+ const schema = state.schemaList.find((s) => s.key === state.selectedKey);+ lines.push(padToWidth(palette.status.warning(`选择 "${schema?.label ?? state.selectedKey}" 的值`), width));+ } else {+ const schema = state.schemaList.find((s) => s.key === state.selectedKey);+ lines.push(padToWidth(palette.status.warning(`输入 "${schema?.label ?? state.selectedKey}" 的新值`), width));+ }++ lines.push(blank); // Gap between title and content++ // Search box for search_list phase+ if (state.phase === "search_list") {+ if (state.searchMode) {+ lines.push(padToWidth(palette.text.primary(`搜索: ${state.searchQuery}${END_CURSOR}`), width));+ } else {+ lines.push(padToWidth(palette.text.dim("输入搜索 · ↑/↓ 选择 · Enter/空格 修改 · / 搜索 · Esc 关闭"), width));+ }+ lines.push(blank); // Gap between search box and list+ }++ // Current value display for select_value / input_value+ if ((state.phase === "select_value" || state.phase === "input_value") && state.selectedKey) {const schema = state.schemaList.find((s) => s.key === state.selectedKey);const rawVal = state.currentValues[state.selectedKey] ?? "";- const currentVal = schema?.sensitive- ? rawVal.length > 8 ? `${rawVal.slice(0, 4)}****${rawVal.slice(-4)}` : rawVal ? "***" : "(empty)"- : rawVal || "(empty)";- lines.push(padToWidth(palette.text.dim(`current: ${currentVal}`), width));+ const currentVal = formatConfigValue(schema!, rawVal);+ lines.push(padToWidth(palette.text.dim(`当前值: ${currentVal}`), width));+ lines.push(blank); // Gap between current value and content}+ // Content areaif (state.phase === "input_value") {lines.push(...this.editor.render(width));} else {lines.push(...state.list.render(width));}- lines.push(padToWidth(palette.text.dim(hint), width));- return lines;- }-- private openConfigEditor(- focusKey?: string,- configPayload?: Record<string, unknown> & { schema?: ConfigItemSchema[] },- ): void {- const schemaList = configPayload?.schema ?? [];- if (schemaList.length === 0) {- this.state.addItem(addError(this.state.getSnapshot().sessionId, "No config schema available"));- return;- }- const currentValues: Record<string, string> = {};- for (const schema of schemaList) {- currentValues[schema.key] = String(configPayload?.[schema.key] ?? "");- }+ lines.push(blank); // Gap between content and hint- if (focusKey) {- const schema = schemaList.find((s) => s.key === focusKey);- if (schema && schema.type === "select" && schema.options) {- // 用临时的 select_group 状态承载 schemaList/currentValues,再 showConfigValueSelect 会替换成 select_value- this.configEditorState = {- phase: "select_group",- schemaList,- currentValues,- selectedGroup: null,- selectedKey: null,- list: new SelectList([], 1, selectListTheme),- };- this.showConfigValueSelect(schema, currentValues);- return;- }+ // Hint line+ let hint: string;+ if (state.phase === "search_list") {+ hint = state.searchMode+ ? "Backspace 删除 · ↑/↓ 导航 · Enter 选择 · Esc 清除搜索"+ : "↑/↓ 选择 · Enter/空格 修改 · / 搜索 · Esc 关闭";+ } else if (state.phase === "input_value") {+ hint = "输入值 · Enter 确认 · Esc 返回";+ } else {+ hint = "↑/↓ 选择 · Enter 确认 · Esc 返回";}-- this.showConfigGroupSelector(schemaList, currentValues);+ lines.push(padToWidth(palette.text.dim(hint), width));+ return lines;}- private showConfigGroupSelector(- schemaList: ConfigItemSchema[],- currentValues: Record<string, string>,- ): void {- const groups: Record<string, ConfigItemSchema[]> = {};- for (const schema of schemaList) {- const group = schema.group || "Other";- if (!groups[group]) groups[group] = [];- groups[group].push(schema);- }-- const groupItems: SelectItem[] = Object.keys(groups).map((groupName) => ({- value: groupName,- label: groupName,- description: `${groups[groupName].length} items`,- }));+ private updateConfigSearchQuery(query: string): void {+ if (!this.configEditorState) return;+ const filteredItems = filterConfigItems(+ this.configEditorState.schemaList,+ this.configEditorState.currentValues,+ query,+ );const list = new SelectList(- groupItems,- Math.min(Math.max(groupItems.length, 1), 8),+ filteredItems,+ Math.min(Math.max(filteredItems.length, 1), 10),selectListTheme,{ minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 42 },);list.onSelect = (item) => {- this.showConfigGroupItems(item.value, groups[item.value], currentValues);- };- list.onCancel = () => {- if (this.statusViewState) {- this.statusViewState.phase = "tab_view";- this.statusViewState.tab = "config";- this.rebuildStatusViewTabList();- this.configEditorState = null;- this.tui.requestRender();- } else {- this.configEditorState = null;- this.tui.requestRender();- }- };- this.configEditorState = {- phase: "select_group",- schemaList,- currentValues,- selectedGroup: null,- selectedKey: null,- list,- };- this.tui.requestRender();- }-- private showConfigGroupItems(- groupName: string,- schemas: ConfigItemSchema[],- currentValues: Record<string, string>,- ): void {- const items: SelectItem[] = schemas.map((schema) => {- const val = currentValues[schema.key] ?? "";- const displayVal =- schema.type === "toggle"- ? val === "true" ? "Enabled" : "Disabled"- : schema.sensitive- ? val.length > 8 ? `${val.slice(0, 4)}****${val.slice(-4)}` : "***"- : val;- return {- value: schema.key,- label: `${schema.label}: ${displayVal}`,- description: schema.description,- };- });- items.push({ value: "__back__", label: "Back", description: "" });- const list = new SelectList(items, Math.min(Math.max(items.length, 1), 8), selectListTheme, {- minPrimaryColumnWidth: 24,- maxPrimaryColumnWidth: 42,- });- list.onSelect = (item) => {- if (item.value === "__back__") {- this.showConfigGroupSelector(this.configEditorState!.schemaList, currentValues);- return;- }- const schema = schemas.find((s) => s.key === item.value);+ if (item.value.startsWith("__group_")) return; // Skip group headers+ const schema = this.configEditorState!.schemaList.find((s) => s.key === item.value);if (!schema) return;- this.handleConfigItemSelection(schema, currentValues);+ this.handleConfigItemSelectionFromFlatList(schema);};list.onCancel = () => {- if (this.statusViewState) {- this.statusViewState.phase = "tab_view";- this.statusViewState.tab = "config";- this.rebuildStatusViewTabList();- this.configEditorState = null;- this.tui.requestRender();- } else {- this.showConfigGroupSelector(this.configEditorState!.schemaList, currentValues);- }+ this.closeConfigEditor();};this.configEditorState = {- phase: "select_item",- schemaList: this.configEditorState!.schemaList,- currentValues,- selectedGroup: groupName,- selectedKey: null,+ ...this.configEditorState,list,+ searchQuery: query,};this.tui.requestRender();}- private handleConfigItemSelection(+ private handleConfigItemSelectionFromFlatList(schema: ConfigItemSchema,- currentValues: Record<string, string>,): void {+ const currentValues = this.configEditorState!.currentValues;+if (schema.type === "toggle") {const currentVal = currentValues[schema.key] ?? "false";const newValue = currentVal === "true" ? "false" : "true";- void this.applyConfigEditorSet(schema.key, newValue, schema, currentValues);+ void this.applyConfigEditorSetAndStay(schema.key, newValue, schema, currentValues);return;}++ // Save current list for returning later+ const savedList = this.configEditorState!.list;+if (schema.type === "select" && schema.options) {- this.showConfigValueSelect(schema, currentValues);+ const valueList = this.buildConfigValueSelectList(schema, currentValues);+ this.configEditorState = {+ ...this.configEditorState!,+ phase: "select_value",+ selectedKey: schema.key,+ previousPhase: "search_list",+ savedList,+ list: valueList,+ };+ this.tui.requestRender();return;}+// string / password → input modethis.editor.setText("");this.configEditorState = {+ ...this.configEditorState!,phase: "input_value",- schemaList: this.configEditorState!.schemaList,- currentValues,- selectedGroup: this.configEditorState!.selectedGroup,selectedKey: schema.key,- list: this.configEditorState!.list,+ previousPhase: "search_list",+ savedList,};this.tui.requestRender();}- private showConfigValueSelect(+ private buildConfigValueSelectList(schema: ConfigItemSchema,currentValues: Record<string, string>,- ): void {+ ): SelectList {const currentValue = currentValues[schema.key] ?? "";const items: SelectItem[] = (schema.options ?? []).map((option) => ({value: option,@@ -2690,57 +2740,23 @@ export class AppScreen implements Component, Focusable {maxPrimaryColumnWidth: 42,});list.onSelect = (item) => {- void this.applyConfigEditorSet(schema.key, item.value, schema, currentValues);- };- list.onCancel = () => {- if (this.configEditorState?.selectedGroup) {- const groupSchemas = this.configEditorState.schemaList.filter(- (s) => s.group === this.configEditorState!.selectedGroup,- );- this.showConfigGroupItems(this.configEditorState.selectedGroup, groupSchemas, currentValues);- } else if (this.statusViewState) {- this.statusViewState.phase = "tab_view";- this.statusViewState.tab = "config";- this.rebuildStatusViewTabList();- this.configEditorState = null;- this.tui.requestRender();- } else {- this.configEditorState = null;- this.tui.requestRender();- }- };- this.configEditorState = {- phase: "select_value",- schemaList: this.configEditorState!.schemaList,- currentValues,- selectedGroup: this.configEditorState?.selectedGroup ?? null,- selectedKey: schema.key,- list,+ void this.applyConfigEditorSetAndStay(schema.key, item.value, schema, currentValues);};- this.tui.requestRender();+ return list;}- private async applyConfigEditorSet(+ private async applyConfigEditorSetAndStay(key: string,value: string,schema: ConfigItemSchema,currentValues: Record<string, string>,): Promise<void> {- // Handle frontend-only config keys+ // Handle frontend-only config keys (theme)if (key === "theme") {this.state.setThemeName(value as import("./theme.js").ThemeName);currentValues[key] = value;- this.state.addItem(addInfo(this.state.getSnapshot().sessionId, `✓ ${key}: ${value} (applied)`, "c"));- if (this.statusViewState) {- this.statusViewState.phase = "tab_view";- this.statusViewState.tab = "config";- this.rebuildStatusViewTabList();- this.configEditorState = null;- this.tui.requestRender();- } else {- this.configEditorState = null;- this.tui.requestRender();- }+ this.state.addItem(addInfo(this.state.getSnapshot().sessionId, `✓ ${key}: ${value} (已应用)`, "c"));+ this.refreshConfigEditorList();return;}try {@@ -2750,24 +2766,144 @@ export class AppScreen implements Component, Focusable {}>("config.set", { [key]: value });currentValues[key] = value;const msg = result.applied_without_restart- ? `✓ ${key}: ${schema.sensitive ? "***" : value} (applied)`- : `✓ ${key}: ${schema.sensitive ? "***" : value} (restart required)`;+ ? `✓ ${key}: ${schema.sensitive ? "***" : value} (已应用)`+ : `✓ ${key}: ${schema.sensitive ? "***" : value} (需重启)`;this.state.addItem(addInfo(this.state.getSnapshot().sessionId, msg, "c"));} catch (error) {const message = error instanceof Error ? error.message : String(error);this.state.addItem(addError(this.state.getSnapshot().sessionId, `config.set failed: ${message}`));}+ this.refreshConfigEditorList();+ }++ private refreshConfigEditorList(): void {+ if (!this.configEditorState) return;++ // After a change, return to the flat list with browse mode so user can see updated values+ const filteredItems = filterConfigItems(+ this.configEditorState.schemaList,+ this.configEditorState.currentValues,+ this.configEditorState.searchQuery,+ );+ const list = new SelectList(+ filteredItems,+ Math.min(Math.max(filteredItems.length, 1), 10),+ selectListTheme,+ { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 42 },+ );+ list.onSelect = (item) => {+ if (item.value.startsWith("__group_")) return; // Skip group headers+ const schema = this.configEditorState!.schemaList.find((s) => s.key === item.value);+ if (!schema) return;+ this.handleConfigItemSelectionFromFlatList(schema);+ };+ list.onCancel = () => {+ this.closeConfigEditor();+ };++ // If we were in StatusView, return to config tabif (this.statusViewState) {- // Return to config tab in StatusView instead of closing entirelythis.statusViewState.phase = "tab_view";this.statusViewState.tab = "config";this.rebuildStatusViewTabList();this.configEditorState = null;this.tui.requestRender();- } else {- this.configEditorState = null;- this.tui.requestRender();+ return;}++ this.configEditorState = {+ ...this.configEditorState,+ phase: "search_list",+ selectedKey: null,+ previousPhase: null,+ savedList: null,+ searchMode: false,+ list,+ };+ this.tui.requestRender();+ }++ private closeConfigEditor(): void {+ if (this.statusViewState) {+ this.statusViewState.phase = "tab_view";+ this.statusViewState.tab = "config";+ this.rebuildStatusViewTabList();+ }+ this.configEditorState = null;+ this.tui.requestRender();+ }++ private openConfigEditor(+ focusKey?: string,+ configPayload?: Record<string, unknown> & { schema?: ConfigItemSchema[] },+ ): void {+ const schemaList = configPayload?.schema ?? [];+ if (schemaList.length === 0) {+ this.state.addItem(addError(this.state.getSnapshot().sessionId, "No config schema available"));+ return;+ }+ const currentValues: Record<string, string> = {};+ for (const schema of schemaList) {+ currentValues[schema.key] = String(configPayload?.[schema.key] ?? "");+ }++ if (focusKey) {+ const schema = schemaList.find((s) => s.key === focusKey);+ if (schema) {+ // Initialize base state then immediately transition to the item's sub-panel+ const filteredItems = filterConfigItems(schemaList, currentValues, "");+ const baseList = new SelectList(+ filteredItems,+ Math.min(Math.max(filteredItems.length, 1), 10),+ selectListTheme,+ { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 42 },+ );+ this.configEditorState = {+ phase: "search_list",+ schemaList,+ currentValues,+ selectedKey: null,+ searchQuery: "",+ searchMode: true,+ list: baseList,+ previousPhase: null,+ savedList: null,+ };+ this.handleConfigItemSelectionFromFlatList(schema);+ return;+ }+ }++ // Default: start in search_list mode with search enabled (search-first approach)+ const filteredItems = filterConfigItems(schemaList, currentValues, "");+ const list = new SelectList(+ filteredItems,+ Math.min(Math.max(filteredItems.length, 1), 10),+ selectListTheme,+ { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 42 },+ );+ list.onSelect = (item) => {+ if (item.value.startsWith("__group_")) return; // Skip group headers+ const schema = this.configEditorState!.schemaList.find((s) => s.key === item.value);+ if (!schema) return;+ this.handleConfigItemSelectionFromFlatList(schema);+ };+ list.onCancel = () => {+ this.closeConfigEditor();+ };++ this.configEditorState = {+ phase: "search_list",+ schemaList,+ currentValues,+ selectedKey: null,+ searchQuery: "",+ searchMode: true,+ list,+ previousPhase: null,+ savedList: null,+ };+ this.tui.requestRender();}// ──────────────────────────── StatusView ────────────────────────────@@ -3008,19 +3144,28 @@ export class AppScreen implements Component, Focusable {}this.statusViewState.phase = "config_editor";++ // Initialize search_list state then navigate to the item's sub-panel+ const filteredItems = filterConfigItems(schemaList, currentValues, "");+ const baseList = new SelectList(+ filteredItems,+ Math.min(Math.max(filteredItems.length, 1), 10),+ selectListTheme,+ { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 42 },+ );this.configEditorState = {- phase: "select_group",+ phase: "search_list",schemaList,currentValues,- selectedGroup: null,selectedKey: null,- list: new SelectList([], 1, selectListTheme),+ searchQuery: "",+ searchMode: true,+ list: baseList,+ previousPhase: null,+ savedList: null,};-- // Navigate directly to the item's group or value- const group = schema.group || "Other";- const groupSchemas = schemaList.filter((s) => (s.group || "Other") === group);- this.showConfigGroupItems(group, groupSchemas, currentValues);+ // Navigate directly to the item's sub-panel+ this.handleConfigItemSelectionFromFlatList(schema);}private closeStatusView(): void {