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: https://github.com/siyuan-note/siyuan/issues/19046
Vanessad372da300a5a
diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.tsindex 05849930de..54961822d2 100644--- a/app/src/boot/globalEvent/command/global.ts+++ b/app/src/boot/globalEvent/command/global.ts@@ -47,7 +47,15 @@ import {adjustEditorFontSize} from "../../../util/editorFontSize";import {toggleDockPanel} from "../../../layout/dock/panel";/// #endif-export const globalCommand = (command: string, app: App) => {+const getSelectionText = (range?: Range) => {+ if (range) {+ return range.toString();+ }+ const selection = document.getSelection();+ return selection?.rangeCount ? selection.getRangeAt(0).toString() : "";+};++export const globalCommand = (command: string, app: App, range?: Range) => {/// #if MOBILEswitch (command) {case "fileTree":@@ -101,11 +109,11 @@ export const globalCommand = (command: string, app: App) => {openSearch({app,hotkey: Constants.DIALOG_GLOBALSEARCH,- key: (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange()).toString()+ key: getSelectionText(range)});return true;case "stickSearch":- openGlobalSearch(app, (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange()).toString(), true);+ openGlobalSearch(app, getSelectionText(range), true);return true;case "goBack":goBack(app);diff --git a/app/src/boot/globalEvent/command/protyle.ts b/app/src/boot/globalEvent/command/protyle.tsindex adbdc36ee7..099a0788f8 100644--- a/app/src/boot/globalEvent/command/protyle.ts+++ b/app/src/boot/globalEvent/command/protyle.ts@@ -11,7 +11,7 @@ import {fetchPost} from "../../../util/fetch";export const onlyProtyleCommand = (options: {command: string,- previousRange: Range,+ previousRange?: Range,protyle: IProtyle,}) => {if (options.command === "switchReadonly") {@@ -32,6 +32,9 @@ export const onlyProtyleCommand = (options: {});return true;}+ if (!options.previousRange) {+ return false;+ }const nodeElement = hasClosestBlock(options.previousRange.startContainer);if (!nodeElement) {return false;diff --git a/app/src/boot/globalEvent/commonHotkey.ts b/app/src/boot/globalEvent/commonHotkey.tsindex 6a93b8c12e..8c34af16c1 100644--- a/app/src/boot/globalEvent/commonHotkey.ts+++ b/app/src/boot/globalEvent/commonHotkey.ts@@ -1,7 +1,7 @@import {Constants} from "../../constants";import {fetchPost} from "../../util/fetch";/// #if !BROWSER-import {sendGlobalShortcut} from "./keydown";+import {sendGlobalShortcut} from "./globalShortcut";import {ipcRenderer} from "electron";/// #endifimport type {App} from "../../index";diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex a8bbe1ad54..ab5ef14a95 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -44,7 +44,6 @@ import {getNextFileLi, getPreviousFileLi} from "../../protyle/wysiwyg/getBlock";import {Backlink} from "../../layout/dock/Backlink";/// #if !BROWSERimport {setZoom} from "../../layout/topBar";-import {ipcRenderer} from "electron";/// #endifimport {openHistory} from "../../history/history";import {openCard, openCardByData} from "../../card/openCard";@@ -54,7 +53,6 @@ import {reloadProtyle} from "../../protyle/util/reload";import {openRecentDocs} from "../../business/openRecentDocs";import type {App} from "../../index";import {toggleDockPanel} from "../../layout/dock/panel";-import {clearDisallowedTextInputHotkey} from "../../util/hotKeyPolicy";import {openBacklink, openGraph, openOutline, toggleDockBar} from "../../layout/dock/util";import {workspaceMenu} from "../../menus/workspace";import {Search} from "../../search";@@ -66,7 +64,8 @@ import {searchKeydown} from "./searchKeydown";import {historyKeydown} from "../../history/keydown";import {zoomOut} from "../../menus/protyle";import {getPlainText} from "../../protyle/util/paste";-import {commandPanel, execByCommand} from "./command/panel";+import {commandPanel} from "./command/panel";+import {execByCommand} from "../../command/executor";import {filterHotkey} from "./commonHotkey";import {editorConfigApi} from "../../config/tabs/editorRuntime";import {copyPNGByLink} from "../../menus/util";@@ -1886,49 +1885,3 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {return true;}};--export const sendGlobalShortcut = (app: App) => {- /// #if !BROWSER- if (isWindow()) {- return;- }- const hotkeys = [clearDisallowedTextInputHotkey(window.siyuan.config.keymap.general.toggleWin.custom)];- app.plugins.forEach(plugin => {- plugin.commands.forEach(command => {- if (command.globalCallback && command.customHotkey) {- const hotkey = clearDisallowedTextInputHotkey(command.customHotkey);- if (hotkey) {- hotkeys.push(hotkey);- }- }- });- });- ipcRenderer.send(Constants.SIYUAN_HOTKEY, {- languages: window.siyuan.languages["_trayMenu"],- hotkeys- });- /// #endif-};---export const sendUnregisterGlobalShortcut = (app: App) => {- /// #if !BROWSER- if (isWindow()) {- return;- }- ipcRenderer.send(Constants.SIYUAN_CMD, {- cmd: "unregisterGlobalShortcut",- accelerator: window.siyuan.config.keymap.general.toggleWin.custom- });- app.plugins.forEach(plugin => {- plugin.commands.forEach(command => {- if (command.globalCallback) {- ipcRenderer.send(Constants.SIYUAN_CMD, {- cmd: "unregisterGlobalShortcut",- accelerator: command.customHotkey- });- }- });- });- /// #endif-};diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.tsindex ccaaf5ea57..9b30c6d7cf 100644--- a/app/src/boot/onGetConfig.ts+++ b/app/src/boot/onGetConfig.ts@@ -28,7 +28,7 @@ import {mountHelp} from "../util/mount";import {openChangelog} from "./openChangelog";import type {App} from "../index";import {initWindowEvent} from "./globalEvent/event";-import {sendGlobalShortcut} from "./globalEvent/keydown";+import {sendGlobalShortcut} from "./globalEvent/globalShortcut";import {closeWindow} from "../window/closeWin";import {correctHotkey, syncAppMenuShortcuts} from "./globalEvent/commonHotkey";import {recordBeforeResizeTop} from "../protyle/util/resize";diff --git a/app/src/config/tabs/keymapUi.ts b/app/src/config/tabs/keymapUi.tsindex 7189fa5fcc..980defe1c4 100644--- a/app/src/config/tabs/keymapUi.ts+++ b/app/src/config/tabs/keymapUi.ts@@ -9,7 +9,7 @@ import {fetchPost} from "../../util/fetch";import {exportLayout} from "../../layout/util";import {updateDockHotkeys} from "../../layout/dock/util";import {confirmDialog} from "../../dialog/confirmDialog";-import {sendGlobalShortcut, sendUnregisterGlobalShortcut} from "../../boot/globalEvent/keydown";+import {sendGlobalShortcut, sendUnregisterGlobalShortcut} from "../../boot/globalEvent/globalShortcut";import {syncAppMenuShortcuts} from "../../boot/globalEvent/commonHotkey";import {normalizeSearchText} from "../search/normalize";import {genButtonRowHtml, genConfigGroup} from "../render/render";diff --git a/app/src/index.ts b/app/src/index.tsindex 94ffd1d4cd..9c4ed10ea2 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -57,6 +57,7 @@ import {setTitle} from "./util/processTitle";import {ensureUILayout} from "./util/ensureUILayout";import {applyEntryVisibility} from "./config/entryVisibility/runtime";import {removeBlockPanelEditors} from "./block/panelRemoval";+import {initializeEnglishCommandTranslations} from "./command/english";export class App {public plugins: import("./plugin").Plugin[] = [];@@ -304,6 +305,11 @@ export class App {getLocalStorage(() => {fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {window.siyuan.languages = lauguages;+ void initializeEnglishCommandTranslations(+ window.siyuan.config.appearance.lang,+ lauguages as Record<string, string>,+ Constants.SIYUAN_VERSION,+ );window.siyuan.menus = new Menus(this);bootSync();fetchPost("/api/setting/getCloudUser", {}, async userResponse => {diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.tsindex 2039da2adb..4aebeb13a5 100644--- a/app/src/mobile/index.ts+++ b/app/src/mobile/index.ts@@ -60,6 +60,7 @@ import {openByMobile} from "../editor/openLink";import {initHarmonyTextSelectionMenu} from "../util/harmonyTextSelectionMenu";import {updateMobileTopBarLayout} from "./util/mobileTopBar";import {showMobileBars} from "./util/mobileBars";+import {initializeEnglishCommandTranslations} from "../command/english";class App {public plugins: import("../plugin").Plugin[] = [];@@ -185,6 +186,11 @@ class App {getLocalStorage(() => {fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {window.siyuan.languages = lauguages;+ void initializeEnglishCommandTranslations(+ window.siyuan.config.appearance.lang,+ lauguages as Record<string, string>,+ Constants.SIYUAN_VERSION,+ );window.siyuan.menus = new Menus(this);document.title = window.siyuan.languages.siyuanNote;bootSync();diff --git a/app/src/mobile/util/keydown.ts b/app/src/mobile/util/keydown.tsindex 376c6b3333..df46c81660 100644--- a/app/src/mobile/util/keydown.ts+++ b/app/src/mobile/util/keydown.ts@@ -1,5 +1,5 @@import type {App} from "../../index";-import {execByCommand} from "../../boot/globalEvent/command/panel";+import {execByCommand} from "../../command/executor";import {matchHotKey} from "../../protyle/util/hotKey";import {getCurrentEditor} from "../editor";import {filterHotkey} from "../../boot/globalEvent/commonHotkey";diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.tsindex bc9a03ea4c..a757f44a33 100644--- a/app/src/plugin/index.ts+++ b/app/src/plugin/index.ts@@ -29,6 +29,7 @@ import {removeBreadcrumbButton as removePluginBreadcrumbButton,} from "./breadcrumbButton";import type {TCustomBlockRender} from "./customBlockRender";+import {registerPluginCommand} from "./commandAdapter";const disposedPlugins = new WeakSet<Plugin>();@@ -175,6 +176,7 @@ export class Plugin {console.error(`${this.name} - commands data is error and has been removed.`);} else {this.commands.push(command);+ registerPluginCommand(this.app, this, command);/// #if !BROWSERif (!isWindow() && command.globalCallback && command.customHotkey &&!isDisallowedTextInputHotkey(command.customHotkey)) {diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.tsindex 7c593761b0..14468766b9 100644--- a/app/src/plugin/uninstall.ts+++ b/app/src/plugin/uninstall.ts@@ -17,6 +17,8 @@ import {removeBreadcrumbButtons} from "./breadcrumbButton";import {refreshDockCatalog} from "../config/entryVisibility/catalog";import {isWindow} from "../util/functions";import {destroyEventBus} from "./EventBusCore";+import {unregisterPluginCommands} from "./commandAdapter";+import {sendGlobalShortcut} from "../boot/globalEvent/globalShortcut";const runCleanup = (plugin: Plugin, step: string, callback: () => unknown) => {try {@@ -32,6 +34,7 @@ const runCleanup = (plugin: Plugin, step: string, callback: () => unknown) => {};export const beginPluginTeardown = (plugin: Plugin) => {+ runCleanup(plugin, "commands", () => unregisterPluginCommands(plugin));runCleanup(plugin, "asset upload", () => cancelAssetUploadsByPlugin(plugin));};@@ -135,6 +138,7 @@ export const destroyPlugin = (app: App, plugin: Plugin, isUninstall: boolean) =>});});runCleanup(plugin, "style", () => document.getElementById("pluginsStyle" + plugin.name)?.remove());+ runCleanup(plugin, "commands", () => unregisterPluginCommands(plugin));/// #if !BROWSERif (!isWindow()) {runCleanup(plugin, "global shortcut", () => {@@ -149,6 +153,9 @@ export const destroyPlugin = (app: App, plugin: Plugin, isUninstall: boolean) =>}});});+ if (window.siyuan.languages?.["_trayMenu"]) {+ runCleanup(plugin, "global shortcut sync", () => sendGlobalShortcut(app));+ }}/// #endif};diff --git a/app/src/window/index.ts b/app/src/window/index.tsindex e44964b12d..df802b8891 100644--- a/app/src/window/index.ts+++ b/app/src/window/index.ts@@ -37,6 +37,7 @@ import {removeBlockPanelEditors} from "../block/panelRemoval";import {updateServerAddresses} from "../config/tabs/accessRuntime";import {applyCloudUserState} from "../config/tabs/accountUi";import {emitToPlugins} from "../plugin/EventBusCore";+import {initializeEnglishCommandTranslations} from "../command/english";class App {public plugins: import("../plugin").Plugin[] = [];@@ -218,6 +219,11 @@ class App {getLocalStorage(() => {fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {window.siyuan.languages = lauguages;+ void initializeEnglishCommandTranslations(+ window.siyuan.config.appearance.lang,+ lauguages as Record<string, string>,+ Constants.SIYUAN_VERSION,+ );window.siyuan.menus = new Menus(this);fetchPost("/api/setting/getCloudUser", {}, async userResponse => {window.siyuan.user = userResponse.data;diff --git a/kernel/model/file.go b/kernel/model/file.goindex 7d3e73ab63..26cf2651cf 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -1576,7 +1576,7 @@ func GetHPathByPath(boxID, p string) (hPath string, err error) {return}- bt := treenode.GetBlockTreeByBoxPath(boxID, p)+ bt := treenode.GetBlockTreeRootByPath(boxID, p)if nil == bt {err = ErrBlockNotFoundreturn@@ -1593,7 +1593,7 @@ func GetHPathsByPaths(paths []string) (hPaths []string, err error) {continue}- bt := treenode.GetBlockTreeByBoxPath(box.ID, p)+ bt := treenode.GetBlockTreeRootByPath(box.ID, p)if nil == bt {logging.LogWarnf("block tree not found by path [%s]", p)continuediff --git a/kernel/model/file_test.go b/kernel/model/file_test.goindex 9f75e77dec..6af1974abf 100644--- a/kernel/model/file_test.go+++ b/kernel/model/file_test.go@@ -637,6 +637,35 @@ func TestPerformCreateDocTransactionSyncReturnsWriteError(t *testing.T) {}}+func TestGetHPathsByPathsUsesDocumentRoot(t *testing.T) {+ fixture := setupFileOperationTest(t)+ tree, err := LoadTreeByBlockID(fixture.sourceID)+ if nil != err {+ t.Fatalf("load source document failed: %v", err)+ }++ tree.Root.FirstChild.Unlink()+ tree.HPath = "/Renamed"+ tree.Root.SetIALAttr("title", "Renamed")+ tree.Root.AppendChild(treenode.NewParagraph("20260831000000-newpath"))+ treenode.UpsertBlockTree(tree)++ staleBlock := treenode.GetBlockTree(fixture.childID)+ if nil == staleBlock || "/Source" != staleBlock.HPath {+ t.Fatalf("expected stale content block path to remain in the fixture: %+v", staleBlock)+ }++ hPath, err := GetHPathByPath(fixture.box.ID, fixture.sourcePath)+ if nil != err || "/Renamed" != hPath {+ t.Fatalf("unexpected document path: got %q, err=%v", hPath, err)+ }++ hPaths, err := GetHPathsByPaths([]string{fixture.sourcePath})+ if nil != err || !reflect.DeepEqual([]string{"File operation test/Renamed"}, hPaths) {+ t.Fatalf("unexpected document paths: got %v, err=%v", hPaths, err)+ }+}+func TestGetBoxesByPathsStrictRejectsInvalidPaths(t *testing.T) {fixture := setupFileOperationTest(t)tests := []struct {