Skip to content

Commit 4a0c41c

Browse files
authored
Merge pull request Stack-Cairn#103 from SaladDay/fix/history-share-tool-redaction-minimal
fix(history-share): cover all catalog tools in redaction
2 parents 6e735b8 + f4d78ad commit 4a0c41c

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

crates/agent-gateway/web/src/pages/chat/assistant-bubble/assistantBubbleUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,12 @@ export function isBuiltinShareToolName(name: string) {
345345
"McpManager",
346346
"MemoryManager",
347347
"Read",
348+
"ReadTerminal",
349+
"SendMessage",
348350
"SkillsManager",
349351
"SSHManager",
350352
"SshManager",
353+
"TodoWrite",
351354
"TunnelManager",
352355
"Write",
353356
].includes(trimmed);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import { fileURLToPath } from "node:url";
4+
5+
import { createWebModuleLoader } from "../../test/helpers/load-web-module.mjs";
6+
7+
const rootDir = fileURLToPath(new URL("../", import.meta.url));
8+
const loader = createWebModuleLoader({ rootDir });
9+
const { BUILTIN_TOOL_CATALOG } = loader.loadModule("src/lib/tools/builtinToolCatalog.ts");
10+
const { isBuiltinShareToolName } = loader.loadModule(
11+
"src/pages/chat/assistant-bubble/assistantBubbleUtils.ts",
12+
);
13+
14+
test("shared history recognizes every catalog tool as builtin", () => {
15+
for (const entry of BUILTIN_TOOL_CATALOG) {
16+
assert.equal(isBuiltinShareToolName(entry.toolName), true, entry.toolName);
17+
}
18+
assert.equal(isBuiltinShareToolName("mcp_docs_search"), true);
19+
assert.equal(isBuiltinShareToolName("CustomTool"), false);
20+
});

crates/agent-gui/src-tauri/src/services/gateway_bridge.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,13 @@ fn is_builtin_share_tool_name(name: &str) -> bool {
937937
| "McpManager"
938938
| "MemoryManager"
939939
| "Read"
940+
| "ReadTerminal"
941+
| "SendMessage"
940942
| "SkillsManager"
941943
| "SSHManager"
942944
| "SshManager"
945+
| "TodoWrite"
946+
| "TunnelManager"
943947
| "Write"
944948
)
945949
}
@@ -1598,8 +1602,9 @@ mod tests {
15981602

15991603
use super::{
16001604
build_history_prefix_segments, flatten_history_messages_json,
1601-
flatten_history_messages_json_window, history_message_content_hash, parse_runs_limit,
1602-
redact_builtin_tool_content_json, sanitize_provider_summaries,
1605+
flatten_history_messages_json_window, history_message_content_hash,
1606+
is_builtin_share_tool_name, parse_runs_limit, redact_builtin_tool_content_json,
1607+
sanitize_provider_summaries,
16031608
};
16041609
use crate::commands::chat_history::ChatHistorySegmentRecord;
16051610

@@ -1903,4 +1908,23 @@ mod tests {
19031908
assert_eq!(items[3]["content"][0]["text"], "工具调用内容已脱敏");
19041909
assert_eq!(items[3]["details"]["kind"], "redacted_tool_content");
19051910
}
1911+
1912+
#[test]
1913+
fn shared_chat_history_builtin_policy_covers_the_tool_catalog() {
1914+
let catalog = include_str!("../../../src/lib/tools/builtinToolCatalog.ts");
1915+
let tool_names = catalog.lines().filter_map(|line| {
1916+
line.trim()
1917+
.strip_prefix("toolName: \"")
1918+
.and_then(|value| value.strip_suffix("\","))
1919+
});
1920+
let mut count = 0;
1921+
for tool_name in tool_names {
1922+
count += 1;
1923+
assert!(
1924+
is_builtin_share_tool_name(tool_name),
1925+
"{tool_name} is missing from share redaction"
1926+
);
1927+
}
1928+
assert!(count > 0, "catalog parser found no tools");
1929+
}
19061930
}

0 commit comments

Comments
 (0)