Skip to content

[codex] Add local execution environment - #89

Merged
delete-cloud merged 2 commits into
mainfrom
codex-environment-local-pr1
May 2, 2026
Merged

delete-cloud merged 2 commits into
mainfrom
codex-environment-local-pr1

Conversation

@delete-cloud

@delete-cloud delete-cloud commented May 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Add an AgentKit Environment protocol and app-level LocalEnvironment implementation.
  • Resolve local execution bindings into environments while keeping cloud bindings on an explicit not-implemented path.
  • Wire create_agent, SessionManager, and CoreToolsPlugin so local file, patch, and shell tools use the environment boundary.
  • Initialize shell session cwd from the active workspace and fall back to the injected workspace when session cwd is missing.
  • Preserve backward-compatible workspace_root construction for existing callers.

Verification

  • uv run pytest tests/agentkit tests/coding_agent/environment/test_local_environment.py tests/ui/test_execution_binding.py tests/coding_agent/plugins/test_core_tools.py tests/coding_agent/plugins/test_core_tools_parity.py tests/coding_agent/plugins/test_shell_session.py tests/coding_agent/test_bootstrap.py tests/ui/test_session_manager_runtime.py -q
  • uv run basedpyright src/agentkit/environment src/coding_agent/environment src/coding_agent/app.py src/coding_agent/plugins/core_tools.py src/coding_agent/plugins/shell_session.py src/coding_agent/ui/binding_resolver.py src/coding_agent/ui/session_manager.py tests/agentkit/environment/test_protocols.py tests/coding_agent/environment/test_local_environment.py tests/ui/test_execution_binding.py tests/coding_agent/plugins/test_core_tools.py tests/coding_agent/plugins/test_shell_session.py tests/coding_agent/test_bootstrap.py tests/ui/test_session_manager_runtime.py --level error
  • uv run python -m compileall -q src tests
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Introduced an Environment abstraction with a LocalEnvironment; agent creation and child pipelines can accept an injected Environment so nested pipelines and tools inherit it.
    • Shell session and binding resolution now respect pipeline workspace_root when available.
  • Tests

    • Added tests for LocalEnvironment, file confinement and patching, shell tool behavior, binding resolution, session/runtime integration, and plugin behavior with injected environments.

@coderabbitai

coderabbitai Bot commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9dbaf49e-395e-452f-9976-75f5f9284898

📥 Commits

Reviewing files that changed from the base of the PR and between cd2de83 and 13de5c6.

📒 Files selected for processing (1)
  • coding-agent/src/coding_agent/ui/binding_resolver.py

📝 Walkthrough

Walkthrough

Adds an Environment protocol and FileTools type, implements LocalEnvironment, and threads Environment objects through pipeline creation, binding resolution, CoreToolsPlugin, shell-session init, and session/agent wiring; tests added for protocol conformance, tool behavior, and environment propagation.

Changes

Environment abstraction and local runtime wiring

Layer / File(s) Summary
Protocol / Exports
agentkit/environment/protocols.py, agentkit/environment/__init__.py
Adds Environment Protocol (kind, tool_config, build_file_tools, build_file_patch_tool, build_shell_tool) and FileTools type alias; re-exports Environment/FileTools.
Local implementation
coding_agent/environment/local.py, coding_agent/environment/__init__.py
Adds LocalEnvironment that resolves/normalizes workspace_root, returns tool_config() and delegates to workspace-scoped file/shell tool factories; package exports LocalEnvironment.
Application factory
coding-agent/src/coding_agent/app.py
create_child_pipeline/create_agent gain optional environment; default to LocalEnvironment when omitted, derive/validate/resolve workspace_root from environment.tool_config(), wrap child-pipeline builder to propagate environment, and store environment in ctx.config.
Binding resolver
coding-agent/src/coding_agent/ui/binding_resolver.py
BindingResolver adds resolve_environment(); DefaultBindingResolver returns LocalEnvironment for local bindings, raises CloudBindingNotImplementedError for cloud bindings; workspace root resolution now applies expanduser().
Session manager / runtime wiring
coding-agent/src/coding_agent/ui/session_manager.py
Adds _resolve_environment(session) delegating to binding resolver and passes resolved environment into _create_agent_for_session call sites (checkpoint restore, run, runtime build).
Core tools plugin
coding-agent/src/coding_agent/plugins/core_tools.py
CoreToolsPlugin accepts injected environment; reads workspace_root from environment.tool_config() and builds file/shell tools via self._environment.* methods; bash_run arg preparation updated to use shell-session cwd/env with fallback to workspace root.
Shell session initial cwd
coding-agent/src/coding_agent/plugins/shell_session.py
ShellSessionPlugin computes initial cwd from ctx.config["workspace_root"] when present (validates/type-checks/resolve), otherwise falls back to os.getcwd().
Agentkit package export
coding-agent/src/agentkit/environment/__init__.py
Re-exports Environment and FileTools from new protocols module.
Tests
tests/... (coding_agent/environment/test_local_environment.py, agentkit/environment/test_protocols.py, coding_agent/plugins/test_core_tools.py, coding_agent/test_bootstrap.py, ui/test_execution_binding.py, ui/test_session_manager_runtime.py, coding_agent/plugins/test_shell_session.py)
Adds tests asserting LocalEnvironment behavior, protocol conformance, environment injection into CoreToolsPlugin and create_agent, binding resolver behavior, shell session mount using pipeline workspace root, and file tool confinement/patch behavior.

