Return OpenCode's working directory for this run. The safe default is the repo root with local file/bash/edit tools denied. Any filesystem/code capability must opt into a dedicated workspace folder. This keeps the default comparable to tools-only MCP agents while allowing a separate
(
*,
workspace_dir: Path | str | None = None,
allow_bash: bool = False,
allow_edit: bool = False,
allow_files: bool = False,
)
| 190 | |
| 191 | |
| 192 | def _resolve_run_dir( |
| 193 | *, |
| 194 | workspace_dir: Path | str | None = None, |
| 195 | allow_bash: bool = False, |
| 196 | allow_edit: bool = False, |
| 197 | allow_files: bool = False, |
| 198 | ) -> Path: |
| 199 | """Return OpenCode's working directory for this run. |
| 200 | |
| 201 | The safe default is the repo root with local file/bash/edit tools denied. |
| 202 | Any filesystem/code capability must opt into a dedicated workspace folder. |
| 203 | This keeps the default comparable to tools-only MCP agents while allowing a |
| 204 | separate CLI/code-capable track. |
| 205 | """ |
| 206 | workspace_requested = allow_bash or allow_edit or allow_files |
| 207 | if workspace_requested and workspace_dir is None: |
| 208 | raise ValueError( |
| 209 | "--workspace-dir is required when enabling files, edits, or bash" |
| 210 | ) |
| 211 | if workspace_dir is None: |
| 212 | return _REPO_ROOT |
| 213 | |
| 214 | run_dir = Path(workspace_dir).expanduser().resolve() |
| 215 | run_dir.mkdir(parents=True, exist_ok=True) |
| 216 | return run_dir |
| 217 | |
| 218 | |
| 219 | def _json_events(stdout: str) -> tuple[list[dict[str, Any]], list[str]]: |
no outgoing calls