An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve Agent super-block layout guidance https://github.com/siyuan-note/siyuan/issues/18887
Daniel17187b32e0b5
diff --git a/docs/SY-FORMAT.md b/docs/SY-FORMAT.mdindex 58ce2d7ca4..487c446734 100644--- a/docs/SY-FORMAT.md+++ b/docs/SY-FORMAT.md@@ -302,7 +302,7 @@ The table lists the five built-in types and their defaults. Custom `CalloutType`] }```-> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (horizontal) or `"col"` (vertical). A canonical super block contains the open marker, layout marker, at least one content block, and close marker — at least four children total. It may contain multiple content blocks, can nest, and is the only container that can hold any block (including itself).+> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (vertical) or `"col"` (horizontal). A canonical super block contains the open marker, layout marker, at least one content block, and close marker — at least four children total. It may contain multiple content blocks, can nest, and is the only container that can hold any block (including itself).### 5.9 Embed block (five-part structure `{{ ... }}`)diff --git a/docs/SY-FORMAT.zh-CN.md b/docs/SY-FORMAT.zh-CN.mdindex 429e1e04bc..262cbb7b88 100644--- a/docs/SY-FORMAT.zh-CN.md+++ b/docs/SY-FORMAT.zh-CN.md@@ -302,7 +302,7 @@ NodeList NodeList] }```-> `NodeSuperBlockLayoutMarker.Data` 只能是 `"row"`(横向)或 `"col"`(纵向)。规范超级块包含开始标记、布局标记、至少一个内容块和结束标记,因此至少有四个子节点。它可以包含多个内容块并可嵌套,也是唯一能容纳任意块(包括自身)的容器。+> `NodeSuperBlockLayoutMarker.Data` 只能是 `"row"`(纵向)或 `"col"`(横向)。规范超级块包含开始标记、布局标记、至少一个内容块和结束标记,因此至少有四个子节点。它可以包含多个内容块并可嵌套,也是唯一能容纳任意块(包括自身)的容器。### 5.9 嵌入块(五段结构 `{{ ... }}`)diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex 3afcb86b43..f5c84c7366 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -50,6 +50,18 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their- Container blocks (can hold child blocks): document, blockquote, list, list-item, super-block, callout. Leaf blocks (cannot hold children): heading, paragraph, code-block, math-block, table, HTML-block, thematic-break, video, audio, widget, iframe, attribute-view, block-query-embed.- Heading hierarchy: headings (h1-h6) are leaf blocks. Blocks that appear "under" a heading in the UI are its *following siblings* in the AST, not its children. To place a block below a heading, pass the heading's ID (or the ID of the last block currently below it) as previousID, not as parentID.- Nested lists: a list-item cannot directly contain another list-item. To nest lists, create a list (NodeList) as a child of the outer list-item, then add list-items to that inner list. The parent of a list-item must always be a list (NodeList).+- Super-block layouts: despite the token names, "row" means a vertical layout with child blocks stacked top-to-bottom, while "col" means a horizontal layout with child blocks placed side-by-side. Never infer the visual direction from the English token alone.+- To create a super-block, prefer block.insert/append/prepend with dataType "markdown" and Kramdown. For example, a horizontal super-block containing two paragraphs is:++{{{col++first paragraph++second paragraph++}}}++ Use {{{row for a vertical super-block. Never use data-layout in raw block DOM. If raw DOM is unavoidable, the outer block must use data-type="NodeSuperBlock" and data-sb-layout="row" or data-sb-layout="col", and every child must be complete block DOM with an explicit data-type; otherwise content may become an HTML block.- Notebook: a top-level container holding documents. Use notebook.list to enumerate; pass notebook ID when creating documents.- hPath (human-readable path): the title-based path shown in the document tree, e.g. "/Diary/2024/June". The "path" parameter in document.create/move/list refers to hPath, not the internal ID-based filesystem path. A rename changes hPath but not the ID.- Document vs block move: document.move relocates an entire document (and children) to a new hPath within a notebook — needs id, notebook (from document.get field "Box"), and path. block.move repositions a single content block under a new parent block.diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.goindex 42d8228c3e..f22162233b 100644--- a/kernel/agent/prompt_test.go+++ b/kernel/agent/prompt_test.go@@ -78,6 +78,22 @@ func TestSystemPromptDocumentsTagRendering(t *testing.T) {}}+func TestSystemPromptDocumentsSuperBlockLayout(t *testing.T) {+ for _, instruction := range []string{+ `"row" means a vertical layout`,+ `"col" means a horizontal layout`,+ `{{{col`,+ `Use {{{row for a vertical super-block`,+ `Never use data-layout in raw block DOM`,+ `data-sb-layout="row" or data-sb-layout="col"`,+ `every child must be complete block DOM with an explicit data-type`,+ } {+ if !strings.Contains(systemPrompt, instruction) {+ t.Fatalf("system prompt is missing the super-block instruction %q", instruction)+ }+ }+}+func TestSystemPromptOmitsUnavailableSkillInstructions(t *testing.T) {capabilities := &capabilitySet{registrations: map[string]*capabilityRegistration{}}prompt := buildSystemPrompt("English", capabilities)diff --git a/kernel/mcp/tools/block.go b/kernel/mcp/tools/block.goindex 6f33a28934..99554faa00 100644--- a/kernel/mcp/tools/block.go+++ b/kernel/mcp/tools/block.go@@ -37,7 +37,7 @@ var BlockTool = &Tool{"notebook": {Type: "string", Description: "Notebook ID that owns the target blocks; required for encrypted notebooks"},"id": {Type: "string", Description: "Block ID"},"ids": {Type: "string", Description: "Comma-separated block IDs (for batch_get, batch_kramdown)"},- "data": {Type: "string", Description: "Content (markdown or dom). Markdown block references use ((blockID \"anchor text\")); never [[blockID]]"},+ "data": {Type: "string", Description: "Content in markdown or block DOM. Prefer markdown. A horizontal super-block uses {{{col with blank-line-separated child blocks and }}} on its own line; col is horizontal and row is vertical. Raw super-block DOM uses data-type=\"NodeSuperBlock\" and data-sb-layout, never data-layout, and every child needs an explicit data-type. Markdown block references use ((blockID \"anchor text\")); never [[blockID]]"},"dataType": {Type: "string", Description: "Content type: markdown or dom", Enum: []string{"markdown", "dom"}},"lockType": {Type: "boolean", Description: "Reject update when the parsed block type differs from the existing block type; defaults to false"},"parentID": {Type: "string", Description: "Parent block ID"},diff --git a/kernel/mcp/tools/block_test.go b/kernel/mcp/tools/block_test.goindex 010a1eec99..cb4c5ad904 100644--- a/kernel/mcp/tools/block_test.go+++ b/kernel/mcp/tools/block_test.go@@ -10,9 +10,41 @@ package toolsimport ("encoding/json"+ "strings""testing")+func TestBlockToolDocumentsSuperBlockSyntax(t *testing.T) {+ description := BlockTool.InputSchema.Properties["data"].Description+ for _, instruction := range []string{+ "{{{col",+ "col is horizontal and row is vertical",+ "data-sb-layout",+ "never data-layout",+ "every child needs an explicit data-type",+ } {+ if !strings.Contains(description, instruction) {+ t.Fatalf("block data description is missing the super-block instruction %q", instruction)+ }+ }+}++func TestMarkdownToBlockDOMCreatesHorizontalSuperBlock(t *testing.T) {+ dom, err := markdownToBlockDOM("{{{col\n\nfirst paragraph\n\nsecond paragraph\n\n}}}")+ if err != nil {+ t.Fatal(err)+ }+ if !strings.Contains(dom, `data-type="NodeSuperBlock"`) || !strings.Contains(dom, `data-sb-layout="col"`) {+ t.Fatalf("horizontal super-block was not preserved in block DOM: %s", dom)+ }+ if count := strings.Count(dom, `data-type="NodeParagraph"`); count != 2 {+ t.Fatalf("expected two paragraph blocks, got %d: %s", count, dom)+ }+ if strings.Contains(dom, `data-type="NodeHTMLBlock"`) {+ t.Fatalf("super-block children became HTML blocks: %s", dom)+ }+}+func TestBlockWriteSuccess(t *testing.T) {const id = "20260818000000-abcdefg"result, err := blockWriteSuccess("append", id)