Fix: Add NERVE_AGENT_WORKSPACES config for custom agent workspace paths#202
Fix: Add NERVE_AGENT_WORKSPACES config for custom agent workspace paths#202gregb100 wants to merge 1 commit intodaggerhashimoto:masterfrom
Conversation
Allows mapping specific agent IDs to custom workspace locations via environment variable (e.g., NERVE_AGENT_WORKSPACES=otto:/path/to/workspace). This fixes the Memory tab showing 'Sandboxed Workspace' incorrectly when the workspace exists locally but at a non-standard path. Related to daggerhashimoto#145 - builds on the remote workspace detection to support custom workspace paths beyond the default ~/.openclaw/workspace-{agentId} convention.
📝 WalkthroughWalkthroughThe changes add support for per-agent workspace path customization via the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@server/lib/config.ts`:
- Around line 97-99: The parsing currently uses pair.split(':') which splits on
every colon and truncates workspacePath (e.g., Windows paths); change the logic
that builds result (where pair is parsed and result[agentId.trim()] =
workspacePath.trim()) to only split on the first ':' — e.g., find the first
colon with pair.indexOf(':') and set agentId = pair.slice(0, idx) and
workspacePath = pair.slice(idx + 1) (or use pair.split(':', 2)) so workspacePath
preserves any remaining colons, then trim and assign as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ec42c249-b0c4-4a3f-b81c-f075dba49d9e
📒 Files selected for processing (2)
server/lib/agent-workspace.tsserver/lib/config.ts
| const [agentId, workspacePath] = pair.split(':'); | ||
| if (agentId && workspacePath) { | ||
| result[agentId.trim()] = workspacePath.trim(); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n server/lib/config.ts | sed -n '80,110p'Repository: daggerhashimoto/openclaw-nerve
Length of output: 1831
🏁 Script executed:
# Search for test cases or examples related to agentWorkspaces format
rg -i "agentworkspace|agent.*workspace" --type ts --type js -B 2 -A 2 server/ | head -100Repository: daggerhashimoto/openclaw-nerve
Length of output: 5904
🏁 Script executed:
# Check the agent-workspace.ts file to understand how the parsed config is used
cat -n server/lib/agent-workspace.ts | head -50Repository: daggerhashimoto/openclaw-nerve
Length of output: 1964
Split only on the first : to avoid truncating workspace paths.
Using pair.split(':') breaks values like agent1:C:\work\space (Windows drive letters and any path containing :) because destructuring [agentId, workspacePath] = split_result captures only the first two array elements. This truncates workspacePath to just C, causing incorrect workspace resolution in agent-workspace.ts line 44.
🔧 Proposed fix
for (const pair of pairs) {
- const [agentId, workspacePath] = pair.split(':');
- if (agentId && workspacePath) {
- result[agentId.trim()] = workspacePath.trim();
- }
+ const idx = pair.indexOf(':');
+ if (idx <= 0 || idx === pair.length - 1) continue;
+
+ const agentId = pair.slice(0, idx).trim();
+ const workspacePath = pair.slice(idx + 1).trim();
+ if (agentId && workspacePath) {
+ result[agentId] = workspacePath;
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const [agentId, workspacePath] = pair.split(':'); | |
| if (agentId && workspacePath) { | |
| result[agentId.trim()] = workspacePath.trim(); | |
| const idx = pair.indexOf(':'); | |
| if (idx <= 0 || idx === pair.length - 1) continue; | |
| const agentId = pair.slice(0, idx).trim(); | |
| const workspacePath = pair.slice(idx + 1).trim(); | |
| if (agentId && workspacePath) { | |
| result[agentId] = workspacePath; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@server/lib/config.ts` around lines 97 - 99, The parsing currently uses
pair.split(':') which splits on every colon and truncates workspacePath (e.g.,
Windows paths); change the logic that builds result (where pair is parsed and
result[agentId.trim()] = workspacePath.trim()) to only split on the first ':' —
e.g., find the first colon with pair.indexOf(':') and set agentId =
pair.slice(0, idx) and workspacePath = pair.slice(idx + 1) (or use
pair.split(':', 2)) so workspacePath preserves any remaining colons, then trim
and assign as before.
What
Adds NERVE_AGENT_WORKSPACES environment variable to map agent IDs to custom workspace paths. This allows Nerve to detect and access workspaces located at non-standard paths (e.g., /home/clawhost/projects/otto instead of ~/.openclaw/workspace-otto).
Why
Fixes the Memory tab incorrectly showing "Sandboxed Workspace" when the workspace exists locally but at a non-standard path. Related to #145 — builds on the remote workspace detection to support custom workspace paths beyond the default ~/.openclaw/workspace-{agentId} convention.
How
• Added agentWorkspaces config parser in server/lib/config.ts that reads NERVE_AGENT_WORKSPACES env var (format: agentId:/path,agentId2:/path2)
• Modified server/lib/agent-workspace.ts to check for custom workspace path before falling back to default ~/.openclaw/workspace-{agentId}
• Example config: NERVE_AGENT_WORKSPACES={agentId}:/home/projects/{agentId}
Type of Change
• [x] 🐛 Bug fix (non-breaking change that fixes an issue)
• [ ] ✨ New feature (non-breaking change that adds functionality)
• [ ] 💥 Breaking change (fix or feature that would cause existing functionality to change)
• [ ] 📝 Documentation update
• [ ] 🔧 Refactor / chore (no functional change)
Checklist
• [x] npm run lint passes
• [x] npm run build && npm run build:server succeeds
• [ ] npm test -- --run passes
• [ ] New features include tests
• [ ] UI changes include a screenshot or screen recording
Screenshots
N/A — backend-only fix
Summary by CodeRabbit