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): /workspace add: update path validation

ray_led52a204cd71d
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts b/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts
index fab29e762e..17a7ead0c6 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts
@@ -110,7 +110,7 @@ export function createWorkspaceCommand(): SlashCommand {
} else if (result === "not_found") {
ctx.addItem(addError(ctx.sessionId, `Path does not exist: ${resolvedPath}`));
} else {
- ctx.addItem(addError(ctx.sessionId, `Invalid path: ${resolvedPath}`));
+ ctx.addItem(addError(ctx.sessionId, `Path is not a directory: ${resolvedPath}`));
}
},
},
@@ -134,7 +134,7 @@ export function createWorkspaceCommand(): SlashCommand {
return;
}
if (result === "invalid") {
- ctx.addItem(addError(ctx.sessionId, `Invalid path: ${directoryPath}`));
+ ctx.addItem(addError(ctx.sessionId, `Path is not a directory: ${directoryPath}`));
return;
}
diff --git a/jiuwenclaw/cli/src/core/tui-trusted-dirs-store.ts b/jiuwenclaw/cli/src/core/tui-trusted-dirs-store.ts
index 5863204a46..4835900935 100644
--- a/jiuwenclaw/cli/src/core/tui-trusted-dirs-store.ts
+++ b/jiuwenclaw/cli/src/core/tui-trusted-dirs-store.ts
@@ -1,4 +1,4 @@
-import { existsSync } from "node:fs";
+import { existsSync, statSync } from "node:fs";
import { resolve } from "node:path";
/**
@@ -31,8 +31,8 @@ export function getTrustedDirs(): string[] {
/**
* Add a trusted directory.
- * @param path - Directory path to add
- * @returns "added" if added, "exists" if already trusted, "not_found" if path doesn't exist, "invalid" if invalid path
+ * @param path - Directory path to add (must be a folder, not a file)
+ * @returns "added" if added, "exists" if already trusted, "not_found" if path doesn't exist, "invalid" if invalid path or not a directory
*/
export function addTrustedDir(path: string): "added" | "exists" | "not_found" | "invalid" {
const normalized = normalizePath(path);
@@ -42,6 +42,14 @@ export function addTrustedDir(path: string): "added" | "exists" | "not_found" |
if (!existsSync(normalized)) {
return "not_found";
}
+ try {
+ const stats = statSync(normalized);
+ if (!stats.isDirectory()) {
+ return "invalid";
+ }
+ } catch {
+ return "invalid";
+ }
if (_trustedDirs.includes(normalized)) {
return "exists";
}
@@ -51,8 +59,8 @@ export function addTrustedDir(path: string): "added" | "exists" | "not_found" |
/**
* Reset trusted dirs and set a single path.
- * @param path - Directory path to set as the only trusted dir
- * @returns "set" if set successfully, "not_found" if path doesn't exist, "invalid" if invalid path
+ * @param path - Directory path to set as the only trusted dir (must be a folder, not a file)
+ * @returns "set" if set successfully, "not_found" if path doesn't exist, "invalid" if invalid path or not a directory
*/
export function setTrustedDir(path: string): "set" | "not_found" | "invalid" {
const normalized = normalizePath(path);
@@ -62,6 +70,14 @@ export function setTrustedDir(path: string): "set" | "not_found" | "invalid" {
if (!existsSync(normalized)) {
return "not_found";
}
+ try {
+ const stats = statSync(normalized);
+ if (!stats.isDirectory()) {
+ return "invalid";
+ }
+ } catch {
+ return "invalid";
+ }
_trustedDirs = [normalized];
return "set";
}