Sequence Diagram(s)

sequenceDiagram
    participant SessionMgr as Session Manager
    participant Binding as Binding Resolver
    participant App as App Factory
    participant Env as LocalEnvironment
    participant Core as CoreToolsPlugin
    participant Tools as Tool Factories

    SessionMgr->>Binding: resolve_environment(binding)
    Binding-->>SessionMgr: Environment (LocalEnvironment)

    SessionMgr->>App: create_agent(environment=env)
    App->>Env: tool_config()
    Env-->>App: {"workspace_root": path}
    App->>Core: init CoreToolsPlugin(environment=env)

    Core->>Env: build_file_tools()
    Env->>Tools: build_file_tools(workspace_root)
    Tools-->>Core: file tool callables

    Core->>Env: build_file_patch_tool()
    Env->>Tools: build_file_patch_tool(workspace_root)
    Tools-->>Core: patch callable

    Core->>Env: build_shell_tool()
    Env->>Tools: shell.bash_run
    Tools-->>Core: shell callable
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through protocols, snug and spry,
Local roots resolved beneath moonlit sky,
Tools tied to workspaces, tidy and bright,
Pipelines carry environments into the night,
A happy rabbit thumbs a joyful byte.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.28% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Add local execution environment' clearly and concisely describes the main change: introducing a local execution environment feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex-environment-local-pr1

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@delete-cloud
delete-cloud marked this pull request as ready for review May 2, 2026 06:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
coding-agent/src/agentkit/environment/protocols.py (1)

1-28: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Run the required AgentKit test suite for this change before merge.

This introduces new behavior under src/agentkit/, but the listed verification only runs targeted tests/coding_agent/ + tests/ui/ files. Please add relevant tests/agentkit/ coverage to the verification run.

As per coding guidelines, coding-agent/src/agentkit/**/*.py: “When changing agentkit code, run relevant tests/agentkit/ tests plus impacted tests/coding_agent/ tests”.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@coding-agent/src/agentkit/environment/protocols.py` around lines 1 - 28, The
change adds new behavior in agentkit (see Environment protocol and FileTools
tuple in protocols.py) but CI only runs tests/coding_agent/ and tests/ui/; add
and run relevant tests under tests/agentkit/ that cover Environment.kind,
tool_config, build_file_tools, build_file_patch_tool, and build_shell_tool
behavior (including return types of FileTools callables) and update the test run
to include tests/agentkit/ alongside existing targeted suites before merging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@coding-agent/src/coding_agent/plugins/core_tools.py`:
- Around line 127-135: The session context may have cwd==None so
_prepare_arguments (the method containing the shown snippet in CoreToolsPlugin)
should fall back to the injected workspace root; when self._shell_session is
present get the session via self._shell_session.get_session_context() and set
args["cwd"] to session.get("cwd") or self._workspace_root (i.e., use the session
cwd if present otherwise default to self._workspace_root), leaving env behavior
unchanged; alternatively you can instead update ShellSessionPlugin.do_mount() to
read ctx.config["workspace_root"] and initialize cwd with that value, but pick
one of these two fixes and apply it consistently.

---

Outside diff comments:
In `@coding-agent/src/agentkit/environment/protocols.py`:
- Around line 1-28: The change adds new behavior in agentkit (see Environment
protocol and FileTools tuple in protocols.py) but CI only runs
tests/coding_agent/ and tests/ui/; add and run relevant tests under
tests/agentkit/ that cover Environment.kind, tool_config, build_file_tools,
build_file_patch_tool, and build_shell_tool behavior (including return types of
FileTools callables) and update the test run to include tests/agentkit/
alongside existing targeted suites before merging.
🪄 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 Plus

Run ID: 61b882b1-71d9-40cc-9702-060604c1b27e

📥 Commits

Reviewing files that changed from the base of the PR and between cbd3263 and 3bb62f5.

