From 13285e7a8bb1c4ad9940f812be66f289413724d3 Mon Sep 17 00:00:00 2001 From: hotwa Date: Wed, 18 Mar 2026 00:36:10 +0800 Subject: [PATCH] Add project workspace init script --- daily/2026-03-18.md | 5 ++ scripts/init-project-workspace.sh | 136 ++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100755 scripts/init-project-workspace.sh diff --git a/daily/2026-03-18.md b/daily/2026-03-18.md index 5e7d68e..2ef631f 100644 --- a/daily/2026-03-18.md +++ b/daily/2026-03-18.md @@ -59,3 +59,8 @@ - 若 Pixi 失效或不适用,可使用 UV 作为后备方案 - 默认应把 Pixi 作为首选项目环境管理器 - 已新增长期决策文档:`shared/long-term/decisions/project-workspace-layout.md` +- 已新增可复用初始化脚本:`scripts/init-project-workspace.sh` + - 用于快速创建标准项目容器目录 + - 会初始化 `repos/`、`worktrees/`、`shared/`、`docs/`、`scripts/`、`tmp/` + - 会生成项目级 `docs/PROJECT-RULES.md` + - 该规则文档内已包含 Pixi 优先、`.pixi/` 不跟踪、UV 作为后备方案的说明 diff --git a/scripts/init-project-workspace.sh b/scripts/init-project-workspace.sh new file mode 100755 index 0000000..07aa078 --- /dev/null +++ b/scripts/init-project-workspace.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +set -euo pipefail + +PROJECT_ROOT_BASE="${PROJECT_ROOT_BASE:-$HOME/project/workspace}" + +usage() { + cat <<'EOF' +Usage: + init-project-workspace.sh + +Description: + Create a standard project container under ~/project/workspace with: + repos/ + worktrees/ + shared/ + docs/ + scripts/ + tmp/ + + Also creates: + - docs/PROJECT-RULES.md + - .gitignore at project container root + - shared/.gitkeep + - tmp/.gitkeep + +Notes: + - Project repos inside repos/ should prefer Pixi for environment management. + - Each repo should include pixi.toml. + - .pixi/ must not be tracked by git. + - UV may be used only as a fallback when Pixi is not suitable. +EOF +} + +if [[ "${1:-}" == "-h" || "${1:-}" == "--help" || $# -lt 1 ]]; then + usage + exit 0 +fi + +PROJECT_NAME="$1" +PROJECT_DIR="$PROJECT_ROOT_BASE/$PROJECT_NAME" + +mkdir -p \ + "$PROJECT_DIR/repos" \ + "$PROJECT_DIR/worktrees" \ + "$PROJECT_DIR/shared" \ + "$PROJECT_DIR/docs" \ + "$PROJECT_DIR/scripts" \ + "$PROJECT_DIR/tmp" + +cat > "$PROJECT_DIR/.gitignore" <<'EOF' +# macOS +.DS_Store + +# Editor / IDE +.vscode/ +.idea/ + +# Logs / temp +*.log +*.tmp + +# Local scratch / caches +.cache/ +EOF + +cat > "$PROJECT_DIR/docs/PROJECT-RULES.md" <<'EOF' +# Project Rules + +## Workspace Layout + +This project follows the standard OpenClaw multi-machine project container layout: + +```text +/ +├── repos/ +├── worktrees/ +├── shared/ +├── docs/ +├── scripts/ +└── tmp/ +``` + +## Environment Management + +Default rule: + +- Prefer **Pixi** for per-project environment management +- Each repo should include `pixi.toml` +- If reproducibility is needed, include `pixi.lock` +- Do **not** track `.pixi/` +- Use **UV** only when Pixi is unsuitable or blocked + +Recommended `.gitignore` entries inside each repo: + +```gitignore +.pixi/ +.venv/ +__pycache__/ +node_modules/ +``` + +## Multi-Machine Collaboration + +- `mac-5` = brain → orchestration / review / final integration +- `mac-6` = hands → execution / implementation / build +- `mac-7` = eyes → browser / verification / acceptance + +Collaboration model: + +- Each machine keeps its own local project copy +- Code sync uses git remote +- Active `.git` / `git worktree` metadata is not treated as file-sync state +- Final integration and merge should usually happen on `mac-5` + +## Worktree Convention + +Recommended layout: + +```text +worktrees// +``` + +Examples: + +- `worktrees/backend/feat-auth` +- `worktrees/frontend/feat-dashboard` +- `worktrees/backend/integration-merge` +EOF + +touch "$PROJECT_DIR/shared/.gitkeep" "$PROJECT_DIR/tmp/.gitkeep" + +echo "Created project container: $PROJECT_DIR" +echo "Next steps:" +echo " 1) Put real repos under: $PROJECT_DIR/repos" +echo " 2) Put parallel worktrees under: $PROJECT_DIR/worktrees" +echo " 3) For each repo, prefer Pixi with pixi.toml and ignore .pixi/"