完成运行时与启动链路的全面相对路径整改,统一以仓库根为路径基准并移除 oclaw 双层硬编码。

同时补齐路径回归测试与开源自检文档,确保从非仓库 cwd 启动时 workspace 根、配置和 wiki 路径仍稳定可用。

Made-with: Cursor
This commit is contained in:
oliver 2026-04-26 09:22:42 +08:00
parent dbbe3add6a
commit 9d2900db02
40 changed files with 223 additions and 82 deletions

View file

@ -33,13 +33,17 @@ from oclaw.runtime.hooks.user_config_hooks import (
)
from oclaw.runtime.hooks.workspace import load_workspace_hook_entries
from oclaw.runtime.hooks_runtime import resolve_runtime_config
from oclaw.runtime.tools.experts.workspace.workspace_base import workspace_root
def _resolve_cli_workspace(ns: argparse.Namespace) -> str:
w = getattr(ns, "workspace", None)
if isinstance(w, str) and w.strip():
return w.strip()
return str(os.getenv("OCLAW_WORKSPACE") or os.getcwd()).strip() or "."
env_ws = str(os.getenv("OCLAW_WORKSPACE") or "").strip()
if env_ws:
return env_ws
return str(workspace_root())
def prepare_hooks_cli_config(cfg: dict[str, Any] | None) -> dict[str, Any]:

View file

@ -53,7 +53,8 @@ def _expand_env_value(v: str) -> str:
def _mcp_local_env_paths_in_load_order() -> list[Path]:
return [
Path(db_path()).resolve().parent / "mcp_local.env",
(PROJECT_ROOT / "oclaw" / "_local" / "mcp_local.env").resolve(),
(PROJECT_ROOT / "_local" / "mcp_local.env").resolve(),
(PROJECT_ROOT.parent / "_local" / "mcp_local.env").resolve(),
]
@ -66,7 +67,7 @@ def mcp_local_env_merged() -> dict[str, str]:
def mcp_local_env_file_path() -> Path:
return (PROJECT_ROOT / "oclaw" / "_local" / "mcp_local.env").resolve()
return (PROJECT_ROOT / "_local" / "mcp_local.env").resolve()
def gateway_mcp_env_extras() -> dict[str, str]:

View file

@ -13,7 +13,7 @@ from oclaw.platform.persistence.sqlite_store import SqliteStore
from oclaw.runtime.tools.mcp.registry import McpRegistry
_EXPORT_FILENAME = "mcp_registry_migrated.json"
_LOCAL_DIR = (PROJECT_ROOT / "oclaw" / "_local").resolve()
_LOCAL_DIR = (PROJECT_ROOT / "_local").resolve()
_EXPORT_PATH = (_LOCAL_DIR / _EXPORT_FILENAME).resolve()

View file