📒 Files selected for processing (13)
  • coding-agent/src/agentkit/environment/__init__.py
  • coding-agent/src/agentkit/environment/protocols.py
  • coding-agent/src/coding_agent/app.py
  • coding-agent/src/coding_agent/environment/__init__.py
  • coding-agent/src/coding_agent/environment/local.py
  • coding-agent/src/coding_agent/plugins/core_tools.py
  • coding-agent/src/coding_agent/ui/binding_resolver.py
  • coding-agent/src/coding_agent/ui/session_manager.py
  • coding-agent/tests/coding_agent/environment/test_local_environment.py
  • coding-agent/tests/coding_agent/plugins/test_core_tools.py
  • coding-agent/tests/coding_agent/test_bootstrap.py
  • coding-agent/tests/ui/test_execution_binding.py
  • coding-agent/tests/ui/test_session_manager_runtime.py

Comment thread coding-agent/src/coding_agent/plugins/core_tools.py
@delete-cloud
delete-cloud force-pushed the codex-environment-local-pr1 branch from 3bb62f5 to 0571bfa Compare May 2, 2026 06:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
coding-agent/src/agentkit/environment/protocols.py (1)

6-12: 💤 Low value

Consider documenting the FileTools tuple positions.

The tuple type correctly captures the callable signatures, but the mapping to specific tools (file_read, file_write, file_replace, glob_files, grep_search) is implicit. A docstring or inline comment would improve maintainability.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@coding-agent/src/agentkit/environment/protocols.py` around lines 6 - 12, Add
a short docstring or inline comment for the FileTools type that explicitly maps
each tuple position to the tool name and its signature (e.g., position 0 =
file_read: Callable[[str], str | dict[str, Any]], position 1 = file_write:
Callable[[str, str], str], position 2 = file_replace: Callable[[str, str, str],
str], position 3 = glob_files: Callable[[str, str], str], position 4 =
grep_search: Callable[[str, str, str], str | dict[str, Any]]), so readers can
immediately see which callable corresponds to file_read, file_write,
file_replace, glob_files and grep_search when they encounter the FileTools
alias.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@coding-agent/src/agentkit/environment/protocols.py`:
- Around line 6-12: Add a short docstring or inline comment for the FileTools
type that explicitly maps each tuple position to the tool name and its signature
(e.g., position 0 = file_read: Callable[[str], str | dict[str, Any]], position 1
= file_write: Callable[[str, str], str], position 2 = file_replace:
Callable[[str, str, str], str], position 3 = glob_files: Callable[[str, str],
str], position 4 = grep_search: Callable[[str, str, str], str | dict[str,
Any]]), so readers can immediately see which callable corresponds to file_read,
file_write, file_replace, glob_files and grep_search when they encounter the
FileTools alias.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 30f72bb1-02d8-46a6-8386-5bcc9605439a

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb62f5 and 0571bfa.

📒 Files selected for processing (16)
  • coding-agent/src/agentkit/environment/__init__.py
  • coding-agent/src/agentkit/environment/protocols.py
  • coding-agent/src/coding_agent/app.py
  • coding-agent/src/coding_agent/environment/__init__.py
  • coding-agent/src/coding_agent/environment/local.py
  • coding-agent/src/coding_agent/plugins/core_tools.py
  • coding-agent/src/coding_agent/plugins/shell_session.py
  • coding-agent/src/coding_agent/ui/binding_resolver.py
  • coding-agent/src/coding_agent/ui/session_manager.py
  • coding-agent/tests/agentkit/environment/test_protocols.py
  • coding-agent/tests/coding_agent/environment/test_local_environment.py
  • coding-agent/tests/coding_agent/plugins/test_core_tools.py
  • coding-agent/tests/coding_agent/plugins/test_shell_session.py
  • coding-agent/tests/coding_agent/test_bootstrap.py
  • coding-agent/tests/ui/test_execution_binding.py
  • coding-agent/tests/ui/test_session_manager_runtime.py
✅ Files skipped from review due to trivial changes (4)
  • coding-agent/src/agentkit/environment/init.py
  • coding-agent/src/coding_agent/ui/binding_resolver.py
  • coding-agent/tests/ui/test_execution_binding.py
  • coding-agent/src/coding_agent/environment/init.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • coding-agent/src/coding_agent/environment/local.py
  • coding-agent/tests/coding_agent/plugins/test_core_tools.py
  • coding-agent/tests/coding_agent/test_bootstrap.py
  • coding-agent/tests/coding_agent/environment/test_local_environment.py

@delete-cloud
delete-cloud force-pushed the codex-environment-local-pr1 branch from 0571bfa to cd2de83 Compare May 2, 2026 06:56

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
coding-agent/src/coding_agent/ui/session_manager.py (1)

1299-1302: ⚡ Quick win

Prefer environment as the single source of workspace context here.

At Line 1299-1302 (and similarly in restore/build runtime paths), passing both workspace_root and environment duplicates resolution and keeps an unnecessary local-path dependency. Since create_agent/create_child_pipeline already derive workspace from environment, you can pass only environment in these paths.

