Ai agents build and env

From rjmurillo/ai-agents · View interactive version

Ai agents build and env is an AI agent skill from the GitHub repository rjmurillo/ai-agents. Runbook to recreate the ai-agents dev environment from scratch and survive its traps, including the uv-pinned Python, git hooks install, MCP layer setup, contributor commands, and PEP 668. Use when you say `set up this repo`, `bootstrap the environment`, `fresh clone setup`, or you hit `ModuleNotFou

How to use this skill

Skill file

ai-agents Build and Environment Runbook

<!-- vendor-portability: contributor-facing knowledge pack for the rjmurillo/ai-agents repo itself; intentionally references upstream paths (.agents/, .claude/, scripts/, build/) because its audience is repo contributors, not plugin consumers -->

Recreate a working dev environment for this repository from a fresh clone, verify

it actually works, and avoid the traps that have cost prior contributors real

time. Audience: a zero-context mid-level engineer or Sonnet-class model. Every

command below was last verified 2026-10-31. Volatile pins are not quoted here:

env_probe.py reads them from the files that define them (see the Scripts section).

Triggers

Scope

This skill is environment setup and survival only. Adjacent problems route to

siblings:

| You want | Use instead |

|----------|-------------|

| Regenerate mirrors, run the drift gates, release | ai-agents-generation-and-release |

| Understand what counts as test evidence, run CI-equivalent gates | ai-agents-validation-and-qa |

| Full catalog of env vars, skip markers, escape hatches | ai-agents-config-catalog |

| Triage a failing hook, gate, or test | ai-agents-debugging-playbook |

Process

Phase 1: Prerequisites

The interpreter version has ONE source of truth: .python-version. Do not

hardcode versions anywhere; run env_probe.py pins or read the pin.

| Tool | Floor | Verify |

|------|-------|--------|

| uv | Must resolve the .python-version pin (old container uv builds cannot; reinstall via the astral.sh standalone installer, never uv self update, which hits GitHub API rate limits on shared egress IPs) | uv python list "$(cat .python-version)" prints a row |

| Python | Exactly the .python-version pin, installed by uv | python3 --version |

| Node.js | The NODE_MAJOR value in scripts/bootstrap-vm.sh (AGENTS.md floor says "Node LTS") | node --version |

| PowerShell | 7.5.4+ per AGENTS.md Stack. Zero .ps1 files remain (ADR-042), but 85 pytest tests in five files launch pwsh (commit 792f6febd3, 2026-11-25) | pwsh --version, then the non-interactive check below |

| gh CLI | 2.60+ per AGENTS.md Stack | gh --version |

| git, jq, curl | any recent | git --version |

pwsh installed as a .NET global tool (~/.dotnet/tools/pwsh) needs DOTNET_ROOT

in every shell, not only interactive ones. Without it the shim looks in

/usr/share/dotnet, prints You must install or update .NET, and exits 150.

Agent shells and git hooks are not interactive, so ~/.zshrc and ~/.bashrc

miss them. For zsh, put export DOTNET_ROOT="$HOME/.dotnet" in ~/.zshenv.

Check with env -u DOTNET_ROOT zsh -c 'pwsh -NoProfile -c 1'; echo $?, which must print 0.

Measured cases and the bash -c gap: docs/runbooks/local-hook-failure.md.

Container or VM setup: bash scripts/bootstrap-vm.sh automates all of the above

on Ubuntu (needs sudo; export GH_TOKEN first). It installs uv, the pinned

Python via uv python install --default, Node 22, pwsh, gh, syncs dependencies,

and installs Lefthook. Do not copy its shell implementation for new scripts;

ADR-042 requires Python for new automation.

Testing on the other OS (Windows from a Linux host, Linux from a Windows host):

follow references/cross-os-testing.md. It

covers the CI Windows leg, a Windows VM or dockurr/windows container (needs

/dev/kvm), Ubuntu on WSL, and a throwaway ubuntu:26.04 container.

Windows container images do not run on a Linux Docker host.

Manual Python install when not using the bootstrap script:

uv python install --default "$(cat .python-version)"

Phase 2: Core Install

From the repo root:

uv sync --frozen --extra dev
uv run --frozen lefthook install --reset-hooks-path
uv run --frozen lefthook check-install

What these do:

locked (--frozen never rewrites the lockfile) with dev extras. The pre-push

gate runs validation through uv run --frozen, so this .venv is the

environment a push validates against (grep -n "uv sync --frozen" scripts/bootstrap-vm.sh).

check-install verifies that the shims are active. Lefthook reads the

configuration at runtime, so editing the jobs under an already-installed hook

type needs no reinstall. Adding or removing a hook type does: with

no_auto_install: true set, the new type has no shim until install runs

again.

Phase 3: Verify the Install

Run the smoke probe. It runs lefthook version, lefthook check-install, and

pytest tests/test_paths.py --collect-only, and compares the lefthook version

to the lefthook== pin in pyproject.toml.

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-build-and-env/scripts/env_probe.py --repo . smoke; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

Exit 0 means all three passed. Exit 1 names the failing command. Exit 3 means

uv is missing. It does not check PyYAML or the interpreter: use pins for the

pin values, then uv run python -c "import yaml; print(yaml.__version__)" and

python3 --version to compare.

Phase 4: MCP Layer

.mcp.json at repo root defines two servers. Copy .env.example to .env

and fill keys (env_probe.py envfile lists the key names in .env.example). Never commit

.env (universal.md MUST 6: no secrets).

MUST NOT commit credentials, tokens, or API keys. Secrets live in environment variables or the secrets manager.

| Server | Transport | Role | When absent |

|--------|-----------|------|-------------|

| serena | stdio, uvx --from git+https://github.com/oraios/serena (port 24282, context claude-code) | Canonical memory (ADR-106) plus LSP symbol navigation | Memories stay readable as plain files under .serena/memories/ (env_probe.py pins reports the entry count). The LSP read gate that could misfire on code files was retired |

| deepwiki | http, https://mcp.deepwiki.com/mcp | External GitHub repo documentation | No local impact; fall back to web search |

Proxy and TLS note (generic, not environment-specific): the stdio server is

fetched by uvx on first launch, so a corporate proxy must allow uv's

downloads and uv must trust the proxy CA. Use standard HTTPS_PROXY plus uv's

system-certificate option (UV_SYSTEM_CERTS; the older UV_NATIVE_TLS name is

deprecated as of uv 0.11.26). Never disable TLS verification.

Phase 5: Editor and LSP Reality

This repo prefers LSP-first navigation (ADR-062, the using-serena-symbols skill's references/rule-lsp-first.md):

use Serena symbol tools over grep for code navigation. This is static steering

now, not a runtime gate. The PreToolUse LSP gate and its environment escapes

(SKIP_LSP_GATE, LSP_GATE_MODE, LSP_DOWN) were retired; no Read

call is blocked and there is nothing to set.

Known Traps

Each row verified 2026-10-31. Longer stories live with the sibling skills

ai-agents-failure-archaeology and ai-agents-debugging-playbook.

| Trap | Symptom | Fix |

|------|---------|-----|

| CONTRIBUTING.md build commands were DEAD before commit b320f4ac1 | CONTRIBUTING.md said build/Generate-Agents.ps1 PowerShell invocation until commit b320f4ac1 repointed it to build/generate_agents.py (git show b320f4ac1 -- CONTRIBUTING.md); zero .ps1 files exist in the repo (ADR-042) | Real commands: uv run python build/generate_agents.py and uv run python build/scripts/build_all.py |

| PEP 668: bare pip fails | pip install X errors with externally-managed-environment on uv-managed interpreters | Everything goes through uv: uv sync, uv add, uv run (grep -n "uv sync --frozen" scripts/bootstrap-vm.sh) |

| Skill scripts need the project venv | .claude/skills/github/scripts/pr/*.py import github_core, which imports yaml at load; bare python3 throws ModuleNotFoundError: No module named 'yaml' unless .venv/bin is first on PATH (bootstrap-vm.sh arranges that; a manual setup usually does not) | Run skill scripts with uv run python, which resolves the venv deterministically |

| Moving a worktree leaves the uv shebangs stale | Direct .venv/bin/pytest fails with "bad interpreter" after mv; the shebangs in .venv/bin/* (POSIX) or .venv/Scripts/* (Windows) still name the old worktree path | Run scripts/maintenance/repair_worktree_venv.py with uv run python (or uv sync --frozen --extra dev --reinstall: --reinstall recreates the launchers a bare --frozen sync would leave stale, --extra dev keeps pytest/ruff/mypy, --frozen matches CI); prefer uv run python -m pytest for move-safe validation. Detect without mutating: instruments.py run venv-stale-check (exit 1 means stale) |

| Two floors, not one | pyproject.toml project.requires-python says requires-python = ">=3.14" (the dev/install contract), but plugin hooks run under the host's ambient interpreter, which may be older | Develop and test against .python-version. The blocking CI syntax gate parses every file at the hook-portability floor (syntax_floor in env_probe.py pins), NOT the dev pin, so hooks stay portable to older hosts (decoupled from requires-python); see ai-agents-debugging-playbook |

| LF line endings enforced | CRLF in YAML frontmatter breaks the Copilot CLI parser (github/copilot-cli#694); .gitattributes:59 sets * text=auto eol=lf | Configure your editor for LF; never commit CRLF |

| Pre-push jobs can take minutes | Lefthook runs the named validators in lefthook.yml for matching push files | Budget minutes per push; do not attempt --no-verify (prohibited, AGENTS.md Never list) |

| Skill test location | Skill tests live in tests/skills/NAME/, never inside the skill directory | the colocated-test guard blocks test files placed inside a skill; details in ai-agents-validation-and-qa |

Verification

The 15-minute smoke checklist. All boxes checked means the environment works.

Scripts

Run these instead of counting or comparing by hand. Each is read-only.

# interpreter, lefthook, PyYAML, requires-python, Node major, syntax floor, memory entries
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-build-and-env/scripts/env_probe.py --repo . pins; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# .env present, .env tracked (exit 1), .env.example keys
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-build-and-env/scripts/env_probe.py --repo . envfile; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
# Phase 3 commands (needs uv)
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-build-and-env/scripts/env_probe.py --repo . smoke; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-build-and-env/scripts/instruments.py --repo . list; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

pins answers what the files say, not what is installed: compare with

python3 --version and node --version yourself. envfile cannot tell whether a key

value is valid. instruments.py list also links the stale-launcher check

scripts/maintenance/repair_worktree_venv.py --check, which only covers a

worktree whose .venv exists.

Anti-Patterns

predate ADR-042; the pwsh commands cannot run.

blocks it; the venv from uv sync --frozen --extra dev is the environment.

Escape hatches here get teeth or get abused (session 1187); skipping hooks is

on the AGENTS.md Never list.

YAML frontmatter parsing downstream.

degradation: fall back per the Phase 4 table and keep working.

to resolve to. Re-run uv sync --frozen --extra dev instead.

Provenance and Maintenance

Last verified 2026-10-31 at commit 42e409325. reverify.json holds the

checks for the paths and strings this skill relies on. Check drift with:

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/skill-bootstrap/scripts/bootstrap_drift.py check --repo . --skills-root .claude/skills --name ai-agents-build-and-env --require; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

| Fact | Source | Re-verify |

|------|--------|-----------|

| Interpreter, lefthook, PyYAML, requires-python, Node major, syntax floor | .python-version, pyproject.toml, scripts/bootstrap-vm.sh, scripts/validation/validate_python_syntax.py | env_probe.py pins |

| uv sync --frozen --extra dev is the canonical sync | scripts/bootstrap-vm.sh | grep -n "uv sync --frozen" scripts/bootstrap-vm.sh |

| pwsh 7.5.4+, gh 2.60+ floors | AGENTS.md Stack section | grep -n "gh2.60" AGENTS.md |

| Zero .ps1 files (ADR-042) | repo tree | git ls-files "*.ps1" prints nothing |

| build/Generate-Agents.ps1 removed in 7b8347daa | git history | reverify.json absent check |

| Stale pwsh commands (historical, fixed by commit b320f4ac1) | CONTRIBUTING.md, before b320f4ac1 | git show b320f4ac1 -- CONTRIBUTING.md |

| Git hook jobs, filters, and validators | lefthook.yml | uv run --frozen lefthook validate |

| MCP servers serena/deepwiki | .mcp.json | cat .mcp.json |

| .env key names | .env.example | env_probe.py envfile |

| LF enforcement rationale | .gitattributes | grep -n "eol=lf" .gitattributes |

| uv TLS var rename | uv 0.11.26 runtime warning | uv run python -c pass under UV_NATIVE_TLS |

Maintenance rule: if any re-verify command disagrees with this file, the repo

won. Update this skill in the same PR that changes the underlying fact. Do not

add a version to src/claude/.claude-plugin/plugin.json or

src/copilot-cli/.claude-plugin/plugin.json: the manifests carry no version

(ADR-092, see ai-agents-change-control).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.