@ -144,19 +144,19 @@ def register_memory_parser(root_sub: argparse._SubParsersAction[argparse.Argumen
memory_sub = memory.add_subparsers(dest="memory_cmd", required=True)
status = memory_sub.add_parser("status", help="Show memory workload status")
status.add_argument("--base-dir", default="oclaw/docs/memory-system", help="Memory system base directory")
status.add_argument("--base-dir", default="docs/memory-system", help="Memory system base directory")
status.add_argument("--review-backlog", type=int, default=0, help="Current due review backlog")
status.set_defaults(func=_cmd_memory_status)
daily = memory_sub.add_parser("daily", help="Generate today's automated memory run")
daily.add_argument("--base-dir", default="oclaw/docs/memory-system", help="Memory system base directory")
daily.add_argument("--base-dir", default="docs/memory-system", help="Memory system base directory")
daily.add_argument("--date", default=None, help="Run date in YYYY-MM-DD")
daily.add_argument("--focus", default=None, help="Override focus topic")
daily.add_argument("--review-backlog", type=int, default=0, help="Current due review backlog")
daily.set_defaults(func=_cmd_memory_daily)
weekly = memory_sub.add_parser("weekly", help="Generate weekly review run sheet")
weekly.add_argument("--base-dir", default="oclaw/docs/memory-system", help="Memory system base directory")
weekly.add_argument("--base-dir", default="docs/memory-system", help="Memory system base directory")
weekly.add_argument("--date", default=None, help="Run date in YYYY-MM-DD")
weekly.add_argument("--review-backlog", type=int, default=0, help="Current due review backlog")
weekly.set_defaults(func=_cmd_memory_weekly)

View file

@ -17,7 +17,12 @@ function Write-Step([string]$msg) {
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoParent
Set-Location $repoRoot
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
Write-Step "Starting gateway + desktop"

View file

@ -22,6 +22,10 @@ if (-not (Test-Path $desktopDir)) {
Set-Location $desktopDir
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
if (-not $KeepExistingGateway) {
Write-Host "==> Cleaning previous gateway listener" -ForegroundColor Cyan

View file

@ -19,16 +19,20 @@ function Fail([string]$msg) {
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoParent
Set-Location $repoRoot
$runDir = Join-Path $PSScriptRoot ".run"
New-Item -ItemType Directory -Force -Path $runDir | Out-Null
$pidFile = Join-Path $runDir "gateway.pid"
Write-Step "Project root: $repoRoot"
Write-Step "Working directory: $repoParent"
Write-Step "Working directory: $repoRoot"
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
$venvPython = Join-Path $repoRoot ".venv/Scripts/python.exe"
if (Test-Path $venvPython) {
@ -70,7 +74,7 @@ if ($WithWikiWorker) {
if ($Background) {
Write-Step "Starting gateway in background"
$p = Start-Process -FilePath $pythonExe -ArgumentList @("-m","oclaw.runtime.operations","gateway","start","--host",$BindHost,"--port",$Port) -WorkingDirectory $repoParent -PassThru -WindowStyle Hidden
$p = Start-Process -FilePath $pythonExe -ArgumentList @("-m","oclaw.runtime.operations","gateway","start","--host",$BindHost,"--port",$Port) -WorkingDirectory $repoRoot -PassThru -WindowStyle Hidden
Set-Content -Path $pidFile -Value "$($p.Id)" -Encoding ascii
Write-Host "gateway.pid = $pidFile" -ForegroundColor DarkGray
Write-Host "PID = $($p.Id)" -ForegroundColor Green

View file

@ -17,12 +17,16 @@ function Fail([string]$msg) {
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoParent
Set-Location $repoRoot
Write-Step "Project root: $repoRoot"
Write-Step "Working directory: $repoParent"
Write-Step "Working directory: $repoRoot"
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
$venvPython = Join-Path $repoRoot ".venv/Scripts/python.exe"
if (Test-Path $venvPython) {

View file

@ -6,10 +6,11 @@ $ErrorActionPreference = "Stop"
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
return (Resolve-Path (Join-Path $here "..")).Path
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$repoRoot = Resolve-RepoRoot
$repoParent = Split-Path -Parent $repoRoot
$runDir = Join-Path $PSScriptRoot ".run"
$null = New-Item -ItemType Directory -Force -Path $runDir -ErrorAction SilentlyContinue
$pidFile = Join-Path $runDir "wiki_worker.pid"
@ -25,6 +26,16 @@ function Test-AlivePid([int]$procId) {
}
}
function Test-IsWikiWorkerPid([int]$procId) {
try {
$wmi = Get-CimInstance Win32_Process -Filter "ProcessId = $procId" -ErrorAction Stop
$cmd = [string]($wmi.CommandLine)
return $cmd -like "*oclaw.runtime.workers.wiki.main*"
} catch {
return $false
}
}
$venvPython = Join-Path $repoRoot ".venv/Scripts/python.exe"
if (Test-Path $venvPython) {
$pythonExe = $venvPython
@ -35,6 +46,11 @@ if (Test-Path $venvPython) {
}
$pythonExe = "python"
}
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
if (-not $Background) {
& $pythonExe -m oclaw.runtime.workers.wiki.main
@ -45,7 +61,7 @@ if (Test-Path $pidFile) {
$raw = (Get-Content $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
$existing = 0
[void][int]::TryParse([string]$raw, [ref]$existing)
if ($existing -gt 0 -and (Test-AlivePid $existing)) {
if ($existing -gt 0 -and (Test-AlivePid $existing) -and (Test-IsWikiWorkerPid $existing)) {
Write-Host "[ok] wiki worker already running pid=$existing"
exit 0
}

View file

@ -6,8 +6,12 @@ function Write-Step([string]$msg) {
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoParent
Set-Location $repoRoot
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
$venvPython = Join-Path $repoRoot ".venv/Scripts/python.exe"
if (Test-Path $venvPython) {
@ -17,7 +21,7 @@ if (Test-Path $venvPython) {
}
Write-Step "Project root: $repoRoot"
Write-Step "Working directory: $repoParent"
Write-Step "Working directory: $repoRoot"
Write-Step "Stack status"
& $pythonExe -m oclaw.runtime.operations stack status

View file

@ -10,8 +10,12 @@ function Write-Step([string]$msg) {
$repoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
$repoParent = Split-Path -Parent $repoRoot
Set-Location $repoParent
Set-Location $repoRoot
$env:PYTHONPATH = $repoParent
$env:PYTHONSAFEPATH = "1"
$env:AIA_WORKSPACE_ROOT = $repoRoot
$env:OPS_WORKSPACE_ROOT = $repoRoot
$env:OCLAW_WORKSPACE = $repoRoot
$venvPython = Join-Path $repoRoot ".venv/Scripts/python.exe"
if (Test-Path $venvPython) {
@ -21,7 +25,7 @@ if (Test-Path $venvPython) {
}
Write-Step "Project root: $repoRoot"
Write-Step "Working directory: $repoParent"
Write-Step "Working directory: $repoRoot"
Write-Step "Stopping stack services..."
try {

View file

@ -16,7 +16,7 @@ from oclaw.platform.persistence.sqlite_store import SqliteStore
def _load_cfg() -> dict:
cfg_file = (Path(PROJECT_ROOT) / "oclaw" / "oclaw.json").resolve()
cfg_file = (Path(PROJECT_ROOT) / "oclaw.json").resolve()
if not cfg_file.exists():
return {}
try:
@ -30,7 +30,7 @@ def _wiki_root_from_cfg(cfg: dict) -> Path:
plugins = cfg.get("plugins") if isinstance(cfg, dict) else {}
entries = plugins.get("entries") if isinstance(plugins, dict) else {}
mw = entries.get("memory-wiki") if isinstance(entries, dict) else {}
root_cfg = str((mw or {}).get("wiki_root") or "oclaw/docs/memory-system/wiki").strip()
root_cfg = str((mw or {}).get("wiki_root") or "docs/memory-system/wiki").strip()
root = Path(root_cfg)
if not root.is_absolute():
root = (Path(PROJECT_ROOT) / root).resolve()