feat(workspace): make workspace location configurable via env var

- Add MYCLAUDE_WORKSPACE_ROOT env var, default ~/workspace
- Auto-create workspace directory if it does not exist
- Move workspace/CLAUDE.md + .gitignore to workspace_template/
- Remove hardcoded symlink paths from workspace template
- Update get_workspace_root() with env-var priority logic
- Update metabot bots.json defaultWorkingDirectory to ~/workspace
This commit is contained in:
Zhengshou Lai
2026-04-23 08:47:22 +08:00
parent bebf7ba17a
commit 475a0911e2
5 changed files with 52 additions and 34 deletions
+13 -7
View File
@@ -42,16 +42,22 @@
```
myclaude/
├── myclaude/ # Python 源码
│ ├── cli.py # CLI entrypoint
│ ├── commands/ # 子命令
├── myclaude/ # Python 源码
│ ├── cli.py # CLI entrypoint
│ ├── commands/ # 子命令
│ └── ...
├── workspace/ # 主工作环境 (默认 --cwd 目标)
│ └── CLAUDE.md # 日常工作指令
└── .claude/ # Claude Code 运行时配置
├── workspace_template/ # workspace 模板 (CLAUDE.md, .gitignore)
└── .claude/ # Claude Code 运行时配置
workspace/ # 主工作环境 (默认 --cwd 目标, 独立目录)
├── CLAUDE.md # 日常工作指令
├── myacademia -> ... # 符号链接
├── myslides -> ...
└── tmp/ # 临时文件
```
默认运行 `myclaude`(不带 --cwd)时,cwd 为 `workspace/`,指向工作区 CLAUDE.md。
默认运行 `myclaude`(不带 --cwd)时,cwd 为 `MYCLAUDE_WORKSPACE_ROOT`
(默认 `~/workspace`),指向独立工作区 CLAUDE.md。
开发 CLI 时运行 `myclaude --cwd .` 以读取本文件。
---
+2 -13
View File
@@ -10,7 +10,7 @@ import click
from rich.console import Console
from myclaude.commands import update_cmd, upgrade_cmd
from myclaude.project_root import get_myclaude_project_root
from myclaude.project_root import get_workspace_root
stderr_console = Console(stderr=True)
@@ -23,18 +23,7 @@ def _package_version() -> str:
def _resolve_chat_cwd() -> Path:
root = get_myclaude_project_root()
fallback = Path.home() / ".myclaude"
if root == fallback:
stderr_console.print(
"[red]Cannot resolve myclaude project root.[/red] Run from the repo or set "
"[cyan]MYCLAUDE_PROJECT_ROOT[/cyan].",
)
raise SystemExit(1)
workspace = root / "workspace"
if workspace.is_dir():
return workspace
return root
return get_workspace_root()
@click.group(
+23 -1
View File
@@ -1,4 +1,4 @@
"""Resolve myclaude repository root for make / editable install flows."""
"""Resolve myclaude repository and workspace roots."""
import os
from pathlib import Path
@@ -54,3 +54,25 @@ def get_myclaude_project_root() -> Path:
here = here.parent
return Path.home() / ".myclaude"
def get_workspace_root() -> Path:
"""
Root of the myclaude workspace directory.
Order: MYCLAUDE_WORKSPACE_ROOT > project_root/workspace/ > ~/workspace
Creates the directory if it does not exist.
"""
env_root = os.environ.get("MYCLAUDE_WORKSPACE_ROOT")
if env_root:
root = Path(env_root).expanduser().resolve()
else:
project_root = get_myclaude_project_root()
project_workspace = project_root / "workspace"
if project_workspace.is_dir():
root = project_workspace
else:
root = Path.home() / "workspace"
root.mkdir(parents=True, exist_ok=True)
return root
@@ -46,23 +46,24 @@
```
workspace/
├── .obsidian/ # Obsidian 配置
├── myacademia -> ... # → Obsidian/iCloud 知识库
├── myagent -> ... # → myagent 项目
├── mydesktop -> ... # → Obsidian/iCloud 过程/共享文件
├── myslides -> ... # → Slidev 幻灯片
├── mytoolkit -> ... # → 个人 CLI 工具集
├── mywebpage -> ... # → Docusaurus 网站
├── myacademia -> ... # → Obsidian/iCloud 知识库 (符号链接)
├── myagent -> ... # → myagent 项目 (符号链接)
├── mydesktop -> ... # → Obsidian/iCloud 过程/共享文件 (符号链接)
├── myslides -> ... # → Slidev 幻灯片 (符号链接)
├── mytoolkit -> ... # → 个人 CLI 工具集 (符号链接)
├── mywebpage -> ... # → Docusaurus 网站 (符号链接)
├── scripts/ # 实用脚本
└── tmp/ # 临时文件
```
**符号链接目标**:
- `myacademia``~/Library/Mobile Documents/iCloud~md~obsidian/Documents/myacademia`
- `mydesktop``~/Library/Mobile Documents/iCloud~md~obsidian/Documents/mydesktop`
- `myagent``~/Documents/myResearch/myProjects/apaam/repo/myagent`
- `myslides``~/Documents/myWork/sysu/4_成果归档/myslides`
- `mytoolkit``~/Documents/MyBin/mytoolkit`
- `mywebpage``~/Documents/myWork/sysu/4_成果归档/mywebpage`
**符号链接配置**
根据实际环境创建符号链接,目标路径因人而异。例如:
- `myacademia` → Obsidian/iCloud 知识库路径
- `mydesktop` → Obsidian/iCloud 过程文件路径
- `myagent` → myagent 项目路径
- `myslides` → Slidev 幻灯片路径
- `mytoolkit` → 个人 CLI 工具集路径
- `mywebpage` → Docusaurus 网站路径
**重要路径**:
- `myacademia/` - Obsidian 知识库