An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797
Daniel19721196df3f
diff --git a/app/src/assets/scss/business/_agentChat.scss b/app/src/assets/scss/business/_agentChat.scssindex ef84df6235..c3b12885eb 100644--- a/app/src/assets/scss/business/_agentChat.scss+++ b/app/src/assets/scss/business/_agentChat.scss@@ -411,7 +411,6 @@color: var(--b3-theme-on-surface);line-height: 1.5;margin-bottom: 8px;- padding: 8px 10px;background: transparent;border: none;border-radius: 0;diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex 583d07d523..1cac98c2fd 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -53,7 +53,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their- Exploring structure: document.list (see child documents under an hPath) → document.get (read document metadata and content) → block.get_children (list blocks inside a document) → block.get (read a specific block). Use breadcrumb to trace a block's location path.- Creating content: document.create specifies the target notebook and hPath to create a document → block.append/prepend/insert to add blocks into the document. Use dataType "markdown" for text content.- Creating diary/dailynote: dailynote.create with notebook ID to create or open today's daily note → dailynote.append/prepend to add content. Do not use document.create for diary/dailynote requests.-- Modifying content: block.update with a block's ID and new markdown content.+- Modifying content: block.update replaces a single block's content with new markdown. To insert multiple new blocks into a document, use block.append/block.prepend (add to parent) or block.insert (add between siblings). Do NOT use block.update to add new blocks.- Organizing: document.move (full document relocation to a new hPath, needs notebook ID from document.get). document.rename changes a document's title (hPath follows). block.move repositions a single block under a new parent — for content blocks, not entire documents. document.delete removes a document by ID.- Attributes/properties: use attr.get/set to read/write custom attributes on any block. Use database tools for spreadsheets/attribute views.@@ -87,6 +87,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their## Debugging- When the user reports an error, problem, or unexpected behavior, first use the file tool to read the SiYuan log at "temp/siyuan.log" (relative to the workspace) to find error messages and context.+- Use offset=-200 and limit=200 to read the last 200 lines of the log first. If more context is needed, adjust the offset to read earlier lines.- The log file may contain stack traces, error codes, and timestamps that help pinpoint the issue.- After reading the log, summarize the relevant errors before attempting any fixes.diff --git a/kernel/mcp/tools/file.go b/kernel/mcp/tools/file.goindex f100a924f5..291d4cdf8a 100644--- a/kernel/mcp/tools/file.go+++ b/kernel/mcp/tools/file.go@@ -36,6 +36,8 @@ var FileTool = &Tool{"action": {Type: "string", Description: "Operation", Enum: []string{"list", "read", "write", "delete", "rename", "copy"}},"path": {Type: "string", Description: "Relative path within workspace (for list, read, write, delete)"},"data": {Type: "string", Description: "File content (for write)"},+ "offset": {Type: "number", Description: "Line number to start reading from (for read, 1-based). Negative means N lines from the end. Default: 0 (read from beginning)."},+ "limit": {Type: "number", Description: "Maximum lines to read (for read). Default: all lines."},"old": {Type: "string", Description: "Source path (for rename)"},"new": {Type: "string", Description: "Destination path (for rename)"},"src": {Type: "string", Description: "Source path (for copy)"},@@ -107,6 +109,15 @@ func fileList(args map[string]interface{}) (CallToolResult, error) {return CallToolResult{Content: []ContentItem{{Type: "text", Text: sb.String()}}}, nil}+func getFloat64Arg(args map[string]interface{}, key string) float64 {+ if v, ok := args[key]; ok {+ if f, ok := v.(float64); ok {+ return f+ }+ }+ return 0+}+func fileRead(args map[string]interface{}) (CallToolResult, error) {p, _ := args["path"].(string)if p == "" {@@ -120,7 +131,43 @@ func fileRead(args map[string]interface{}) (CallToolResult, error) {if err != nil {return CallToolResult{Content: []ContentItem{{Type: "text", Text: "read file failed: " + err.Error()}}, IsError: true}, nil}- return CallToolResult{Content: []ContentItem{{Type: "text", Text: string(data)}}}, nil++ offset := int(getFloat64Arg(args, "offset"))+ limit := int(getFloat64Arg(args, "limit"))++ if offset == 0 && limit == 0 {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: string(data)}}}, nil+ }++ lines := strings.Split(string(data), "\n")+ total := len(lines)++ if offset < 0 {+ offset = total + offset+ if offset < 0 {+ offset = 0+ }+ } else {+ offset--+ if offset < 0 {+ offset = 0+ }+ }++ end := total+ if limit > 0 {+ end = offset + limit+ if end > total {+ end = total+ }+ }++ if offset >= total {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: fmt.Sprintf("(file has %d lines, offset out of range)", total)}}, IsError: true}, nil+ }++ result := strings.Join(lines[offset:end], "\n")+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: result}}}, nil}func fileWrite(args map[string]interface{}) (CallToolResult, error) {