ai-agent-utils 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_agent_utils-0.4.0/.env.example +5 -0
- ai_agent_utils-0.4.0/.githooks/pre-commit +19 -0
- ai_agent_utils-0.4.0/.githooks/pre-push +56 -0
- ai_agent_utils-0.4.0/.github/workflows/ci.yml +60 -0
- ai_agent_utils-0.4.0/.github/workflows/release.yml +46 -0
- ai_agent_utils-0.4.0/.gitignore +20 -0
- ai_agent_utils-0.4.0/.gitleaks.toml +20 -0
- ai_agent_utils-0.4.0/.pre-commit-config.yaml +53 -0
- ai_agent_utils-0.4.0/AGENTS.md +215 -0
- ai_agent_utils-0.4.0/GATES.md +306 -0
- ai_agent_utils-0.4.0/LICENSE +194 -0
- ai_agent_utils-0.4.0/PKG-INFO +328 -0
- ai_agent_utils-0.4.0/README.md +112 -0
- ai_agent_utils-0.4.0/assets/gates-architecture.svg +212 -0
- ai_agent_utils-0.4.0/init-agent-project.sh +993 -0
- ai_agent_utils-0.4.0/pyproject.toml +65 -0
- ai_agent_utils-0.4.0/ruff.toml +31 -0
- ai_agent_utils-0.4.0/src/ai_agent_utils/__init__.py +11 -0
- ai_agent_utils-0.4.0/src/ai_agent_utils/__main__.py +7 -0
- ai_agent_utils-0.4.0/src/ai_agent_utils/cli.py +43 -0
- ai_agent_utils-0.4.0/templates/README.md +113 -0
- ai_agent_utils-0.4.0/templates/gates/FACTS.yaml +51 -0
- ai_agent_utils-0.4.0/templates/gates/RETIRED +19 -0
- ai_agent_utils-0.4.0/templates/gates/VERSION +1 -0
- ai_agent_utils-0.4.0/templates/gates/_baseline.py +95 -0
- ai_agent_utils-0.4.0/templates/gates/_config.py +86 -0
- ai_agent_utils-0.4.0/templates/gates/check_publish_contract.py +368 -0
- ai_agent_utils-0.4.0/templates/gates/check_script_standards.py +178 -0
- ai_agent_utils-0.4.0/templates/gates/check_version.py +56 -0
- ai_agent_utils-0.4.0/templates/gates/check_wheel.py +108 -0
- ai_agent_utils-0.4.0/templates/gates/gates_report.sh +49 -0
- ai_agent_utils-0.4.0/templates/gates/no_hardcoding.py +156 -0
- ai_agent_utils-0.4.0/templates/gates/no_orphans.py +212 -0
- ai_agent_utils-0.4.0/templates/gates/publish_contract.toml +158 -0
- ai_agent_utils-0.4.0/templates/gates/scan.py +102 -0
- ai_agent_utils-0.4.0/templates/gates/scratch_external.py +184 -0
- ai_agent_utils-0.4.0/templates/gates/survey.sh +43 -0
- ai_agent_utils-0.4.0/templates/gates/tests/prove_gates.sh +710 -0
- ai_agent_utils-0.4.0/templates/gates/verify.py +99 -0
- ai_agent_utils-0.4.0/templates/gitleaks.toml +20 -0
- ai_agent_utils-0.4.0/templates/install_gates.sh +226 -0
- ai_agent_utils-0.4.0/templates/migrate_scratch.sh +153 -0
- ai_agent_utils-0.4.0/templates/pre-commit-config.yaml +57 -0
- ai_agent_utils-0.4.0/templates/promote_gate.sh +139 -0
- ai_agent_utils-0.4.0/templates/ruff.toml +31 -0
- ai_agent_utils-0.4.0/templates/set_branch_protection.sh +75 -0
- ai_agent_utils-0.4.0/templates/update_gates.sh +148 -0
- ai_agent_utils-0.4.0/tests/check_protection_call.py +157 -0
- ai_agent_utils-0.4.0/tests/check_registry.py +128 -0
- ai_agent_utils-0.4.0/tests/ci_checks.sh +209 -0
- ai_agent_utils-0.4.0/tests/test_cli_wheel.py +96 -0
- ai_agent_utils-0.4.0/uv.lock +79 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Run the checks declared in .pre-commit-config.yaml.
|
|
3
|
+
#
|
|
4
|
+
# Invoked from .githooks/pre-commit because core.hooksPath points here and git
|
|
5
|
+
# ignores .git/hooks while it does. If the config is present, the runner must
|
|
6
|
+
# be too: not running a declared check is not a pass (exit 3).
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
CONFIG="$(git rev-parse --show-toplevel)/.pre-commit-config.yaml"
|
|
10
|
+
if [ -f "$CONFIG" ]; then
|
|
11
|
+
if command -v pre-commit >/dev/null 2>&1; then
|
|
12
|
+
pre-commit run --hook-stage pre-commit || exit 1
|
|
13
|
+
else
|
|
14
|
+
echo " -> .pre-commit-config.yaml is present but pre-commit is not installed." >&2
|
|
15
|
+
echo " Run: uv tool install pre-commit" >&2
|
|
16
|
+
echo " Not running a declared check is not a pass." >&2
|
|
17
|
+
exit 3
|
|
18
|
+
fi
|
|
19
|
+
fi
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Refuse a dirty tree, and refuse a failing or unrunnable test suite.
|
|
3
|
+
#
|
|
4
|
+
# POSIX sh: git invokes this directly, so it must not depend on a shell or an
|
|
5
|
+
# environment being present.
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
echo "Running pre-push checks..."
|
|
9
|
+
|
|
10
|
+
# A dirty tree means what is pushed is not what was tested.
|
|
11
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
12
|
+
echo "Push aborted: the working tree has uncommitted or untracked changes." >&2
|
|
13
|
+
echo " Commit or set them aside first; otherwise what is pushed is not" >&2
|
|
14
|
+
echo " what was tested." >&2
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# The project's own interpreter first, so the suite runs against the
|
|
19
|
+
# environment it was written for rather than whatever is on PATH.
|
|
20
|
+
if [ -x .venv/bin/python ]; then
|
|
21
|
+
PY=.venv/bin/python
|
|
22
|
+
else
|
|
23
|
+
PY="$(command -v python3 || true)"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
if [ -z "$PY" ]; then
|
|
27
|
+
echo "Push aborted: no python3 and no .venv to run the test suite with." >&2
|
|
28
|
+
echo " A suite that could not run has not passed." >&2
|
|
29
|
+
exit 3
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
if [ -d tests ]; then
|
|
33
|
+
if ! "$PY" -c "import pytest" >/dev/null 2>&1; then
|
|
34
|
+
echo "Push aborted: tests/ exists but pytest is not installed for $PY." >&2
|
|
35
|
+
echo " Run: $PY -m pip install pytest" >&2
|
|
36
|
+
echo " A suite that could not run has not passed." >&2
|
|
37
|
+
exit 3
|
|
38
|
+
fi
|
|
39
|
+
echo "Running the test suite..."
|
|
40
|
+
# Exit 5 is "nothing was collected", which is a legitimate state for a
|
|
41
|
+
# repository whose suite is elsewhere. Any other non-zero code is a failure.
|
|
42
|
+
set +e
|
|
43
|
+
"$PY" -m pytest tests/ -q
|
|
44
|
+
rc=$?
|
|
45
|
+
set -e
|
|
46
|
+
[ "$rc" -eq 0 ] || [ "$rc" -eq 5 ] || exit "$rc"
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# The generator checks are this repository's real suite: they seed throwaway
|
|
50
|
+
# projects and assert what the seed produced.
|
|
51
|
+
if [ -f tests/ci_checks.sh ]; then
|
|
52
|
+
echo "Running generator self-tests (~20s: seeds throwaway repos & proves gates; ai-agent-utils only, not in seeded projects)..."
|
|
53
|
+
sh tests/ci_checks.sh >/dev/null
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
echo "Pre-push checks passed."
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
schedule:
|
|
7
|
+
# Weekly Monday 12:00 UTC: re-audits dependencies & refreshes live posture badge
|
|
8
|
+
- cron: "0 12 * * 1"
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test: # this job name is the required status-check context
|
|
15
|
+
runs-on: ubuntu-26.04
|
|
16
|
+
permissions:
|
|
17
|
+
contents: write
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
|
|
20
|
+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
- name: Cache pre-commit environments
|
|
24
|
+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
25
|
+
with:
|
|
26
|
+
path: ~/.cache/pre-commit
|
|
27
|
+
key: pre-commit-${{ runner.os }}-py3.12-${{ hashFiles('.pre-commit-config.yaml', 'templates/pre-commit-config.yaml') }}
|
|
28
|
+
# A seeded project declares pre-commit and its hook refuses to pass
|
|
29
|
+
# without it, so the runner is a real dependency of the seed and
|
|
30
|
+
# therefore of this job.
|
|
31
|
+
- name: Install pre-commit
|
|
32
|
+
run: uv tool install pre-commit
|
|
33
|
+
- name: Run declared pre-commit checks, pytest, and Level-4 security audit
|
|
34
|
+
run: |
|
|
35
|
+
pre-commit run --all-files
|
|
36
|
+
uv sync --frozen
|
|
37
|
+
.venv/bin/pytest tests/ -q
|
|
38
|
+
uvx ai-sec-gate check . --prove --with-deps-audit --min-level 4 --badge /tmp/sec-posture.json
|
|
39
|
+
rm -rf .venv
|
|
40
|
+
- name: Publish live security posture badge to badges branch
|
|
41
|
+
if: always() && github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule')
|
|
42
|
+
run: |
|
|
43
|
+
[ -f /tmp/sec-posture.json ] || exit 0
|
|
44
|
+
REMOTE_URL="$(git config --get remote.origin.url)"
|
|
45
|
+
AUTH_HEADER="$(git config --get http.https://github.com/.extraheader || true)"
|
|
46
|
+
BADGE_TMP="$(mktemp -d)"
|
|
47
|
+
cp /tmp/sec-posture.json "$BADGE_TMP/sec-posture.json"
|
|
48
|
+
git -C "$BADGE_TMP" init -q -b badges
|
|
49
|
+
git -C "$BADGE_TMP" config user.name "github-actions[bot]"
|
|
50
|
+
git -C "$BADGE_TMP" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
51
|
+
[ -n "$AUTH_HEADER" ] && git -C "$BADGE_TMP" config http.https://github.com/.extraheader "$AUTH_HEADER"
|
|
52
|
+
git -C "$BADGE_TMP" add sec-posture.json
|
|
53
|
+
git -C "$BADGE_TMP" commit -q -m "chore: update live security posture badge"
|
|
54
|
+
git -C "$BADGE_TMP" push -f "$REMOTE_URL" badges:refs/heads/badges
|
|
55
|
+
rm -rf "$BADGE_TMP"
|
|
56
|
+
- name: Run generator checks
|
|
57
|
+
run: |
|
|
58
|
+
git config --global user.email "ci@localhost"
|
|
59
|
+
git config --global user.name "ci"
|
|
60
|
+
bash tests/ci_checks.sh
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
pypi:
|
|
11
|
+
runs-on: ubuntu-26.04
|
|
12
|
+
environment: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
id-token: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
|
|
18
|
+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
|
|
19
|
+
|
|
20
|
+
- name: Verify release tag matches pyproject.toml version
|
|
21
|
+
env:
|
|
22
|
+
RELEASE_TAG: ${{ github.ref_name }}
|
|
23
|
+
run: |
|
|
24
|
+
python3 - <<'PY'
|
|
25
|
+
import os, sys, tomllib
|
|
26
|
+
tag_ver = os.environ["RELEASE_TAG"].removeprefix("v")
|
|
27
|
+
with open("pyproject.toml", "rb") as f:
|
|
28
|
+
pkg_ver = tomllib.load(f)["project"]["version"]
|
|
29
|
+
if tag_ver != pkg_ver:
|
|
30
|
+
sys.exit(f"Release tag ({tag_ver!r}) disagrees with pyproject.toml version ({pkg_ver!r})")
|
|
31
|
+
print(f"Verified tag matches pyproject.toml version: {pkg_ver}")
|
|
32
|
+
PY
|
|
33
|
+
|
|
34
|
+
- name: Build sdist and wheel
|
|
35
|
+
run: uv build
|
|
36
|
+
|
|
37
|
+
- name: Verify built wheel hygiene and smoke-install
|
|
38
|
+
run: |
|
|
39
|
+
python3 templates/gates/check_wheel.py dist/*.whl
|
|
40
|
+
uv venv /tmp/smoke-venv
|
|
41
|
+
uv pip install --python /tmp/smoke-venv/bin/python --no-index --find-links dist ai-agent-utils
|
|
42
|
+
/tmp/smoke-venv/bin/init-agent-project --version
|
|
43
|
+
/tmp/smoke-venv/bin/init-agent-project --help >/dev/null
|
|
44
|
+
|
|
45
|
+
- name: Publish to PyPI via OIDC Trusted Publishing
|
|
46
|
+
run: uv publish --trusted-publishing always
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Scratch and temporary work
|
|
2
|
+
/scratch/
|
|
3
|
+
scratch/
|
|
4
|
+
*.png
|
|
5
|
+
|
|
6
|
+
# Python
|
|
7
|
+
.venv/
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.pyc
|
|
10
|
+
*.egg-info/
|
|
11
|
+
dist/
|
|
12
|
+
build/
|
|
13
|
+
|
|
14
|
+
# Environment and personal editor state
|
|
15
|
+
.env
|
|
16
|
+
.vscode/
|
|
17
|
+
.DS_Store
|
|
18
|
+
|
|
19
|
+
# Local notes: a symlink outside the worktree. See .gates/scratch_external.py
|
|
20
|
+
scratch
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# gitleaks configuration, installed as .gitleaks.toml.
|
|
2
|
+
#
|
|
3
|
+
# gitleaks' built-in rules cover credentials: API keys, tokens, private keys.
|
|
4
|
+
# The one rule added here covers a home-directory path, which ties a file to
|
|
5
|
+
# one machine and names the account it came from.
|
|
6
|
+
|
|
7
|
+
title = "gitleaks defaults plus home-directory paths"
|
|
8
|
+
|
|
9
|
+
[extend]
|
|
10
|
+
useDefault = true
|
|
11
|
+
|
|
12
|
+
[[rules]]
|
|
13
|
+
id = "absolute-home-path"
|
|
14
|
+
description = "An absolute home-directory path in a tracked file"
|
|
15
|
+
regex = '''(?:/Users/|/home/)[A-Za-z0-9._-]+|C:\\Users\\'''
|
|
16
|
+
keywords = ["/users/", "/home/", "c:\\users\\"]
|
|
17
|
+
|
|
18
|
+
[allowlist]
|
|
19
|
+
description = "The file that defines the rule"
|
|
20
|
+
paths = ['''(^|/)\.?gitleaks\.toml$''']
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# What runs before every commit.
|
|
2
|
+
#
|
|
3
|
+
# pip install pre-commit install the runner
|
|
4
|
+
# pre-commit run --all-files run everything now
|
|
5
|
+
# pre-commit autoupdate --freeze move the pinned revs forward to 40-char SHAs
|
|
6
|
+
#
|
|
7
|
+
# This file is installed as .pre-commit-config.yaml. It is invoked from
|
|
8
|
+
# .githooks/pre-commit rather than from .git/hooks, because core.hooksPath
|
|
9
|
+
# points at .githooks and git ignores .git/hooks while it does. There is
|
|
10
|
+
# therefore no `pre-commit install` step.
|
|
11
|
+
#
|
|
12
|
+
# Revisions are pinned. An unpinned hook changes what it refuses without a
|
|
13
|
+
# diff, which makes a passing commit unreproducible.
|
|
14
|
+
#
|
|
15
|
+
# These are the general-purpose checks, identical in every repository.
|
|
16
|
+
# Repository-specific rules belong in the `local` section at the bottom, or
|
|
17
|
+
# in a gate under .gates/ when they need more than a pattern.
|
|
18
|
+
|
|
19
|
+
repos:
|
|
20
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
21
|
+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
|
|
22
|
+
hooks:
|
|
23
|
+
- id: check-ast # every Python file parses
|
|
24
|
+
- id: detect-private-key
|
|
25
|
+
- id: check-merge-conflict
|
|
26
|
+
- id: check-yaml
|
|
27
|
+
- id: check-toml
|
|
28
|
+
- id: check-added-large-files
|
|
29
|
+
- id: end-of-file-fixer
|
|
30
|
+
- id: trailing-whitespace
|
|
31
|
+
|
|
32
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
33
|
+
rev: 9026c9127e153371d7a78dfcb0c45ae2046a3d10 # frozen: v0.17.6
|
|
34
|
+
hooks:
|
|
35
|
+
- id: ruff-check
|
|
36
|
+
# Report only. A linter that edits code on commit changes files the
|
|
37
|
+
# author did not open, which is a decision about style rather than a
|
|
38
|
+
# check for correctness. The rule selection is in ruff.toml.
|
|
39
|
+
args: [--no-fix]
|
|
40
|
+
|
|
41
|
+
# Secrets and machine-specific paths. gitleaks is the standard scanner;
|
|
42
|
+
# .gitleaks.toml keeps its default rules and adds one for home-directory
|
|
43
|
+
# paths.
|
|
44
|
+
- repo: https://github.com/gitleaks/gitleaks
|
|
45
|
+
rev: 2ca41cc1372d1e939a6a879f18cdc19fc1cac1ce # frozen: v8.30.0
|
|
46
|
+
hooks:
|
|
47
|
+
- id: gitleaks
|
|
48
|
+
|
|
49
|
+
# Semantic crypto/auth AST checks and repository security posture.
|
|
50
|
+
- repo: https://github.com/rctruta/ai-sec-gate
|
|
51
|
+
rev: 6c8b79f11486d1920d2e78dd007ab2e54a12e47d # frozen: v0.2.3
|
|
52
|
+
hooks:
|
|
53
|
+
- id: ai-sec-gate
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# AGENTS.md — Agent Contract & Gate Map
|
|
2
|
+
|
|
3
|
+
> **Workspace Policy for `ai-agent-utils`.** Humans and AI coding agents share this repository.
|
|
4
|
+
> Every enforceable rule below is backed by a local gate or remote policy mechanism.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Standard Engineering Practices (No One-Offs)
|
|
9
|
+
|
|
10
|
+
- All code, scripts, linters, and configurations must adhere to standard engineering practices.
|
|
11
|
+
- Do not create ad-hoc, brittle single-use scripts, custom regex parsers, or bespoke governance mechanisms where industry-standard tooling exists (e.g., use `pre-commit`, `ruff`, `gitleaks`, `pytest`, `unittest`).
|
|
12
|
+
- **Gate engines are immutable mechanism:** The scripts in `.gates/` are generic engines. All project-specific configuration (paths, thresholds, exclusions) must be declared in `pyproject.toml` (under `[tool.gates]`) or `.gates.toml`. Never edit the Python code in `.gates/` to change project layout or policy.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 1. Local & Remote Gates
|
|
17
|
+
|
|
18
|
+
- **Local Commit Gate (`.githooks/pre-commit`):**
|
|
19
|
+
- Runs `pre-commit` (`ruff` `E9/F/B/S`, `gitleaks` secrets + home-path rules, `ai-sec-gate` semantic crypto/auth & posture check, `check-ast`, `check-yaml`, `check-toml`, `detect-private-key`, `check-added-large-files`).
|
|
20
|
+
- **Local Push Gate (`.githooks/pre-push`):**
|
|
21
|
+
- Refuses to push a dirty working tree (including untracked files).
|
|
22
|
+
- Runs `pytest tests/ -q` and `sh tests/ci_checks.sh` (full generator + gate-proof suite); push aborts on any failure.
|
|
23
|
+
- **Remote CI & Branch Protection (`.github/workflows/ci.yml`):**
|
|
24
|
+
- All GitHub Actions are pinned to 40-char commit SHAs, with cached `pre-commit` environments.
|
|
25
|
+
- Runs `pre-commit run --all-files`, `pip-audit` dependency vulnerability scanning, and `tests/ci_checks.sh`.
|
|
26
|
+
- `main` is the source of truth; do not commit directly to `main`.
|
|
27
|
+
- Feature work must happen on topic branches (`feat/...`, `fix/...`, `docs/...`, `refactor/...`) via Pull Requests.
|
|
28
|
+
- **One-use branches (Squash-and-Merge):** Treat branches as one-use — after a PR merges, always start the next change with `git fetch origin && git checkout -b <new-branch> origin/main`.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Publishing: what an agent may and may not do
|
|
33
|
+
|
|
34
|
+
This repository is public. Anything pushed to it, including branches, commit
|
|
35
|
+
messages and pull-request text, can be read by anyone and stays in history.
|
|
36
|
+
|
|
37
|
+
- **Agents do not publish.** No `git push` unless the owner asks for it in the
|
|
38
|
+
current session, and never to `main`. No merging pull requests, no
|
|
39
|
+
force-push, no rewriting history, no changing repository settings. An agent
|
|
40
|
+
works on a local branch; the owner reviews, pushes and merges.
|
|
41
|
+
- **Stage files by name.** Never `git add -A` or `git add .`. Before every
|
|
42
|
+
commit, read `git status` and `git diff --staged` and confirm each path is
|
|
43
|
+
meant to be public.
|
|
44
|
+
- **Private material stays outside the repository.** Personal notes, summaries of
|
|
45
|
+
chat conversations, local machine paths, and unpublished work are never copied in, referenced by
|
|
46
|
+
absolute path, or quoted in code, comments, tests, commit messages or PR
|
|
47
|
+
text. Code that needs private data reads its location from an environment
|
|
48
|
+
variable.
|
|
49
|
+
- **Commit messages and PR text are public writing.** Use a short
|
|
50
|
+
Conventional Commits subject (`fix: ...`, `docs: ...`, `chore: ...`) that
|
|
51
|
+
says what changed. A body, if any, explains the change technically. No
|
|
52
|
+
session narrative, no account of earlier mistakes, no incident dates, no
|
|
53
|
+
names of people or private documents.
|
|
54
|
+
- **The owner reviews before merge:** `git log -p origin/main..HEAD` and the
|
|
55
|
+
PR title. Squash merges use the PR title only, so the commit on `main` says
|
|
56
|
+
exactly what was reviewed.
|
|
57
|
+
- **Secrets:** gitleaks runs in pre-commit, and GitHub secret scanning and push
|
|
58
|
+
protection are on. Fix a finding by removing the value. Do not allowlist it
|
|
59
|
+
unless the owner says so.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 2. Project Architecture & Tools
|
|
64
|
+
|
|
65
|
+
- **Python CLI Wrapper (`src/ai_agent_utils/`):** Thin zero-dependency Hatchling package exposing `init-agent-project` (resolving bundled `init-agent-project.sh` + `templates/` in wheels or directly from a source checkout). Published to PyPI via OIDC in `.github/workflows/release.yml`.
|
|
66
|
+
- **Initialization Script (`init-agent-project.sh`):** Provisions new workspaces across three modes (`--gates` full default with Level-4 `ai-sec-gate`, `--no-gates`, and `--lite` quick prototype / issue-repro), optional Python (`--python` using `pyproject.toml` + `uv sync`), optional `--lock`, owner-agnostic badges (`--owner`), and optional portfolio metadata (`--portfolio`, `--description`, `--section`).
|
|
67
|
+
- **Templates (`templates/`):** Canonical gate scripts (`templates/gates/`, documented in `GATES.md`), pre-commit/ruff/gitleaks configs, and installer scripts.
|
|
68
|
+
- **Package Specification:** `pyproject.toml` (Hatchling backend, Python >= 3.11 for stdlib `tomllib`).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 3. Fresh Clone Setup
|
|
73
|
+
|
|
74
|
+
If working in a fresh clone, activate git hooks:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git config core.hooksPath .githooks
|
|
78
|
+
uv sync
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 4. Rules a gate now enforces
|
|
84
|
+
|
|
85
|
+
Each of these was written as a rule first, stated repeatedly, and broken anyway.
|
|
86
|
+
A rule in a document binds nobody. These are the gates that replaced them.
|
|
87
|
+
|
|
88
|
+
- **No value is written twice.** If a value lives in a data file, code reads it;
|
|
89
|
+
code does not restate it. `.gates/no_hardcoding.py` compares the two after
|
|
90
|
+
normalising entities, dashes, case and years, and refuses the commit.
|
|
91
|
+
*Origin: a generator rendered a list of certificates as literal HTML while the
|
|
92
|
+
same certificates sat in the YAML it was meant to read. The data was edited
|
|
93
|
+
and the page kept showing the hardcoded copy.*
|
|
94
|
+
|
|
95
|
+
- **No tracked file carries a credential or one machine's absolute path.**
|
|
96
|
+
The `gitleaks` hook in `.pre-commit-config.yaml` runs gitleaks' default
|
|
97
|
+
rules plus the home-directory rule in `.gitleaks.toml`.
|
|
98
|
+
|
|
99
|
+
- **A gate scans itself.** No gate may exempt its own directory. The escape
|
|
100
|
+
valve is the `allow:` block in `FACTS.yaml`, which is a decision visible in
|
|
101
|
+
the diff rather than an invisible skip-list entry.
|
|
102
|
+
*Origin: a privacy gate written after a real address leaked kept that address
|
|
103
|
+
in its own docstring for two weeks, because its file was in its own skip list.*
|
|
104
|
+
|
|
105
|
+
- **Local notes live outside the worktree.** `scratch/` is a symlink to a
|
|
106
|
+
directory outside the repository, and `.gates/scratch_external.py` asserts
|
|
107
|
+
it. git refuses to stage through a symlink — `fatal: pathspec is beyond a
|
|
108
|
+
symbolic link` — so the guarantee does not depend on anyone remembering.
|
|
109
|
+
*Origin: a public repository carried `scratch/` on line 25 of its .gitignore
|
|
110
|
+
AND a 23 KB draft tracked in HEAD for three months. An ignore rule is
|
|
111
|
+
consulted only for files git does not already track, so it had been present
|
|
112
|
+
and powerless the whole time.*
|
|
113
|
+
|
|
114
|
+
- **A publishing surface declares its own rules.**
|
|
115
|
+
`.gates/check_publish_contract.py` reads `publish_contract.toml`, where each
|
|
116
|
+
surface names the file whose presence means it is in play. A live surface
|
|
117
|
+
whose trigger is missing fails; a *planned* surface whose trigger appears
|
|
118
|
+
also fails, because the artifact's arrival demands its rules. That second
|
|
119
|
+
case is what lets a surface be declared years before it exists.
|
|
120
|
+
*Origin: three silent drifts in one afternoon — a registry manifest naming
|
|
121
|
+
the previous version, that manifest existing only on an unpushed local
|
|
122
|
+
branch, and a CITATION.cff three releases stale so every citation named the
|
|
123
|
+
wrong version. The registry being published to checked none of it.*
|
|
124
|
+
|
|
125
|
+
- **A tracked Python file must at least parse.** The `check-ast` hook in
|
|
126
|
+
`.pre-commit-config.yaml`. Every other check reads files as text, so a
|
|
127
|
+
syntax error passes all of them.
|
|
128
|
+
|
|
129
|
+
- **Lint and security findings are defects, not style.** The `ruff-check` hook
|
|
130
|
+
runs the rule set selected in `ruff.toml` — `E9`, `F`, `B`, `S` (including
|
|
131
|
+
Bandit security rules) — and reports without editing. Widening the selection
|
|
132
|
+
is a one-line change, and the findings it produces are fixed in that same
|
|
133
|
+
change rather than ignored.
|
|
134
|
+
|
|
135
|
+
- **Workflow actions are pinned by commit SHA, and dependencies are audited.**
|
|
136
|
+
Workflows in `.github/workflows/` and `templates/ci/` pin external actions to
|
|
137
|
+
immutable 40-char commit SHAs and audit resolved dependencies in CI
|
|
138
|
+
(`pip-audit`, plus `npm audit` when `package-lock.json` is present).
|
|
139
|
+
|
|
140
|
+
- **An untested gate is theatre.** `.gates/tests/prove_gates.sh` makes each gate
|
|
141
|
+
fire on a planted violation and stay quiet on a clean tree. Run it after
|
|
142
|
+
touching any gate.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 5. Rules no gate can enforce
|
|
147
|
+
|
|
148
|
+
These are real and they are on your honour, because the check needs judgement
|
|
149
|
+
or project-specific wiring. Stating them here is not enforcement; it is a
|
|
150
|
+
reminder of where the gates stop.
|
|
151
|
+
|
|
152
|
+
- **A check that nothing runs is a file, not a gate.** Wire it into a hook in
|
|
153
|
+
the same change that writes it. If it needs a built artifact or a library
|
|
154
|
+
the running environment lacks, say which stage it belongs to rather than
|
|
155
|
+
leaving it to be discovered.
|
|
156
|
+
*Origin: a manifest test with ten assertions, covering exactly the drift that
|
|
157
|
+
later shipped, was written in August, committed only to a local branch that
|
|
158
|
+
was never pushed, and run by nothing. The check existed. Nothing gated it.*
|
|
159
|
+
|
|
160
|
+
- **A gate in this registry runs on the standard library alone.** A freshly
|
|
161
|
+
bootstrapped project has installed nothing. A gate that imports a third-party
|
|
162
|
+
package will crash in its pre-commit hook.
|
|
163
|
+
*Origin: a gate that read its config with pyyaml broke `init-agent-project`
|
|
164
|
+
outright — the hook raised ModuleNotFoundError and the first commit never
|
|
165
|
+
happened. `tomllib` has been in the standard library since 3.11.*
|
|
166
|
+
|
|
167
|
+
- **When a gate and your expectation disagree, check the gate's premise before
|
|
168
|
+
"fixing" anything.** A finding can be about the checker rather than the code.
|
|
169
|
+
*Origin: three times in one day — a parse error that was only an error on an
|
|
170
|
+
older interpreter, a trigger that fired because `pyproject.toml` signals that
|
|
171
|
+
a project exists rather than that it publishes, and a probe that blamed the
|
|
172
|
+
gate for its own oversight.*
|
|
173
|
+
|
|
174
|
+
- **Two patches to the same failure means the model is wrong.** Fix the design,
|
|
175
|
+
not the third symptom.
|
|
176
|
+
*Origin: a release failed on a missing library, then on another missing
|
|
177
|
+
library, and only the third failure revealed that the real defect was having
|
|
178
|
+
one name for two different moments in the release job.*
|
|
179
|
+
|
|
180
|
+
- **A structural change needs its blast radius measured, not reasoned about.**
|
|
181
|
+
Before refactoring, snapshot what the system produces. After, diff the
|
|
182
|
+
snapshots. Content that changed during a change that was supposed to be
|
|
183
|
+
structural is the finding.
|
|
184
|
+
|
|
185
|
+
git tag -a known-good-pre-refactor -m "<command that proves it works>"
|
|
186
|
+
# refactor
|
|
187
|
+
git show known-good-pre-refactor # re-read the proving command
|
|
188
|
+
|
|
189
|
+
*Origin: a template conversion dropped an entire section from a page, five
|
|
190
|
+
credits and a line of prose. Every test passed: they asserted that the HTML
|
|
191
|
+
was well-formed and that every anchor resolved, and nothing asserted the
|
|
192
|
+
content was still there.*
|
|
193
|
+
|
|
194
|
+
- **Tests must assert content, not only shape.** A page can lose a section and
|
|
195
|
+
stay valid. For any generated artifact, assert that every record in the source
|
|
196
|
+
reaches the output — the mapping is project-specific, so the test is yours to
|
|
197
|
+
write.
|
|
198
|
+
|
|
199
|
+
- **Fixing a late-stage bug means re-checking the early stages.** The same
|
|
200
|
+
defect usually has siblings that were written at the same time by the same
|
|
201
|
+
hand. When you find one, grep for its shape before moving on.
|
|
202
|
+
*Origin: the hardcoded certificates were fixed; nineteen more hardcoded values
|
|
203
|
+
sat in the same file, found only when a gate was pointed at it.*
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 6. Documentation Triggers (When to Update README)
|
|
208
|
+
|
|
209
|
+
Do NOT update the README for internal bug fixes, refactorings, or minor code edits.
|
|
210
|
+
Review and update the README and agent instructions ONLY when a change crosses an external boundary:
|
|
211
|
+
1. **CLI / Entrypoints:** A command, CLI flag, or runner script is added, renamed, or removed.
|
|
212
|
+
2. **Dependencies & Toolchain:** A dependency, interpreter version, or external tool requirement is changed in `pyproject.toml`.
|
|
213
|
+
3. **Environment & Configuration:** A new environment variable, configuration table, or setup prerequisite is introduced.
|
|
214
|
+
4. **Repository Layout:** A top-level directory or primary data pipeline is added, moved, or removed.
|
|
215
|
+
If none of these boundaries was crossed, leave the README untouched.
|