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
feat: 添加/workspace add/set增加安全检查白名单
Haowei_Du4ac9e817c508
diff --git a/jiuwenclaw/agentserver/security/permissions_persist.py b/jiuwenclaw/agentserver/security/permissions_persist.pyindex d49ad9209c..3d9097dc36 100644--- a/jiuwenclaw/agentserver/security/permissions_persist.py+++ b/jiuwenclaw/agentserver/security/permissions_persist.py@@ -172,7 +172,39 @@ def persist_cli_trusted_directory(raw_path: str) -> dict[str, Any]:写入:- `permissions.external_directory`:目录 allow- - `permissions.approval_overrides`:追加 path/command 两条 allow override(可选)+ """+ if not isinstance(raw_path, str) or not raw_path.strip():+ return {"ok": False, "error": "path is empty"}++ try:+ resolved = Path(raw_path.strip()).expanduser().resolve(strict=False)+ except (OSError, RuntimeError) as e:+ return {"ok": False, "error": f"invalid path: {e}"}++ dir_norm = resolved.as_posix().rstrip("/")+ if not dir_norm:+ return {"ok": False, "error": "path resolves to empty"}++ from ruamel.yaml.scalarstring import DoubleQuotedScalarString++ data, yaml_path = _load_config_yaml_round_trip()+ permissions = _ensure_permissions_dict(data)+ ext_cfg = _ensure_external_directory_dict(permissions)+ ext_cfg[DoubleQuotedScalarString(dir_norm)] = DoubleQuotedScalarString("allow")++ _dump_config_yaml_round_trip(yaml_path, data)+ return {+ "ok": True,+ "normalized": dir_norm,+ }+++def persist_cli_trusted_directory_with_overrides(raw_path: str) -> dict[str, Any]:+ """CLI `command.add_dir`:全局信任目录子树(包含覆盖规则)。++ 写入:+ - `permissions.external_directory`:目录 allow+ - `permissions.approval_overrides`:追加 path/command 两条 allow override"""if not isinstance(raw_path, str) or not raw_path.strip():return {"ok": False, "error": "path is empty"}@@ -249,6 +281,7 @@ def persist_cli_trusted_directory(raw_path: str) -> dict[str, Any]:__all__ = ["build_command_allow_pattern","persist_cli_trusted_directory",+ "persist_cli_trusted_directory_with_overrides","persist_external_directory_allow","persist_permission_allow_rule",]diff --git a/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts b/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.tsindex 17a7ead0c6..946c956e31 100644--- a/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts+++ b/jiuwenclaw/cli/src/core/commands/builtins/workspace-dir.ts@@ -98,6 +98,16 @@ export function createWorkspaceCommand(): SlashCommand {}const result = ctx.addTrustedDir(resolvedPath);if (result === "added") {+ // Sync to server-side permissions+ try {+ ctx.sendEventOnly("command.add_dir", {+ path: resolvedPath,+ remember: true+ });+ } catch (error) {+ // Ignore sync errors, still add locally+ console.warn("Failed to sync trusted directory to server:", error);+ }ctx.addItem(addInfo(ctx.sessionId, `Trusted directory added: ${resolvedPath}`, "c", {view: "kv",@@ -156,6 +166,16 @@ export function createWorkspaceCommand(): SlashCommand {// Execute the set operationctx.setTrustedDir(directoryPath);+ // Sync to server-side permissions+ try {+ ctx.sendEventOnly("command.add_dir", {+ path: directoryPath,+ remember: true+ });+ } catch (error) {+ // Ignore sync errors, still set locally+ console.warn("Failed to sync trusted directory to server:", error);+ }ctx.addItem(addInfo(ctx.sessionId, `Trusted directory set: ${directoryPath}`, "c", {view: "kv",diff --git a/jiuwenclaw/cli/src/ui/app-screen.ts b/jiuwenclaw/cli/src/ui/app-screen.tsindex 7389262a34..b2d9a836af 100644--- a/jiuwenclaw/cli/src/ui/app-screen.ts+++ b/jiuwenclaw/cli/src/ui/app-screen.ts@@ -103,7 +103,7 @@ function resolveFdBinary(): string | null {}function isPermissionRequest(source: string | undefined, questionText: string): boolean {- return source === "permission" || PERMISSION_TOOL_RE.test(questionText);+ return source === "permission_interrupt" || PERMISSION_TOOL_RE.test(questionText);}function parsePermissionSummary(questionText: string): PermissionSummary {@@ -1683,12 +1683,12 @@ export class AppScreen implements Component, Focusable {const items: SelectItem[] = question.options.map((option) => ({value: option.label,label:- pendingQuestion.source === "permission"+ pendingQuestion.source === "permission_interrupt"? normalizePermissionOptionLabel(option.label): option.label,description: option.description,}));- const maxVisible = pendingQuestion.source === "permission" ? 4 : 6;+ const maxVisible = pendingQuestion.source === "permission_interrupt" ? 4 : 6;const list = new SelectList(items,Math.min(Math.max(items.length, 1), maxVisible),