Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Avoid snapshots for read-only agent queries https://github.com/siyuan-note/siyuan/issues/18256

Daniele45b47a6fe9e
diff --git a/kernel/agent/tools_test.go b/kernel/agent/tools_test.go
index 82cef85eb8..ae1195b300 100644
--- a/kernel/agent/tools_test.go
+++ b/kernel/agent/tools_test.go
@@ -160,6 +160,28 @@ func TestImageToolActionEffects(t *testing.T) {
}
}
+func TestQueryToolActionEffects(t *testing.T) {
+ tests := []struct {
+ toolName string
+ action string
+ }{
+ {toolName: "sql", action: "query"},
+ {toolName: "sql", action: ""},
+ {toolName: "search", action: "fulltext"},
+ {toolName: "search", action: "semantic"},
+ {toolName: "search", action: "asset"},
+ {toolName: "search", action: "getasset"},
+ }
+ for _, test := range tests {
+ if needsConfirm(test.toolName, test.action, nil) {
+ t.Errorf("read-only action %s::%s must not require confirmation", test.toolName, test.action)
+ }
+ if needsLocalSnapshot(test.toolName, test.action) {
+ t.Errorf("read-only action %s::%s must not create a local snapshot", test.toolName, test.action)
+ }
+ }
+}
+
func TestConfirmSessionAcceptsResponseOnce(t *testing.T) {
const confirmID = "test-confirm"
ch := make(chan confirmResult, 1)
diff --git a/kernel/mcp/tools/search.go b/kernel/mcp/tools/search.go
index 91ef271329..bed2321e32 100644
--- a/kernel/mcp/tools/search.go
+++ b/kernel/mcp/tools/search.go
@@ -44,6 +44,13 @@ var SearchTool = &Tool{
},
Required: []string{"action"},
},
+ EffectScope: EffectScopeLocal,
+ ActionEffects: map[string]ToolEffects{
+ "fulltext": {LocalRead: true},
+ "semantic": {LocalRead: true},
+ "asset": {LocalRead: true},
+ "getasset": {LocalRead: true},
+ },
Handler: searchHandler,
}
diff --git a/kernel/mcp/tools/sql.go b/kernel/mcp/tools/sql.go
index e74d95d60e..61ca6bbfd9 100644
--- a/kernel/mcp/tools/sql.go
+++ b/kernel/mcp/tools/sql.go
@@ -34,6 +34,11 @@ var SQLTool = &Tool{
},
Required: []string{"action", "stmt"},
},
+ EffectScope: EffectScopeLocal,
+ ActionEffects: map[string]ToolEffects{
+ "": {LocalRead: true},
+ "query": {LocalRead: true},
+ },
Handler: sqlHandler,
}