diff --git a/install.sh b/install.sh index c99002d..08064f6 100755 --- a/install.sh +++ b/install.sh @@ -107,6 +107,13 @@ create_workspaces() { log "Workspace 已创建: $ws" done + # 写入 EDICT_REPO_DIR 环境变量(供 kanban_update.py 等脚本定位数据目录) + for agent in "${AGENTS[@]}"; do + ws="$OC_HOME/workspace-$agent" + echo "EDICT_REPO_DIR=$REPO_DIR" > "$ws/.env" + done + log "EDICT_REPO_DIR 已写入所有 workspace/.env" + # 通用 AGENTS.md(工作协议) for agent in "${AGENTS[@]}"; do cat > "$OC_HOME/workspace-$agent/AGENTS.md" << 'AGENTS_EOF' diff --git a/scripts/kanban_update.py b/scripts/kanban_update.py index 42bf9dc..087229f 100644 --- a/scripts/kanban_update.py +++ b/scripts/kanban_update.py @@ -24,7 +24,36 @@ """ import json, pathlib, sys, subprocess, logging, os, re -_BASE = pathlib.Path(__file__).resolve().parent.parent + +def _find_repo_root(): + """Resolve the canonical repo root directory. + + Priority: + 1. EDICT_REPO_DIR environment variable (set by install.sh) + 2. Walk up from __file__ looking for .git or dashboard/ as repo markers + 3. Fall back to __file__-based parent (original behavior) + """ + env_dir = os.environ.get('EDICT_REPO_DIR', '').strip() + if env_dir: + p = pathlib.Path(env_dir) + if p.is_dir(): + return p + + # Walk up from script location looking for repo markers + candidate = pathlib.Path(__file__).resolve().parent.parent + for _ in range(5): + if (candidate / '.git').exists() or (candidate / 'dashboard').is_dir(): + return candidate + parent = candidate.parent + if parent == candidate: + break + candidate = parent + + # Fall back to original behavior + return pathlib.Path(__file__).resolve().parent.parent + + +_BASE = _find_repo_root() TASKS_FILE = _BASE / 'data' / 'tasks_source.json' REFRESH_SCRIPT = _BASE / 'scripts' / 'refresh_live_data.py' diff --git a/scripts/refresh_live_data.py b/scripts/refresh_live_data.py index bd96490..c0f0580 100644 --- a/scripts/refresh_live_data.py +++ b/scripts/refresh_live_data.py @@ -1,12 +1,39 @@ #!/usr/bin/env python3 -import json, pathlib, datetime, logging +import json, pathlib, datetime, logging, os from file_lock import atomic_json_write, atomic_json_read from utils import read_json log = logging.getLogger('refresh') logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(name)s] %(message)s', datefmt='%H:%M:%S') -BASE = pathlib.Path(__file__).parent.parent + +def _find_repo_root(): + """Resolve the canonical repo root directory. + + Priority: + 1. EDICT_REPO_DIR environment variable (set by install.sh) + 2. Walk up from __file__ looking for .git or dashboard/ as repo markers + 3. Fall back to __file__-based parent (original behavior) + """ + env_dir = os.environ.get('EDICT_REPO_DIR', '').strip() + if env_dir: + p = pathlib.Path(env_dir) + if p.is_dir(): + return p + + candidate = pathlib.Path(__file__).resolve().parent.parent + for _ in range(5): + if (candidate / '.git').exists() or (candidate / 'dashboard').is_dir(): + return candidate + parent = candidate.parent + if parent == candidate: + break + candidate = parent + + return pathlib.Path(__file__).resolve().parent.parent + + +BASE = _find_repo_root() DATA = BASE / 'data'