This file gives coding assistants and contributors the project-wide rules for building Gait.
Gait is the offline-first policy-as-code runtime for AI agent tool calls. It bootstraps repo policy with gait init and gait check, captures signed evidence, and enforces fail-closed policy at the tool boundary.
Core primitives:
- Jobs: dispatch multi-step agent work with checkpoints, pause/resume/cancel, approval gates, and deterministic stop reasons (
gait job submit/status/checkpoint/pause/resume/cancel/approve/inspect) - Packs: unified portable artifact envelope (PackSpec v1) for run, job, and call evidence with Ed25519 signatures and SHA-256 manifest (
gait pack verify/diff) - Gate: evaluate structured tool-call intent against YAML policy with fail-closed enforcement (
gait gate eval) - Regress: convert incidents into deterministic CI regression fixtures with JUnit output (
gait capture,gait regress add,gait regress bootstrap) - Voice: gate high-stakes spoken commitments before utterance via signed SayToken capability tokens and callpack artifacts (
gait voice token mint/verify,gait voice pack build/verify/diff) - Context Evidence: deterministic proof of what context the model was working from, with privacy-aware envelopes and fail-closed enforcement when evidence is missing
- Doctor: first-5-minutes diagnostics (stable JSON + fixes) (
gait doctor --json)
Supporting surfaces:
- Registry: signed/pinned skill pack install + verify workflows
- MCP proxy/bridge/serve: transport-aware boundary adapters (
stdio,SSE, streamable HTTP) that route through Gate policy evaluation - Scout: local snapshot/diff/signal reporting for drift and incident clustering
The durable product contract is artifacts and schemas, not a hosted UI.
- Determinism:
verify,diff, and stub replay must be deterministic given the same artifacts. - Offline-first: core workflows must not require network access.
- Default privacy: record reference receipts by default (no raw sensitive content unless explicitly enabled).
- Fail-closed safety: in “production/high-risk” modes, inability to evaluate policy blocks execution.
- Schema stability: artifacts and
--jsonoutputs are versioned and remain backward-compatible within a major. - Stable exit codes: treat exit codes as API surface; add new codes only intentionally.
- Go is authoritative for: schemas, canonicalization, hashing, signing/verification, zip packaging, diffing, stub replay, policy evaluation, job lifecycle, voice token minting/verification, and CLI output.
- Python is an adoption layer only: capture intent, call local Go, return structured results. No policy parsing/logic in Python. Keep SDK ergonomics thin (
ToolAdapter, minimal decorators), not framework replacement. - Wrappers and sidecars are transport only: all enforce/allow/block decisions come from Go (
gait gate eval,gait mcp proxy,gait mcp serve), never framework-local logic. - Next.js docs site (
docs-site/): static export deployed to GitHub Pages. Reads markdown fromdocs/via gray-matter frontmatter. No runtime dependencies. - Node/TypeScript: limited to docs site and local UI shell (
ui/local/). Not part of the core CLI path.
Current reference adapter set (keep parity): openai_agents, langchain, autogen, openclaw, autogpt, gastown, voice_reference, and the canonical sidecar path.
- Any JSON that participates in a digest, signature, cache key, or diff MUST be canonicalized using RFC 8785 (JCS) before hashing/signing.
- Zip artifacts must be byte-stable when regenerated from identical inputs:
- deterministic file ordering
- stable timestamps (fixed epoch)
- stable file modes/ownership metadata
- explicit compression settings
- Never hash “pretty printed” JSON or platform-dependent encodings.
- Never commit secrets, tokens, private keys, or real customer data.
- Avoid logging sensitive payloads; prefer digests + redaction metadata.
- All “unsafe” operations (real tool replay, raw capture, destructive tools) require explicit flags and must be obvious in help text and JSON outputs.
- Use standard crypto primitives (ed25519, sha256) from well-reviewed libraries; no custom crypto.
- Format:
gofmtalways; keep code idiomatic and boring. - Errors: wrap with
%w; return typed sentinel errors only when they improve caller behavior. - Concurrency: keep it explicit; no background goroutines without lifecycle control.
- Time/locale: avoid locale-dependent formatting; timestamps should be RFC 3339/UTC or fixed epochs as defined by schema.
- IO: be careful with filesystem permissions; artifacts should be readable by the user but not world-writable by default.
- Keep Python “thin”: serialization, subprocess/FFI boundary, and ergonomics only.
- Prefer strict typing; keep the public wrapper API small and stable.
- Tooling targets:
uv,ruff,mypy,pytest.
- CI should run Go linting + security scans (e.g.
golangci-lint,go vet,gosec,govulncheck) and Python checks for wrapper code (ruff,mypy,bandit,pytest). - Prefer a cross-platform CI matrix (macOS/Linux/Windows) and path-filtered workflows for speed.
- Releases should produce checksums, SBOMs, and signed provenance/attestations; treat release integrity separately from runpack/trace signing.
- Keep git hooks active (
make hooks) with pre-push runningmake prepushby default (make lint-fast+make test-fast), and useGAIT_PREPUSH_MODE=full git pushfor full local gates; keep.pre-commit-config.yamlaligned with current checks if pre-commit is used locally.
cmd/gait/— CLI entry points and command wiringcore/gate/— policy evaluation, voice token minting/verificationcore/jobruntime/— durable job lifecycle (submit, checkpoint, pause, resume, cancel)core/pack/— PackSpec v1 pack/verify/diffcore/runpack/— legacy runpack capture/verify/diff/replaycore/contextproof/— context evidence envelopescore/doctor/— diagnostics and production-readiness checkscore/guard/— evidence retention, encryption, and incident pack handlingcore/regress/— regression bootstrap and executioncore/mcp/— MCP proxy/bridge/serve adapterscore/scout/— drift snapshots, operational/adoption events, and signal reportsschemas/v1/— JSON schemas for all artifact typessdk/python/— Python wrapper SDKdocs/— markdown docs (consumed by docs-site via gray-matter)docs-site/— Next.js static docs siteexamples/integrations/— reference adapters (voice, langchain, openai, etc.)
- CLI behavior and flag contracts:
cmd/gait/*usage/help text and command tests incmd/gait/*_test.go. - Artifact schemas and compatibility rules:
schemas/*,core/*validators, and contract tests. - Acceptance/UAT coverage scope:
docs/uat_functional_plan.mdandscripts/test_*acceptance*.sh. - If docs and code disagree, treat code/tests as source of truth and patch docs in the same change.
- Prefer table-driven tests and golden fixtures for:
--jsonoutput stability- exit codes
- schema validation and migrations
- JCS canonicalization and digest stability
- zip determinism (same inputs => same bytes)
- policy evaluation determinism
- Maintain deterministic integration/e2e/acceptance suites for adapters, policy compliance, hardening, and release smoke paths.
- Keep coverage gates at >= 85% for Go core/CLI and Python SDK in CI.
- Tests must be offline and hermetic by default (no network, no cloud accounts).
- Behavior regressions: any change to
verify,diff,replay,regress, orgate evaloutput must not break existing golden fixtures or exit code contracts. Runmake test-fastat minimum before pushing. - Safety / fail-closed controls: never weaken a non-allow → non-execute path. If gate evaluation cannot reach a verdict, the default must remain block. Same for voice (no SayToken → no gated speech) and context evidence (missing envelope → fail-closed for high-risk actions).
- Determinism: changes to JSON serialization, zip packaging, hashing, or signing must preserve byte-for-byte reproducibility. Test with existing fixtures, not just new ones.
- CI / portability: CI templates live in
.github/workflows/and must work across Go versions declared ingo.mod. Don't add platform-specific paths or hardcoded tool versions without matrix coverage. - Docs vs CLI drift: if you change a command's flags, arguments, or exit codes, update
docs/,docs-site/public/llms.txt,docs-site/public/llm/*.md, andREADME.mdin the same change. Treatcmd/gait/*usage strings as the source of truth. - Test artifact leaks: tests that create artifacts (packs, tokens, journals) must use
t.TempDir()or equivalent. Never write test output to the source tree. - Shell quoting in PRs: when using
gh pr create --body, backticks and$()in the body text get interpreted by the shell. Use a<<'EOF'heredoc (single-quoted delimiter) to pass the body safely. Same applies to commit messages containing backticks.
- Keep dependencies minimal, especially in core (
cmd/gaitandcore/*). - Avoid adding dashboards/services in v1; keep scope on the execution path.
- When introducing a new artifact/schema:
- version it explicitly
- add validation + golden fixtures
- document upgrade/migration behavior
This repo may use bd (beads) for local, personal task tracking. It is not required for contributors.
- If
bdis available, use it to find and track work:bd ready(unblocked work)bd show <id>/bd listbd create "Title" --type task --priority 2bd dep add <blocked_id> <blocker_id>(dependencies)bd close <id>
- For up-to-date workflow context:
bd prime - Note: bd may be configured in stealth mode (local
.beads/state excluded from git). Do not commit beads artifacts unless explicitly requested.
- Keep these instructions short, concrete, and current.
- If a subdirectory needs specialized rules, add another
AGENTS.mdthere (it scopes to that subtree).