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: Command Line Interface https://github.com/siyuan-note/siyuan/issues/17674
Daniela53053c3543a
diff --git a/kernel/cli/cmd/block.go b/kernel/cli/cmd/block.goindex 86d8c9e9a4..86511b0716 100644--- a/kernel/cli/cmd/block.go+++ b/kernel/cli/cmd/block.go@@ -153,33 +153,6 @@ var blockKramdownCmd = &cobra.Command{},}-var blockInfoCmd = &cobra.Command{- Use: "info --id <id>",- Short: "Get document info",- RunE: func(cmd *cobra.Command, args []string) error {- id, _ := cmd.Flags().GetString("id")- if id == "" {- return fmt.Errorf("--id is required")- }- info, err := model.GetDocInfo(id)- if err != nil {- return err- }- switch outputFormat {- case "json":- data, _ := json.MarshalIndent(info, "", " ")- fmt.Println(string(data))- default:- fmt.Printf("ID: %s\n", info.ID)- fmt.Printf("RootID: %s\n", info.RootID)- fmt.Printf("Name: %s\n", info.Name)- fmt.Printf("RefCount: %d\n", info.RefCount)- fmt.Printf("SubFileCount: %d\n", info.SubFileCount)- }- return nil- },-}-var blockStatCmd = &cobra.Command{Use: "stat --id <id>",Short: "Get block content statistics",@@ -428,7 +401,6 @@ func init() {blockDomCmd.Flags().String("id", "", "block ID")blockKramdownCmd.Flags().String("id", "", "block ID")blockKramdownCmd.Flags().String("mode", "md", "export mode: md | textmark")- blockInfoCmd.Flags().String("id", "", "document block ID")blockStatCmd.Flags().String("id", "", "block ID")blockInsertCmd.Flags().String("parent", "", "parent block ID")@@ -460,7 +432,6 @@ func init() {blockCmd.AddCommand(blockBreadcrumbCmd)blockCmd.AddCommand(blockDomCmd)blockCmd.AddCommand(blockKramdownCmd)- blockCmd.AddCommand(blockInfoCmd)blockCmd.AddCommand(blockStatCmd)blockCmd.AddCommand(blockInsertCmd)blockCmd.AddCommand(blockAppendCmd)diff --git a/kernel/cli/cmd/document.go b/kernel/cli/cmd/document.goindex 3340f33a0b..012e009076 100644--- a/kernel/cli/cmd/document.go+++ b/kernel/cli/cmd/document.go@@ -228,6 +228,33 @@ var documentDuplicateCmd = &cobra.Command{},}+var documentInfoCmd = &cobra.Command{+ Use: "info --id <id>",+ Short: "Get document info",+ RunE: func(cmd *cobra.Command, args []string) error {+ id, _ := cmd.Flags().GetString("id")+ if id == "" {+ return fmt.Errorf("--id is required")+ }+ info, err := model.GetDocInfo(id)+ if err != nil {+ return err+ }+ switch outputFormat {+ case "json":+ data, _ := json.MarshalIndent(info, "", " ")+ fmt.Println(string(data))+ default:+ fmt.Printf("ID: %s\n", info.ID)+ fmt.Printf("RootID: %s\n", info.RootID)+ fmt.Printf("Name: %s\n", info.Name)+ fmt.Printf("RefCount: %d\n", info.RefCount)+ fmt.Printf("SubFileCount: %d\n", info.SubFileCount)+ }+ return nil+ },+}+func resolvePath(boxID, userPath, hpath string) string {if userPath != "" {return userPath@@ -270,6 +297,7 @@ func init() {documentMoveCmd.Flags().String("hpath", "", "target human-readable path")documentDuplicateCmd.Flags().String("id", "", "document block ID to duplicate")+ documentInfoCmd.Flags().String("id", "", "document block ID")rootCmd.AddCommand(documentCmd)documentCmd.AddCommand(documentListCmd)@@ -279,6 +307,7 @@ func init() {documentCmd.AddCommand(documentRenameCmd)documentCmd.AddCommand(documentMoveCmd)documentCmd.AddCommand(documentDuplicateCmd)+ documentCmd.AddCommand(documentInfoCmd)}diff --git a/kernel/cli/cmd/notebook.go b/kernel/cli/cmd/notebook.goindex 2ada521953..81aab848b2 100644--- a/kernel/cli/cmd/notebook.go+++ b/kernel/cli/cmd/notebook.go@@ -21,8 +21,11 @@ import ("fmt""os""text/tabwriter"+ "time""github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/util""github.com/spf13/cobra")@@ -107,6 +110,49 @@ var notebookRenameCmd = &cobra.Command{},}+var notebookOpenCmd = &cobra.Command{+ Use: "open --id <id>",+ Short: "Open a notebook",+ RunE: func(cmd *cobra.Command, args []string) error {+ id, _ := cmd.Flags().GetString("id")+ if id == "" {+ return fmt.Errorf("--id is required")+ }+ existed, err := model.Mount(id)+ if err != nil {+ return err+ }+ if box := model.Conf.Box(id); nil != box {+ evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast)+ evt.Data = map[string]any{+ "box": box,+ "existed": existed,+ }+ util.PushEvent(evt)+ }+ time.Sleep(1 * time.Second)+ sql.FlushQueue()+ fmt.Println(id)+ return nil+ },+}++var notebookCloseCmd = &cobra.Command{+ Use: "close --id <id>",+ Short: "Close a notebook",+ RunE: func(cmd *cobra.Command, args []string) error {+ id, _ := cmd.Flags().GetString("id")+ if id == "" {+ return fmt.Errorf("--id is required")+ }+ model.Unmount(id)+ time.Sleep(1 * time.Second)+ sql.FlushQueue()+ fmt.Println(id)+ return nil+ },+}+func printNotebookTable(boxes []*model.Box) {w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)fmt.Fprintln(w, "ID\tNAME\tCLOSED\tSORT")@@ -121,10 +167,14 @@ func init() {notebookRemoveCmd.Flags().String("id", "", "notebook ID")notebookRenameCmd.Flags().String("id", "", "notebook ID")notebookRenameCmd.Flags().String("name", "", "new notebook name")+ notebookOpenCmd.Flags().String("id", "", "notebook ID")+ notebookCloseCmd.Flags().String("id", "", "notebook ID")rootCmd.AddCommand(notebookCmd)notebookCmd.AddCommand(notebookListCmd)notebookCmd.AddCommand(notebookCreateCmd)notebookCmd.AddCommand(notebookRemoveCmd)notebookCmd.AddCommand(notebookRenameCmd)+ notebookCmd.AddCommand(notebookOpenCmd)+ notebookCmd.AddCommand(notebookCloseCmd)}