Modern Apps git

← Modern-Apps.git

infra: agents harness workspace skeleton and runner wire types

Commit
e783c3224c30e66947f99424c5ec2d8a8f2eaf1d
Author
Vayun Mathur <[email protected]>
When
2026-11-04 23:36 UTC (1 month ago)
Parents
6aedd53
Adds infra/agents, a standalone Cargo workspace (excluded from the root
workspace like tilecodec) for the on-server agent harness: `agentd`
(web UI, task queue, OpenRouter loop, git push) and `agent-runner`
(command and file execution inside the untrusted builder sandbox).

The `proto` crate fixes the agentd -> runner HTTP API up front so both
binaries can be built in parallel against one contract: slot prepare,
exec (shell vs serialized build), read/write/edit/list/search, diff,
commit, bundle export, cancel and build kill. Bundles are the only way
agent commits leave the sandbox, so agentd never runs git against a
repo whose config the sandbox controls.

agentd and runner are empty stubs here; they are filled in by follow-up
commits. Verified with `cargo check` in infra/agents.

Diff

Cargo.toml
diff --git a/Cargo.toml b/Cargo.tomlindex 03cf551fff..a5ee29ba56 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -72,7 +72,7 @@ members = [ # missing member fails resolution of the whole workspace. Excluded entries may # match nothing, so this keeps the root workspace resolvable with and without # personal/ present.-exclude = ["library/tilecodec/src/main/rust", "personal/uniflix_strem/src/main/rust"]+exclude = ["library/tilecodec/src/main/rust", "personal/uniflix_strem/src/main/rust", "infra/agents"] resolver = "2"  [workspace.package]
infra/agents/.gitignore
diff --git a/infra/agents/.gitignore b/infra/agents/.gitignorenew file mode 100644index 0000000000..2f7896d1d1--- /dev/null+++ b/infra/agents/.gitignore@@ -0,0 +1 @@+target/
infra/agents/Cargo.lock
diff --git a/infra/agents/Cargo.lock b/infra/agents/Cargo.locknew file mode 100644index 0000000000..7be9b6696f--- /dev/null+++ b/infra/agents/Cargo.lock@@ -0,0 +1,124 @@+# This file is automatically @generated by Cargo.+# It is not intended for manual editing.+version = 4++[[package]]+name = "agent-runner"+version = "0.1.0"+dependencies = [+ "proto",+ "serde",+ "serde_json",+]++[[package]]+name = "agentd"+version = "0.1.0"+dependencies = [+ "proto",+ "serde",+ "serde_json",+]++[[package]]+name = "itoa"+version = "1.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"++[[package]]+name = "memchr"+version = "2.8.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"++[[package]]+name = "proc-macro2"+version = "1.0.107"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "proto"+version = "0.1.0"+dependencies = [+ "serde",+]++[[package]]+name = "quote"+version = "1.0.47"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"+dependencies = [+ "proc-macro2",+]++[[package]]+name = "serde"+version = "1.0.229"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"+dependencies = [+ "serde_core",+ "serde_derive",+]++[[package]]+name = "serde_core"+version = "1.0.229"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"+dependencies = [+ "serde_derive",+]++[[package]]+name = "serde_derive"+version = "1.0.229"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "serde_json"+version = "1.0.154"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]++[[package]]+name = "syn"+version = "3.0.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "unicode-ident"+version = "1.0.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"++[[package]]+name = "zmij"+version = "1.0.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
infra/agents/Cargo.toml
diff --git a/infra/agents/Cargo.toml b/infra/agents/Cargo.tomlnew file mode 100644index 0000000000..a3f8d8940b--- /dev/null+++ b/infra/agents/Cargo.toml@@ -0,0 +1,14 @@+[workspace]+members = ["proto", "agentd", "runner"]+resolver = "2"++[workspace.package]+version = "0.1.0"+edition = "2021"+publish = false+license = "Apache-2.0"++[workspace.dependencies]+proto = { path = "proto" }+serde = { version = "1", features = ["derive"] }+serde_json = "1"
infra/agents/agentd/Cargo.toml
diff --git a/infra/agents/agentd/Cargo.toml b/infra/agents/agentd/Cargo.tomlnew file mode 100644index 0000000000..5f8aadecac--- /dev/null+++ b/infra/agents/agentd/Cargo.toml@@ -0,0 +1,11 @@+[package]+name = "agentd"+version.workspace = true+edition.workspace = true+publish.workspace = true+license.workspace = true++[dependencies]+proto.workspace = true+serde.workspace = true+serde_json.workspace = true
infra/agents/agentd/src/main.rs
diff --git a/infra/agents/agentd/src/main.rs b/infra/agents/agentd/src/main.rsnew file mode 100644index 0000000000..f328e4d9d0--- /dev/null+++ b/infra/agents/agentd/src/main.rs@@ -0,0 +1 @@+fn main() {}
infra/agents/proto/Cargo.toml
diff --git a/infra/agents/proto/Cargo.toml b/infra/agents/proto/Cargo.tomlnew file mode 100644index 0000000000..6feea2a0ac--- /dev/null+++ b/infra/agents/proto/Cargo.toml@@ -0,0 +1,9 @@+[package]+name = "proto"+version.workspace = true+edition.workspace = true+publish.workspace = true+license.workspace = true++[dependencies]+serde.workspace = true
infra/agents/proto/src/lib.rs
diff --git a/infra/agents/proto/src/lib.rs b/infra/agents/proto/src/lib.rsnew file mode 100644index 0000000000..65d5cef8a9--- /dev/null+++ b/infra/agents/proto/src/lib.rs@@ -0,0 +1,170 @@+//! Wire types for the agentd -> agent-runner HTTP API.+//!+//! agentd (trusted) calls the runner inside the builder sandbox over the+//! internal Docker network. Every route is `POST` with a JSON body except+//! `GET /v1/health` and `GET /v1/slots/{slot}/bundle`. Errors are any non-2xx+//! status with an [`ErrorBody`]. Paths in requests are relative to the slot's+//! checkout root; the runner rejects anything that resolves outside it.++use serde::{Deserialize, Serialize};++/// Default runner port inside the builder container.+pub const RUNNER_PORT: u16 = 7070;++/// Branch prefix agents work and push on.+pub const AGENT_BRANCH_PREFIX: &str = "agent/";++/// `POST /v1/slots/{slot}/prepare` — (re)create the slot checkout on a fresh+/// branch from the mirror's `main`, keeping ignored build outputs warm.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct PrepareRequest {+    /// Full branch name, must start with [`AGENT_BRANCH_PREFIX`].+    pub branch: String,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct PrepareResponse {+    /// Commit the branch was created from.+    pub base_sha: String,+}++#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum ExecKind {+    /// Short command, runs niced, no global lock.+    Shell,+    /// Build/test command, serialized behind the runner's single build slot.+    Build,+}++/// `POST /v1/slots/{slot}/exec` — run `bash -lc <command>` in the slot root+/// as the unprivileged sandbox user, in its own process group.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ExecRequest {+    pub command: String,+    pub kind: ExecKind,+    pub timeout_secs: u64,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ExecResponse {+    /// `None` when killed (timeout, cancel, preemption).+    pub exit_code: Option<i32>,+    /// Head + tail kept when output exceeds the runner's cap.+    pub stdout: String,+    pub stderr: String,+    pub truncated: bool,+    pub timed_out: bool,+    /// Killed by `/cancel` or `/v1/builds/kill`.+    pub killed: bool,+    /// Time spent waiting for the build slot (Build only).+    pub queued_ms: u64,+    pub duration_ms: u64,+}++/// `POST /v1/slots/{slot}/read`+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ReadRequest {+    pub path: String,+    /// 1-based first line; `None` = start of file.+    pub start_line: Option<usize>,+    /// Max lines to return; `None` = runner default cap.+    pub max_lines: Option<usize>,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ReadResponse {+    pub content: String,+    pub total_lines: usize,+    pub truncated: bool,+}++/// `POST /v1/slots/{slot}/write` — create or overwrite (parents created).+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct WriteRequest {+    pub path: String,+    pub content: String,+}++/// `POST /v1/slots/{slot}/edit` — replace exactly one occurrence of `old`.+/// Zero or multiple matches is a 409 with an explanatory [`ErrorBody`].+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct EditRequest {+    pub path: String,+    pub old: String,+    pub new: String,+}++/// `POST /v1/slots/{slot}/list` — one directory level; dirs end with `/`.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ListRequest {+    pub path: String,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ListResponse {+    pub entries: Vec<String>,+    pub truncated: bool,+}++/// `POST /v1/slots/{slot}/search` — ripgrep, respecting .gitignore.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct SearchRequest {+    pub pattern: String,+    /// Subdirectory to search; `None` = slot root.+    pub path: Option<String>,+    /// e.g. `*.kt`+    pub glob: Option<String>,+    pub fixed_string: bool,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct SearchResponse {+    /// `path:line:text` lines.+    pub matches: String,+    pub truncated: bool,+}++/// `POST /v1/slots/{slot}/diff` (empty body) — working tree vs branch base,+/// including untracked files.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct DiffResponse {+    pub stat: String,+    pub diff: String,+    pub truncated: bool,+}++/// `POST /v1/slots/{slot}/commit` — stage everything in the slot and commit.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct CommitRequest {+    pub message: String,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct CommitResponse {+    pub sha: String,+}++/// `GET /v1/slots/{slot}/bundle` — `application/octet-stream` git bundle of+/// `<base_sha>..<branch>` for the slot's current branch. agentd imports it+/// into the mirror (bundles are data; nothing in the sandbox's repo config is+/// ever executed by agentd).++/// `POST /v1/slots/{slot}/cancel` (empty body) — kill whatever the slot runs.+/// `POST /v1/builds/kill` (empty body) — kill the in-flight Build, if any.+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct KillResponse {+    pub killed: bool,+}++/// `GET /v1/health`+#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct HealthResponse {+    pub slots: u32,+    pub build_running: bool,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ErrorBody {+    pub error: String,+}
infra/agents/runner/Cargo.toml
diff --git a/infra/agents/runner/Cargo.toml b/infra/agents/runner/Cargo.tomlnew file mode 100644index 0000000000..8cffcdd407--- /dev/null+++ b/infra/agents/runner/Cargo.toml@@ -0,0 +1,15 @@+[package]+name = "agent-runner"+version.workspace = true+edition.workspace = true+publish.workspace = true+license.workspace = true++[[bin]]+name = "agent-runner"+path = "src/main.rs"++[dependencies]+proto.workspace = true+serde.workspace = true+serde_json.workspace = true
infra/agents/runner/src/main.rs
diff --git a/infra/agents/runner/src/main.rs b/infra/agents/runner/src/main.rsnew file mode 100644index 0000000000..f328e4d9d0--- /dev/null+++ b/infra/agents/runner/src/main.rs@@ -0,0 +1 @@+fn main() {}