Skip to content

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

fix(tui): 启动时当解析config.json 报错时展示信息

openJiuwen-botc359d07cbaac
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
index 38a7a8cca8..d81a3bc634 100644
--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
@@ -1045,6 +1045,11 @@ export class CliPiAppState {
}
};
+ readonly setLastError = (error: string | null): void => {
+ this.lastError = error;
+ this.emitChange();
+ };
+
readonly setThemeName = (theme: ThemeName): void => {
if (this.themeName !== theme) {
this.themeName = theme;
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/tui-config-store.ts b/jiuwenswarm/channels/tui/frontend/src/core/tui-config-store.ts
index b1c36751c1..3f6873a930 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/tui-config-store.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/tui-config-store.ts
@@ -36,7 +36,11 @@ export function loadTuiConfig(): TuiConfig {
return {};
}
return JSON.parse(raw) as TuiConfig;
- } catch {
+ } catch (error) {
+ // 仅在文件存在且错误为 SyntaxError 时记录(JSON 解析失败)
+ if (error instanceof SyntaxError && _configParseError === null) {
+ _configParseError = error.message;
+ }
return {};
}
}
@@ -47,3 +51,17 @@ export function saveTuiConfig(partial: TuiConfig): void {
const merged = { ...existing, ...partial };
writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2) + "\n", "utf8");
}
+
+/** 如果 config.json 包含无效 JSON,保存 JSON 解析错误信息。 */
+let _configParseError: string | null = null;
+
+/**
+ * 消费并清除 config 文件解析错误信息。
+ * 如果没有检测到解析错误或错误已被消费,则返回 null。
+ * 供 AppScreen 在启动时用于显示一次性通知。
+ */
+export function consumeParseError(): string | null {
+ const msg = _configParseError;
+ _configParseError = null;
+ return msg;
+}
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index d901cb942d..707e8da894 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -63,6 +63,7 @@ import {
setCurrentCwd,
setCurrentProjectDir,
} from "../core/tui-trusted-dirs-store.js";
+import { consumeParseError } from "../core/tui-config-store.js";
import { handleAppScreenKeyInput } from "./keymap.js";
import { buildAppScreenLines } from "./screen-layout.js";
import { buildTranscriptLines } from "./transcript-renderer.js";
@@ -824,6 +825,14 @@ export class AppScreen implements Component, Focusable {
setCurrentCwd(process.cwd());
// Initialize startup prompt for workspace trust
this.initStartupPrompt();
+ // 检查一次 config.json 解析错误,用 setTimeout(0) 延迟到 TUI 初始化完成
+ setTimeout(() => {
+ const parseError = consumeParseError();
+ if (parseError) {
+ this.state.setLastError("Invalid config.json. Please fix and restart.");
+ this.tui.requestRender();
+ }
+ }, 0);
}
private initStartupPrompt(): void {