Skip to content

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

:sparkles: Command Line Interface https://github.com/siyuan-note/siyuan/issues/17674

Daniel4443f1bb761e
diff --git a/kernel/cli/cmd/attr.go b/kernel/cli/cmd/attr.go
index 0ddb8e2cc0..8082715925 100644
--- a/kernel/cli/cmd/attr.go
+++ b/kernel/cli/cmd/attr.go
@@ -82,6 +82,7 @@ var attrSetCmd = &cobra.Command{
if err := model.SetBlockAttrs(id, nameValues); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
fmt.Println("ok")
return nil
},
diff --git a/kernel/cli/cmd/block.go b/kernel/cli/cmd/block.go
index 2f096f0260..cc78803b13 100644
--- a/kernel/cli/cmd/block.go
+++ b/kernel/cli/cmd/block.go
@@ -202,6 +202,7 @@ var blockInsertCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(parentID)
fmt.Println("ok")
return nil
},
@@ -227,6 +228,7 @@ var blockAppendCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(parentID)
fmt.Println("ok")
return nil
},
@@ -252,6 +254,7 @@ var blockPrependCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(parentID)
fmt.Println("ok")
return nil
},
@@ -277,6 +280,7 @@ var blockUpdateCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(id)
fmt.Println("ok")
return nil
},
@@ -299,6 +303,7 @@ var blockDeleteCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(id)
fmt.Println(id)
return nil
},
@@ -325,6 +330,7 @@ var blockMoveCmd = &cobra.Command{
}}
model.PerformTransactions(&transactions)
model.FlushTxQueue()
+ model.AppendPushSavedocEntry(id)
fmt.Println("ok")
return nil
},
diff --git a/kernel/cli/cmd/bookmark.go b/kernel/cli/cmd/bookmark.go
index 7098b54792..b3847e482b 100644
--- a/kernel/cli/cmd/bookmark.go
+++ b/kernel/cli/cmd/bookmark.go
@@ -80,6 +80,7 @@ var bookmarkRemoveCmd = &cobra.Command{
if err := model.RemoveBookmark(label); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
return nil
},
}
@@ -99,6 +100,7 @@ var bookmarkRenameCmd = &cobra.Command{
if err := model.RenameBookmark(oldLabel, newLabel); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
return nil
},
}
diff --git a/kernel/cli/cmd/document.go b/kernel/cli/cmd/document.go
index b8bb53443d..97981668ed 100644
--- a/kernel/cli/cmd/document.go
+++ b/kernel/cli/cmd/document.go
@@ -203,6 +203,7 @@ var documentMoveCmd = &cobra.Command{
if err := model.MoveDocs([]string{tree.Path}, toNotebook, resolvePath(toNotebook, toPath, hpath), nil); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
fmt.Println("ok")
return nil
},
@@ -221,6 +222,7 @@ var documentDuplicateCmd = &cobra.Command{
return err
}
model.DuplicateDoc(tree)
+ model.AppendPushReloadFiletreeEntry()
fmt.Println("ok")
return nil
},
diff --git a/kernel/cli/cmd/notebook.go b/kernel/cli/cmd/notebook.go
index c019835c2d..cbfccf7a59 100644
--- a/kernel/cli/cmd/notebook.go
+++ b/kernel/cli/cmd/notebook.go
@@ -63,6 +63,7 @@ var notebookCreateCmd = &cobra.Command{
if err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
fmt.Println(id)
return nil
},
@@ -79,6 +80,7 @@ var notebookRemoveCmd = &cobra.Command{
if err := model.RemoveBox(id); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
fmt.Println(id)
return nil
},
@@ -99,6 +101,7 @@ var notebookRenameCmd = &cobra.Command{
if err := model.RenameBox(id, name); err != nil {
return err
}
+ model.AppendPushReloadFiletreeEntry()
return nil
},
}
diff --git a/kernel/cli/cmd/tag.go b/kernel/cli/cmd/tag.go
index ccd63c55a3..1e2f82aa1a 100644
--- a/kernel/cli/cmd/tag.go
+++ b/kernel/cli/cmd/tag.go
@@ -61,6 +61,7 @@ var tagRemoveCmd = &cobra.Command{
if err := model.RemoveTag(label); err != nil {
return err
}
+ model.AppendPushReloadTagEntry()
return nil
},
}
@@ -80,6 +81,7 @@ var tagRenameCmd = &cobra.Command{
if err := model.RenameTag(oldLabel, newLabel); err != nil {
return err
}
+ model.AppendPushReloadTagEntry()
return nil
},
}
diff --git a/kernel/model/push_queue.go b/kernel/model/push_queue.go
index 083b5658db..8efacb3972 100644
--- a/kernel/model/push_queue.go
+++ b/kernel/model/push_queue.go
@@ -28,6 +28,7 @@ import (
"github.com/gofrs/flock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
+ "github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -70,6 +71,18 @@ func AppendPushReloadDocInfoEntry(box, p string) {
appendPushEntry(pushEntry{Action: "reloadDocInfo", Box: box, Path: p})
}
+func AppendPushSavedocEntry(id string) {
+ appendPushEntry(pushEntry{Action: "savedoc", ID: id})
+}
+
+func AppendPushReloadFiletreeEntry() {
+ appendPushEntry(pushEntry{Action: "reloadFiletree"})
+}
+
+func AppendPushReloadTagEntry() {
+ appendPushEntry(pushEntry{Action: "reloadTag"})
+}
+
func appendPushEntry(entry pushEntry) {
ensurePushQueue()
@@ -140,6 +153,15 @@ func PollPushQueue() {
renderer := render.NewJSONRenderer(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)
size := uint64(len(renderer.Render()))
refreshDocInfo0(tree, size)
+ case "savedoc":
+ bt := treenode.GetBlockTree(e.ID)
+ if bt != nil {
+ util.PushSaveDoc(bt.RootID, "cli", nil)
+ }
+ case "reloadFiletree":
+ util.BroadcastByType("filetree", "reloadFiletree", 0, "", nil)
+ case "reloadTag":
+ util.BroadcastByType("main", "reloadTag", 0, "", nil)
}
}