Proposed simplification
pipeline, ctx = self._create_agent_for_session(
-    workspace_root=self._resolve_workspace_root(session),
     environment=self._resolve_environment(session),
     model_override=session.model_name,
     provider_override=session.provider_name,
     base_url_override=session.base_url,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@coding-agent/src/coding_agent/ui/session_manager.py` around lines 1299 -
1302, The code is passing both workspace_root and environment into
_create_agent_for_session (and similar restore/build runtime call sites) which
duplicates workspace resolution; update those calls to stop passing
workspace_root and only pass environment (use _resolve_environment(session) as
the single source of workspace context), and remove any dependence on
_resolve_workspace_root(session) in these call sites; ensure
_create_agent_for_session and downstream create_agent/create_child_pipeline
still derive workspace from the provided environment and adjust any related
parameter lists or docs if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@coding-agent/src/coding_agent/ui/binding_resolver.py`:
- Around line 47-48: The LocalExecutionBinding branch constructs
LocalEnvironment using resolve_workspace_root() which calls Path(...).resolve()
but doesn't expand ~, so paths like "~/repo" can be misresolved; update
resolve_workspace_root (or the call site) to expand user home first (e.g., use
Path(root).expanduser().resolve()) before passing the path into
LocalEnvironment, or alternatively pass the raw binding.root after expanding the
user component so LocalEnvironment always receives an expanded absolute path;
refer to LocalExecutionBinding, LocalEnvironment, and resolve_workspace_root
when making the change.

---

Nitpick comments:
In `@coding-agent/src/coding_agent/ui/session_manager.py`:
- Around line 1299-1302: The code is passing both workspace_root and environment
into _create_agent_for_session (and similar restore/build runtime call sites)
which duplicates workspace resolution; update those calls to stop passing
workspace_root and only pass environment (use _resolve_environment(session) as
the single source of workspace context), and remove any dependence on
_resolve_workspace_root(session) in these call sites; ensure
_create_agent_for_session and downstream create_agent/create_child_pipeline
still derive workspace from the provided environment and adjust any related
parameter lists or docs if needed.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d09dcf59-f53b-4315-9b51-47482bbf4926

📥 Commits

Reviewing files that changed from the base of the PR and between 0571bfa and cd2de83.

📒 Files selected for processing (16)
  • coding-agent/src/agentkit/environment/__init__.py
  • coding-agent/src/agentkit/environment/protocols.py
  • coding-agent/src/coding_agent/app.py
  • coding-agent/src/coding_agent/environment/__init__.py
  • coding-agent/src/coding_agent/environment/local.py
  • coding-agent/src/coding_agent/plugins/core_tools.py
  • coding-agent/src/coding_agent/plugins/shell_session.py
  • coding-agent/src/coding_agent/ui/binding_resolver.py
  • coding-agent/src/coding_agent/ui/session_manager.py
  • coding-agent/tests/agentkit/environment/test_protocols.py
  • coding-agent/tests/coding_agent/environment/test_local_environment.py
  • coding-agent/tests/coding_agent/plugins/test_core_tools.py
  • coding-agent/tests/coding_agent/plugins/test_shell_session.py
  • coding-agent/tests/coding_agent/test_bootstrap.py
  • coding-agent/tests/ui/test_execution_binding.py
  • coding-agent/tests/ui/test_session_manager_runtime.py
✅ Files skipped from review due to trivial changes (7)
  • coding-agent/src/agentkit/environment/protocols.py
  • coding-agent/src/agentkit/environment/init.py
  • coding-agent/src/coding_agent/environment/init.py
  • coding-agent/tests/coding_agent/plugins/test_core_tools.py
  • coding-agent/tests/ui/test_session_manager_runtime.py
  • coding-agent/src/coding_agent/plugins/core_tools.py
  • coding-agent/tests/coding_agent/test_bootstrap.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • coding-agent/src/coding_agent/environment/local.py
  • coding-agent/tests/coding_agent/plugins/test_shell_session.py
  • coding-agent/tests/agentkit/environment/test_protocols.py

Comment thread coding-agent/src/coding_agent/ui/binding_resolver.py
@coderabbitai

coderabbitai Bot commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 1 unresolved review comment.

Files modified:

  • coding-agent/src/coding_agent/ui/binding_resolver.py

Commit: 13de5c67d696bd00fa60afc1ddbd364e8e1bf732

The changes have been pushed to the codex-environment-local-pr1 branch.

Time taken: 2m 14s

Fixed 1 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@delete-cloud
delete-cloud merged commit 307fb8e into main May 2, 2026
1 check passed
@delete-cloud
delete-cloud deleted the codex-environment-local-pr1 branch May 2, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant