Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
sandbox.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
36#pragma once
37
38#include <filesystem>
39#include <optional>
40#include <string>
41#include <vector>
42
43namespace entropic {
44
50 std::filesystem::path path;
51 std::string delegation_id;
52 std::filesystem::path base_dir;
53};
54
67 std::string patch;
68 std::vector<std::filesystem::path> files_touched;
69 std::filesystem::path base_dir;
70 std::filesystem::path head_dir;
71};
72
100public:
116 explicit SandboxManager(const std::filesystem::path& project_dir);
117
127
128 SandboxManager(SandboxManager&&) = default;
129 SandboxManager& operator=(SandboxManager&&) = default;
130 SandboxManager(const SandboxManager&) = delete;
131 SandboxManager& operator=(const SandboxManager&) = delete;
132
154 std::optional<SandboxInfo> create_sandbox(
155 const std::string& delegation_id,
156 std::optional<SandboxInfo> chain_from = std::nullopt);
157
172 std::optional<SandboxResult> finalize_sandbox(const SandboxInfo& info);
173
183 void discard_sandbox(const SandboxInfo& info);
184
200 std::optional<std::filesystem::path> write_pending_patch(
201 const std::string& delegation_id,
202 const std::string& patch);
203
209 const std::filesystem::path& project_dir() const;
210
216 const std::filesystem::path& session_base() const;
217
218private:
224 bool ensure_base_snapshot();
225
238 bool snapshot_tree(const std::filesystem::path& source,
239 const std::filesystem::path& target);
240
253 bool path_in_session_base(const std::filesystem::path& p) const;
254
260 void safe_remove(const std::filesystem::path& p);
261
266 void prune_stale_sessions();
267
268 std::filesystem::path project_dir_;
269 std::string session_id_;
270 std::filesystem::path session_base_;
271 std::filesystem::path base_dir_;
272 bool base_ready_ = false;
273};
274
286public:
297 using SwapDirFn = void (*)(
298 const std::filesystem::path& path, void* user_data);
299
308 ScopedSandbox(SwapDirFn swap_fn,
309 void* user_data,
310 const std::filesystem::path& sandbox_path,
311 const std::filesystem::path& original_path);
312
318
319 ScopedSandbox(const ScopedSandbox&) = delete;
320 ScopedSandbox& operator=(const ScopedSandbox&) = delete;
321
322private:
323 SwapDirFn swap_fn_;
324 void* user_data_;
325 std::filesystem::path original_path_;
326};
327
328} // namespace entropic
Create, finalize, and discard per-delegation filesystem sandboxes.
Definition sandbox.h:99
const std::filesystem::path & session_base() const
Get this session's sandbox base directory.
Definition sandbox.cpp:599
void discard_sandbox(const SandboxInfo &info)
Remove a sandbox directory.
Definition sandbox.cpp:533
std::optional< SandboxResult > finalize_sandbox(const SandboxInfo &info)
Produce the final patch artifact for a sandbox.
Definition sandbox.cpp:506
std::optional< SandboxInfo > create_sandbox(const std::string &delegation_id, std::optional< SandboxInfo > chain_from=std::nullopt)
Create a new delegation sandbox.
Definition sandbox.cpp:390
~SandboxManager()
Remove this session's sandbox tree.
Definition sandbox.cpp:192
std::optional< std::filesystem::path > write_pending_patch(const std::string &delegation_id, const std::string &patch)
Write a patch to the session's pending/ directory.
Definition sandbox.cpp:552
const std::filesystem::path & project_dir() const
Get the project directory this manager snapshots from.
Definition sandbox.cpp:589
RAII directory swapper for sandbox-scoped tool execution.
Definition sandbox.h:285
~ScopedSandbox()
Restore the original directory.
Definition sandbox.cpp:634
void(*)(const std::filesystem::path &path, void *user_data) SwapDirFn
Callback type for directory swapping.
Definition sandbox.h:298
Activate model on GPU (WARM → ACTIVE).
Identifies one delegation's sandbox directory.
Definition sandbox.h:49
std::filesystem::path base_dir
Snapshot used as this sandbox's starting state.
Definition sandbox.h:52
std::filesystem::path path
Sandbox directory (under session base)
Definition sandbox.h:50
std::string delegation_id
Short delegation id (e.g. "d1", "pipeline")
Definition sandbox.h:51
Final artifact emitted by a finalized sandbox.
Definition sandbox.h:66
std::filesystem::path head_dir
Final sandbox state.
Definition sandbox.h:70
std::vector< std::filesystem::path > files_touched
Relative paths that changed.
Definition sandbox.h:68
std::string patch
Unified diff text.
Definition sandbox.h:67
std::filesystem::path base_dir
Snapshot the diff is against.
Definition sandbox.h:69