The Problem
Conversational AI coding workflows accelerate initial prototyping across tools like Claude Code, OpenAI Codex, Cursor, Google Antigravity, and OpenCode, yet rapid generation frequently breaks engineering discipline in four ways:
- Silent Scope Drift: agents add unrequested payment gateways, libraries, or refactors mid-sprint without surfacing schedule or complexity trade-offs.
- Session Amnesia: switching between IDE assistants resets architectural context, approved constraints, and active blockers.
- Unverified "Done" Claims: models declare tasks finished without executing checks or linking recorded command output.
- Backlog Sprawl: speculative checklists hide the single next deliverable slice inside the active milestone.
The goal of AgentGuardrail is to place a deterministic, local-first project workflow guardrail between the developer and coding assistants via a terminal CLI (agent-guard), an official stdio Model Context Protocol (MCP) server, and portable Agent Skills backed by human-readable JSON files in .agentguardrail/.
My Role & Constraints
I designed and implemented the entire pnpm monorepo (@agent-guardrail/core, @agent-guardrail/cli, and @agent-guardrail/mcp-server) on Node.js 22.14+, TypeScript 6.0, Zod v4, Biome, and the official MCP TypeScript SDK v2 (@modelcontextprotocol/server), published ready for zero-clone npx execution with GitHub Release v0.1.0 bundles.
Key design constraints:
- Local-first transparency with zero network surface: all project state (brief, scope, milestones, tasks, append-only decisions, verification evidence, scope proposals, and session handoffs) lives as Git-friendly JSON/Markdown files under
.agentguardrail/. Static security tests confirmsrc/contains zero HTTP clients orchild_processcalls. - Token-efficient MCP surface & honest scope boundary: the MCP server consolidates operations into 6 action-grouped tools (
guardrail_read,guardrail_project,guardrail_plan,guardrail_scope_guard,guardrail_verify,guardrail_handoff) to conserve LLM context-window budget when paired with other MCP servers. MCP governs structured workflow state and verification proof rather than acting as an OS sandbox; preventing arbitrary file edits or shell commands outside AgentGuardrail intentionally stays with each host IDE's native permissions. - Zero duplicated adapter logic: all five platform adapters (
adapters/antigravity,opencode,claude-code,codex,cursor) configurenpx -y @agent-guardrail/mcp-serverand synchronize canonicalskills/viascripts/skills.mjs.
Key Decisions
1. Deterministic scope proposals & dependency-checked next actions
Instead of relying on system prompt reminders to stop feature creep, ScopeGuard blocks direct mutations to approved MVP boundaries. When an out-of-scope addition arises, the agent must submit a formal SCOPE-* proposal capturing reason, value, complexity, risk, and schedule impact, leaving approval (approved, rejected, or deferred) strictly gated behind human confirmation (APPROVAL_REQUIRED). Meanwhile, the Next Action Engine computes the single highest-priority ready slice while rejecting circular task dependencies (DEPENDENCY_CYCLE).
Scope proposal gates and proof-gated task completion
Every scope shift and task completion is validated in Node.js + Zod v4 instead of prompt trust.
Compass & Scope Guard
Locks approved brief and non-goals; mid-sprint additions require a SCOPE-* impact proposal.
Next Action & Graph
Selects one ready slice inside the active milestone while catching dependency cycles.
Verification Gate
Distinguishes host_observed (exit code), human_confirmed, and agent_reported evidence.
Cross-Agent Handoff
Writes HANDOFF-* snapshot (files changed, decisions, blockers, next step) into .agentguardrail/.
03 -> 02: VERIFICATION_REQUIRED (Missing Proof Guard)
Blocks premature completion when required criteria stay unsatisfied or only agent_reported proof exists under --require-trusted.
2. Provenance-aware verification gates (host_observed, human_confirmed, agent_reported)
To stop models from hallucinating passing test runs, VerificationService enforces two gates before a task can move to done: every required acceptance criterion must be marked satisfied, and passing verification evidence must be linked. Crucially, the engine tracks verification provenance explicitly (host_observed requiring an integer exit_code, human_confirmed, or agent_reported), allowing strict workflows (--require-trusted / require_trusted) to reject agent_reported_only claims with VerificationRequiredError (VERIFICATION_REQUIRED).
Separating
agent_reportedsummaries fromhost_observedexit-code records makes verification honesty enforceable at the domain layer instead of hoping an agent tells the truth.
3. Crash-safe concurrency locking, symlink jails, and .backups/ quarantine
Parallel terminal sessions or multi-agent workers writing to .agentguardrail/ can trigger file races or corrupt JSON edits. The storage layer pairs in-process mutex serialization with an exclusive .write.lock file containing PID liveness checks (automatically evicting stale locks from crashed processes), atomic temp-file renames, optimistic revision checks (REVISION_CONFLICT), symlink-escape prevention across root/collection/leaf paths (PATH_OUTSIDE_PROJECT), and automatic .backups/ snapshots reported through agent-guard doctor.
Deterministic core shared across 5 AI coding hosts and terminal CLI
6 consolidated MCP tools and agent-guard CLI commands route through one atomic filesystem store.
@agent-guardrail/mcp-server (6 Cohesive Tools · 4 Resources · 3 Prompts) + CLI
Serves Antigravity, OpenCode, Claude Code, Codex, and Cursor over stdio JSON-RPC plus agent-guard CLI.
.write.lock + REVISION_CONFLICT
Exclusive file lock with stale-PID eviction plus optimistic revision checks stop silent overwrites.
Symlink & Traversal Jail
Validates root, collection folder, and leaf files against symlink escapes (PATH_OUTSIDE_PROJECT).
.agentguardrail/ + .backups/
Quarantines corrupt JSON into .backups/, normalizes cross-platform paths, and reports via doctor.
4. Structured cross-agent handoffs & canonical skill synchronization
Switching from one AI coding environment to another no longer requires re-reading long chat transcripts. Creating a HANDOFF-* record saves the completed work summary, changed file list, architectural decisions, active blockers, and exact next action directly inside .agentguardrail/sessions/. Four canonical Markdown skills (project-kickoff, scope-change-review, stay-on-track, verify-and-handoff) stay synchronized across all five target adapters via pnpm skills:sync and pnpm skills:check.
The Build
Verification provenance and trust enforcement are implemented directly inside @agent-guardrail/core (packages/core/src/services/verification-service.ts and errors.ts):
// Verified provenance gate in @agent-guardrail/core
export type VerificationTrustLevel =
| "host_observed"
| "human_confirmed"
| "agent_reported_only"
| "unverified";
export async function assertTaskVerifiable(
task: Task,
summary: VerificationSummary,
options: { requireTrusted?: boolean } = {},
) {
const required = task.acceptance_criteria.filter((c) => c.required);
if (required.some((c) => c.status !== "satisfied")) {
throw new VerificationRequiredError("Required acceptance criteria are not all satisfied.");
}
if (summary.passing_records === 0) {
throw new VerificationRequiredError("No passing or human-confirmed verification evidence is recorded.");
}
if (options.requireTrusted && summary.trust_level === "agent_reported_only") {
throw new VerificationRequiredError(
"Trusted verification required: provide host_observed (with exit_code) or human_confirmed verification.",
);
}
}# Full local verification pipeline
pnpm lint && pnpm skills:check && pnpm typecheck && pnpm test && pnpm buildOutcome
- Delivered a token-efficient 6-tool MCP contract (
guardrail_read,guardrail_project,guardrail_plan,guardrail_scope_guard,guardrail_verify,guardrail_handoff), 4guardrail://resources, and 3 workflow prompts overstdioJSON-RPC alongsidenpx @agent-guardrail/cliand 4 portable skills inv0.1.0. - Verified 34 automated Vitest tests across 5 test suites (
store.test.ts10 tests,phase1.test.ts12 tests,cli.test.ts4 tests,stdio.test.ts3 full stdio session tests across all 5 adapter configs, andrelease.test.ts5 skill-sync/security/pack tests),pnpm verify:release, and green GitHub Actions CI acrossubuntu-latest,macos-latest, andwindows-latest. - Validated platform packaging honestly (
2026-11-26): Google Antigravity passedagy plugin validate adapters/antigravity --strict --json(agy 1.5.18, 0 errors/warnings); OpenCode verifiedmcp.serversschema viaopencode mcp add(v2.2.5); Claude Code, OpenAI Codex, and Cursor JSON/TOML manifests and canonical skills verified in automated checks (native client binaries absent on build host).
Reflection
Building AgentGuardrail made one distinction permanently clear: soft prompt instructions fail whenever a coding session grows noisy, whereas small deterministic state machines (SCOPE-* approvals, REVISION_CONFLICT guards, and host_observed verification provenance) give both developers and AI agents a reliable contract without adding database or cloud overhead.



