Skip to content

Latest commit

 

History

History
210 lines (162 loc) · 8.07 KB

AGENTS.md

File metadata and controls

210 lines (162 loc) · 8.07 KB

AGENTS.md

Guidance for AI coding agents working in this repository.

Overview

lab is a personal R&D monorepo: learning projects, libraries, experiments, infrastructure configuration, and dotfiles. The host OS is FreeBSD; Linux-only tooling runs inside jails.

Boundaries

  • Stay inside the project.
  • Do not read, create, modify, or delete files outside the repository root.
  • This includes user dotfiles, system configuration, and other repositories.
  • If a task seems to require it, stop and ask first.

Architecture

Path Contents
book/ Ideas and exercises from books (algos, irex, ostep)
check/ pre-commit check scripts and tools
dp/ Design patterns (errors, graph, proto)
go/ Reusable Go libraries (flags, slices)
iq/ Interview questions, one numbered directory per question
x/ Experimental area: tools, servers, games, wasm, and so on
infra/ Infrastructure configuration and docs (bastion, dns, ldap, ...)
ansible/ Playbooks, roles, and plugins that provision the lab and jails
ports/ FreeBSD ports
home/ Dotfiles and user environment (installed with make)
nvim/ Neovim config and plugins, including the lab-skeleton templates
third_party/, toolchain/ Bazel external deps and toolchain config

Build systems:

  • Go: single module github.com/skhal/lab (go.mod at the root).
  • C++: Bazel (bzlmod, MODULE.bazel), C++20, built with -Wall -Wextra -Werror. BUILD files are generated by Gazelle.
  • Python (Poetry), Lua, and shell appear in smaller places.

Each top-level package has its own CI workflow in .github/workflows/, which runs on changes under that path.

Common commands

Go

% go build ./...
% go test ./...

Bazel

% bazel run :gazelle         # regenerate BUILD files
% bazel test //...
% ./refresh_commands         # gazelle + compile_commands.json

Python

Each Python project has its own pyproject.toml and Poetry environment, such as ansible/ and poetry/plugin/patch. The root pyproject.toml holds only the repository-wide Ruff config and the lint group for CI.

make -C home bootstraps the environment of every project with a pyproject.toml, only when it does not exist yet. Later updates are manual: run poetry sync in the project after its poetry.lock changes, then poetry patch in projects with [[tool.poetry-plugin-patch.spec]], such as ansible/, to re-apply the patches:

% cd ansible
% poetry sync
% poetry patch

Ansible

Python dependencies (ansible-core, pytest) are managed by Poetry from ansible/pyproject.toml, separate from the root pyproject.toml. Run the tests from a project or collection folder with a pytest.ini, for example:

% cd ansible/lab
% poetry run pytest

Or activate the environment first: eval $(poetry -C ansible env activate).

Ansible collections (requirements.yml in each project, such as ansible/lab/requirements.yml) are not on PyPI. ansible-galaxy from the ansible/ environment installs them into the project's .collections folder. make -C home does it after bootstrapping the environment, or by hand:

% cd ansible/lab
% poetry run ansible-galaxy collection install \
    -r requirements.yml -p .collections

The lab.* collections under ansible/collections install the dependencies from their galaxy.yml into their own .collections folder, see the collection ansible.cfg. make -C home does it too. Run ansible-lint from the project or collection folder.

pre-commit

% pre-commit run --files <paths>

Code generation instructions

  • Start from the skeletons. New files are created from templates in nvim/plugin/lab-skeleton/share/new.* (new.go, new.cc, new.h, new.bzl, ...). Copy their structure rather than inventing a new one.

  • License header. Every source file starts with:

    Copyright 2026 Samvel Khalatyan. All rights reserved.
    
    Use of this source code is governed by a BSD-style
    license that can be found in the LICENSE file.
    

    Use the file's own comment syntax. check/cmd/check-license enforces it.

  • Go

    • Every package has a doc.go with a package comment.
    • Every exported entity has a doc comment (enforced by check-godoc).
    • Tests live in the external package (package foo_test) next to the code, use table-driven tests, and compare with go-cmp.
    • Format with goimports. Keep structs field-aligned (fieldalignment). Code must pass go vet, staticcheck, and go fix.
    • Do not edit generated *.pb.go files.
  • C++: Google style (.clang-format), clean under clang-tidy. Add tests with the code. Run Gazelle after adding or moving files.

  • Protobuf: documented messages and fields (check-pbdoc), and field numbers must be unique (check-nextid).

  • Text protos (*.txtpb): always include the proto-file (schema) and proto-message (message type) comments right after the license header. The message is fully qualified by its proto package. Example from infra/cmd/certval/config.txtpb:

    # proto-file: github.com/skhal/lab/infra/cmd/certval/pb/config.proto
    # proto-message: infra.cmd.certval.Config
    
    slack {
      # webhook is the application webhook from api.slack.com
      webhook: "https://hooks.slack.com/services/example"
    }
    

    Comment fields to explain their purpose. Format with txtpbfmt.

  • Bazel: format and lint with buildifier.

  • Shell: write scripts in POSIX sh(1), not bash(1). Use #!/bin/sh, avoid bashisms (arrays, [[ ]], process substitution), and format with shfmt. Shell executables have no file extension. Run project scripts with sh, not bash.

  • Markdown, YAML, JSON, TOML, Lua, Python: use the repo formatters (markdownfmt, yamlfmt, prettier, tombi, stylua, ruff).

  • Sorted lists. Respect keep-sorted blocks.

  • No NOSUBMIT markers, binary files, or untracked-issue TODOs (checked by check-nosubmit, check-todo, check-issue).

  • Spelling. typos runs on all files; see _typos.toml.

  • Prefer small, focused changes and add tests with new behavior.

Shell commands

The agent's Bash tool can only run bash or zsh, so it cannot be switched to sh(1). Stay portable anyway:

  • Write every command in POSIX sh(1) syntax: no arrays, [[ ]], {a,b} brace expansion, process substitution, or $'...' quoting.
  • Run scripts explicitly with sh script, never bash script.
  • Use sh -c '...' only when a snippet needs sh semantics; do not wrap ordinary commands in it, because that bypasses the permission rules in .claude/settings.json.

Checks

Formatting and linting run through pre-commit (.pre-commit-config.yaml). Run pre-commit run --files <changed files> before committing and fix what it reports instead of bypassing hooks.

Commit messages

Short, imperative, prefixed by the area changed, for example ansible: create pkgbuild jail or roles/jail: update jail config params.

Always show the draft commit message to the user for review before committing. Commit only after they approve it.

Style

  • Directory naming: follow style/hier.md when creating, renaming or moving directories.
  • Python: follow style/python.md when writing Python code or creating Python projects.