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: Move rg warning to file search

chensheng1234508b14c4aefed
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
index fab07575e1..c9158e2b0a 100644
--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
@@ -62,7 +62,7 @@ import {
getCurrentCwd,
} from "./core/tui-trusted-dirs-store.js";
import { loadTuiConfig, type StatusLineSetting } from "./core/tui-config-store.js";
-import { execFile } from "node:child_process";
+import { execFile, spawnSync } from "node:child_process";
import { writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, sep } from "node:path";
@@ -140,6 +140,26 @@ function formatElapsed(ms: number): string {
return minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
}
+const LOCAL_FILE_SEARCH_TOOL_NAMES = new Set([
+ "grep",
+ "rg",
+ "ripgrep",
+ "search",
+]);
+
+function isLocalFileSearchTool(name: string): boolean {
+ return LOCAL_FILE_SEARCH_TOOL_NAMES.has(name.trim().toLowerCase());
+}
+
+function detectRipgrep(): boolean {
+ try {
+ const result = spawnSync("rg", ["--version"], { stdio: "ignore" });
+ return result.status === 0;
+ } catch {
+ return false;
+ }
+}
+
export class CliPiAppState {
private listeners = new Set<() => void>();
private entries: HistoryItem[] = [];
@@ -214,6 +234,8 @@ export class CliPiAppState {
private streamingStateBeforeQuestion: StreamingState | null = null;
/** 当前回合的起始时间戳,用于在回合结束时计算执行耗时。 */
private turnStartedAt: number | null = null;
+ private ripgrepAvailable: boolean | null = null;
+ private ripgrepSearchTipShown = false;
/** Harness extension ready info (for file tree display) */
private harnessExtensionReady: HarnessExtensionReady | null = null;
/** Harness activate interaction state (for user confirmation) */
@@ -1517,6 +1539,35 @@ export class CliPiAppState {
return changed;
}
+ private hasRipgrep(): boolean {
+ if (this.ripgrepAvailable === null) {
+ this.ripgrepAvailable = detectRipgrep();
+ }
+ return this.ripgrepAvailable;
+ }
+
+ private maybeAddRipgrepSearchTip(tool: ToolCallDisplay, sessionId: string): void {
+ if (
+ this.ripgrepSearchTipShown ||
+ !isLocalFileSearchTool(tool.name) ||
+ this.hasRipgrep()
+ ) {
+ return;
+ }
+ this.ripgrepSearchTipShown = true;
+ this.entries = [
+ ...this.entries,
+ addInfo(
+ sessionId,
+ "Tips: 未检测到 ripgrep (rg),本次文件搜索可能较慢。" +
+ "建议安装 rg 以优化文件搜索效果。",
+ "i",
+ { view: "dim" },
+ ),
+ ];
+ this.lastError = null;
+ }
+
private addToolCallPayload(
payload: Record<string, unknown>,
sessionId: string,
@@ -1532,6 +1583,7 @@ export class CliPiAppState {
return;
}
+ this.maybeAddRipgrepSearchTip(tool, sessionId);
const started = startedAt ?? new Date().toISOString();
const orphan = this.orphanToolResults.get(tool.callId);
const nextTool = orphan
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts b/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts
index 1ccfa24074..199abf0196 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts
@@ -1,5 +1,4 @@
import { visibleWidth } from "@mariozechner/pi-tui";
-import { spawnSync } from "node:child_process";
import type { ConnectionStatus } from "../core/ws-client.js";
import { padToWidth } from "./rendering/text.js";
import { chalk } from "./theme.js";
@@ -61,15 +60,6 @@ function connectionHint(status: ConnectionStatus): string | null {
}
}
-function hasRipgrep(): boolean {
- try {
- const result = spawnSync("rg", ["--version"], { stdio: "ignore" });
- return result.status === 0;
- } catch {
- return false;
- }
-}
-
export function buildWelcomeLines(
width: number,
connectionStatus: ConnectionStatus,
@@ -79,7 +69,6 @@ export function buildWelcomeLines(
): string[] {
const artWidth = Math.max(...ART_TITLE_RAW.map((line) => visibleWidth(line)));
const hint = connectionHint(connectionStatus);
- const rgTip = hasRipgrep() ? null : "Tips: 未检测到 ripgrep (rg),建议安装以优化文件搜索效果。";
const version = modelInfo.version || "0.1.0";
const provider = modelInfo.provider || "";
const model = modelInfo.model || "";
@@ -117,7 +106,6 @@ export function buildWelcomeLines(
centerLine(cmdBoxLine(commands), width),
centerLine(cmdBottom, width),
...(hint ? [centerLine(chalk.hex("#FFFFFF")(hint), width)] : []),
- ...(rgTip ? [centerLine(chalk.hex("#FFD700")(rgTip), width)] : []),
...(memoryWarnings.length > 0
? memoryWarnings.map((w) => centerLine(chalk.hex("#FFD700")(`Warning: ${w.message}`), width))
: []),
@@ -140,7 +128,6 @@ export function buildWelcomeLines(
padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")("/exit - 退出 ") + chalk.hex("#FFFFFF")("│"), width),
padToWidth(chalk.hex("#FFFFFF")("└────────────────────────────────────────────────────────────┘"), width),
...(hint ? [padToWidth(chalk.hex("#FFFFFF")(hint), width)] : []),
- ...(rgTip ? [padToWidth(chalk.hex("#FFD700")(rgTip), width)] : []),
...(memoryWarnings.length > 0
? memoryWarnings.map((w) => padToWidth(chalk.hex("#FFD700")(`Warning: ${w.message}`), width))
: []),