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

Daniel1fa1b0e5b942
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
index b7bf907b7d..4f10823a1e 100644
--- a/.github/workflows/cd.yml
+++ b/.github/workflows/cd.yml
@@ -103,7 +103,7 @@ jobs:
- os: windows-latest
name: windows build win.exe
kernel_path: "../app/kernel/SiYuan-Kernel.exe"
- build_args_prefix: "-s -w -H=windowsgui -X"
+ build_args_prefix: "-s -w -X"
build_args_suffix: "Mode=prod"
electron_args: "dist"
goos: "windows"
diff --git a/app/nsis/installer.nsh b/app/nsis/installer.nsh
index 43bc850a3d..b4fdb731f9 100644
--- a/app/nsis/installer.nsh
+++ b/app/nsis/installer.nsh
@@ -55,6 +55,7 @@ Caption "${PRODUCT_NAME} ${VERSION}"
${EndIf}
RMDir /r "$PROFILE\AppData\Local\siyuan-updater"
+ nsExec::ExecToLog 'powershell -NoProfile -Command "$p=[Environment]::GetEnvironmentVariable(\"Path\",\"User\");$p=($p.Split(\";\") | ?{$_ -ne \"$INSTDIR\resources\kernel\"}) -join \";\";[Environment]::SetEnvironmentVariable(\"Path\",$p,\"User\")"'
!macroend
# https://nsis.sourceforge.io/FindIt:_Simple_search_for_file_/_directory
diff --git a/kernel/cli/cmd/root.go b/kernel/cli/cmd/root.go
index 85d6fa2896..36e741c345 100644
--- a/kernel/cli/cmd/root.go
+++ b/kernel/cli/cmd/root.go
@@ -51,6 +51,11 @@ var rootCmd = &cobra.Command{
util.WorkingDir = appDir
}
+ langsDir := filepath.Join(util.WorkingDir, "appearance", "langs")
+ if _, err := os.Stat(langsDir); os.IsNotExist(err) {
+ return fmt.Errorf("appearance files not found at [%s]", langsDir)
+ }
+
// 设置工作空间路径
if workspacePath == "" {
workspacePath = os.Getenv("SIYUAN_WORKSPACE_PATH")
@@ -86,6 +91,7 @@ func findAppDir() string {
if exePath, err := os.Executable(); err == nil {
exeDir := filepath.Dir(exePath)
candidates := []string{
+ filepath.Join(exeDir, ".."), // resources/kernel/ → resources/ (production)
filepath.Join(exeDir, "..", "app"), // kernel/cli/ → kernel/ → app/
filepath.Join(exeDir, "app"), // kernel/ → app/
filepath.Join(exeDir, "..", "..", "app"), // kernel/cli/cmd/... → .../app/
diff --git a/kernel/cli/cmd/serve.go b/kernel/cli/cmd/serve.go
index ef820d8826..05f087a7c7 100644
--- a/kernel/cli/cmd/serve.go
+++ b/kernel/cli/cmd/serve.go
@@ -18,6 +18,7 @@ package cmd
import (
"os"
+ "path/filepath"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/job"
@@ -52,6 +53,11 @@ var serveCmd = &cobra.Command{
os.Args = newArgs
defer func() { os.Args = saved }()
+ // 设置工作目录为可执行文件所在目录
+ if exePath, err := os.Executable(); err == nil {
+ util.WorkingDir = filepath.Dir(exePath)
+ }
+
util.Boot()
model.InitJwtKey()
diff --git a/scripts/win-build.bat b/scripts/win-build.bat
index d7780e1e9f..f4a25e2bd2 100755
--- a/scripts/win-build.bat
+++ b/scripts/win-build.bat
@@ -101,7 +101,7 @@ if defined BUILD_AMD64 (
echo.
echo Building Kernel amd64
set GOARCH=amd64
- go build -tags fts5 -o "%PROJECT_ROOT%\app\kernel\SiYuan-Kernel.exe" -ldflags "-s -w -H=windowsgui" .
+ go build -tags fts5 -o "%PROJECT_ROOT%\app\kernel\SiYuan-Kernel.exe" -ldflags "-s -w" .
if errorlevel 1 (
exit /b %errorlevel%
)
@@ -113,7 +113,7 @@ if defined BUILD_ARM64 (
set GOARCH=arm64
@REM if you want to build arm64, you need to install aarch64-w64-mingw32-gcc
set CC="D:/Program Files/llvm-mingw-20240518-ucrt-x86_64/bin/aarch64-w64-mingw32-gcc.exe"
- go build -tags fts5 -o "%PROJECT_ROOT%\app\kernel-arm64\SiYuan-Kernel.exe" -ldflags "-s -w -H=windowsgui" .
+ go build -tags fts5 -o "%PROJECT_ROOT%\app\kernel-arm64\SiYuan-Kernel.exe" -ldflags "-s -w" .
if errorlevel 1 (
exit /b %errorlevel%
)