Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat: 首次启动无需init

douran60e31ca8e3ca
diff --git a/jiuwenclaw/app.py b/jiuwenclaw/app.py
index 2fcb8b58ca..43fb9934bc 100644
--- a/jiuwenclaw/app.py
+++ b/jiuwenclaw/app.py
@@ -895,12 +895,16 @@ async def _run() -> None:
from jiuwenclaw.schema.message import Message, EventType, ReqMethod
from jiuwenclaw.agentserver.memory.config import _load_config as _load_agent_config
from jiuwenclaw.agentserver.tools.browser_tools import restart_local_browser_runtime_server
+ from jiuwenclaw.utils import prepare_workspace, USER_WORKSPACE_DIR
agent_port = int(os.getenv("AGENT_PORT", "18092"))
web_host = os.getenv("WEB_HOST", "127.0.0.1")
web_port = int(os.getenv("WEB_PORT", "19000"))
web_path = os.getenv("WEB_PATH", "/ws")
+ if not USER_WORKSPACE_DIR.exists():
+ prepare_workspace(overwrite=False)
+
def _do_restart() -> None:
"""重新执行当前进程以加载新 .env(配置修改后重启服务)。"""
logger.info("[App] 配置已写回 .env,正在重启服务…")
diff --git a/jiuwenclaw/utils.py b/jiuwenclaw/utils.py
index 429b488157..434e76b665 100644
--- a/jiuwenclaw/utils.py
+++ b/jiuwenclaw/utils.py
@@ -87,31 +87,7 @@ def _find_package_root() -> Path | None:
return current
-def init_user_workspace(overwrite: bool = True) -> Path:
- """Initialize ~/.jiuwenclaw from package or source resources.
-
- 资源布局(新):
- - 模板配置: <package_root>/resources/config.yaml
- - .env 模板: <package_root>/resources/.env.template
- - workspace: 优先 <package_root>/workspace,其次 <package_root>/../workspace
-
- 上述内容会被复制到:
- - ~/.jiuwenclaw/config/config.yaml
- - ~/.jiuwenclaw/.env
- - ~/.jiuwenclaw/workspace/...
-
- 无论是通过 pip/whl 安装还是源码目录直接运行,效果保持一致。
- """
- if USER_WORKSPACE_DIR.exists():
- # Warn user about data loss and ask for confirmation
- print("[jiuwenclaw-init] WARNING: This will delete all historical configuration and memory information.")
- print("[jiuwenclaw-init] This action cannot be undone.")
- confirmation = input("[jiuwenclaw-init] Do you want to confirm reinitialization? (yes/no): ").strip().lower()
-
- if confirmation not in ("yes", "y"):
- print("[jiuwenclaw-init] Initialization cancelled. Exiting.")
- return "cancelled"
-
+def prepare_workspace(overwrite: bool = True):
package_root = _find_package_root()
if not package_root:
raise RuntimeError("package root not found")
@@ -174,6 +150,34 @@ def init_user_workspace(overwrite: bool = True) -> Path:
if overwrite or not env_dest.exists():
shutil.copy2(env_template_src, env_dest)
+
+def init_user_workspace(overwrite: bool = True) -> Path:
+ """Initialize ~/.jiuwenclaw from package or source resources.
+
+ 资源布局(新):
+ - 模板配置: <package_root>/resources/config.yaml
+ - .env 模板: <package_root>/resources/.env.template
+ - workspace: 优先 <package_root>/workspace,其次 <package_root>/../workspace
+
+ 上述内容会被复制到:
+ - ~/.jiuwenclaw/config/config.yaml
+ - ~/.jiuwenclaw/.env
+ - ~/.jiuwenclaw/workspace/...
+
+ 无论是通过 pip/whl 安装还是源码目录直接运行,效果保持一致。
+ """
+ if USER_WORKSPACE_DIR.exists():
+ # Warn user about data loss and ask for confirmation
+ print("[jiuwenclaw-init] WARNING: This will delete all historical configuration and memory information.")
+ print("[jiuwenclaw-init] This action cannot be undone.")
+ confirmation = input("[jiuwenclaw-init] Do you want to confirm reinitialization? (yes/no): ").strip().lower()
+
+ if confirmation not in ("yes", "y"):
+ print("[jiuwenclaw-init] Initialization cancelled. Exiting.")
+ return "cancelled"
+
+ prepare_workspace(overwrite)
+
return USER_WORKSPACE_DIR