agentrail is a Windows-focused execution adapter for AI coding agents.
It provides:
- one self-contained Go binary
- JSON-only stdout
- workspace-aware filesystem controls
- deterministic file and search operations
- direct-argv process execution with no shell parsing
- a normative protocol spec in
PROTOCOL.md
agentrail search <query>agentrail filesagentrail schema <target>agentrail read <path>agentrail write <path>agentrail build-patch <path>agentrail replace <path>agentrail patchagentrail exec -- <argv...>
Global flags:
--jsonforce JSON request mode--allow-outside-workspaceopt-in outside-workspace access forread,search, andfiles
Workspace root is resolved from:
CODEX_TOOL_WORKSPACEif set- otherwise the current working directory
Safety rules:
- deny
.gitandnode_modules - deny Windows system directories unless they are the workspace root
- keep
write,patch,replace, andexec.cwdinside workspace - default
read,search, andfilesto workspace-only access
Every response is a single JSON object and includes:
okactionprotocol_versiontool_versioncapabilities
Read the full normative contract in PROTOCOL.md.
Use agentrail schema <target> or {"action":"schema","target":"<target>"} in JSON mode to inspect the live request contract for patch, build_patch, or replace.
{
"ok": true,
"action": "read",
"protocol_version": 1,
"tool_version": "0.0.0-dev+0000000",
"capabilities": ["build_patch","exec","exec_output_budget","exec_process_tree_kill","files","files_pagination","patch","patch_atomic","patch_expected_file_tokens","read","read_file_token","replace","schema","search","write"],
"path": "src/main.go",
"file_token": "sha256:...",
"content": "...",
"start_line": 1,
"end_line": 80,
"truncated": true,
"has_more": true,
"next_start_line": 81
}{
"ok": true,
"action": "patch",
"repository_state": "changed",
"files_changed": ["src/main.go"],
"hunks_applied": 1,
"results": [
{"path":"src/main.go","ok":true,"changed":true,"hunks_applied":1}
]
}{
"ok": true,
"action": "exec",
"exit_code": 0,
"stdout": "...",
"stderr": "",
"stdout_truncated": false,
"stderr_truncated": false,
"output_bytes": 1842,
"timing_ms": 31
}List files:
agentrail filesPaginated file enumeration:
printf '{"action":"files","limit":200}' | agentrail --jsonSearch:
agentrail search "TODO"Read:
printf '{"action":"read","path":"README.md","start_line":1,"max_bytes":4096}' | agentrail --jsonPatch atomically with file tokens:
printf '{"action":"patch","atomic":true,"expected_file_tokens":{"src/main.go":"sha256:..."},"diff":"--- a/src/main.go\n+++ b/src/main.go\n@@ -1,1 +1,1 @@\n-old\n+new\n"}' | agentrail --jsonBuild a single-file patch from desired content:
printf '{"action":"build_patch","path":"src/main.go","content":"package main\n"}' | agentrail --jsonReplace a single file from desired content:
printf '{"action":"replace","path":"src/main.go","content":"package main\n"}' | agentrail --jsonPatch contract schema:
printf '{"action":"schema","target":"patch"}' | agentrail --jsonNotes:
- The JSON patch endpoint accepts unified diff text in
diffonly. - The diff must include
---and+++file headers before any@@hunks. - Prefer
replacefor safe single-file full-content edits andbuild_patchwhen you want AgentRail to generate the unified diff. - Fields like
mode,patch,old_string, andnew_stringare not part of the CLI JSON contract.
Exec:
agentrail exec -- go test ./...Windows single-binary build:
set CGO_ENABLED=0
set GOOS=windows
set GOARCH=amd64
go build -trimpath -ldflags "-s -w -buildid=" -o bin/agentrail.exe ./cmdNotes:
CGO_ENABLED=0yields a self-contained.exewith no external runtime executable dependencies.- The Windows build guarantees
exec_process_tree_killvia Job Object semantics and advertises that capability accordingly.
go test ./...Coverage includes:
- request parsing and envelope fields
- path traversal and deny rules
- file pagination and cursor errors
- paged reads and file tokens
- patch token checks, no-op behavior, and atomic validation
- generated single-file patch building and replace flows
- exec argv-only execution, timeout handling, and output-budget truncation
MIT. See LICENSE.