
Control Metalayer Loop
- 10 installs
- 1 repo stars
- Updated June 28, 2026
- broomva/agent-control-metalayer-skill
control-metalayer-loop is a skill that initializes a repository into a control-loop driven system with control primitives, policy governance, and CI harnesses for autonomous code agents.
About
A skill that turns a repository into a control-system metalayer for autonomous code agents. A developer uses it to install control primitives, policy and command governance, git hooks, and CI harnesses so agents can operate safely and keep improving. It runs a Typer CLI wizard that scaffolds artifacts in baseline, governed, or autonomous profiles and audits for gaps.
- Initializes a repo into a control-loop driven agentic development system
- Typer wizard with baseline, governed, and autonomous profiles
- Generates control policy, commands, topology, git hooks, and E2E harness
Control Metalayer Loop by the numbers
- 10 all-time installs (skills.sh)
- Ranked #11,937 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Jul 28, 2026 (Skillselion catalog sync)
control-metalayer-loop capabilities & compatibility
- Capabilities
- orchestration
- Works with
- github · playwright
- Use cases
- ci cd · orchestration · testing
What control-metalayer-loop says it does
Use this skill to initialize or upgrade a repository into a control-loop driven agentic development system.
python3 scripts/control_wizard.py init <repo-path> --profile governed
Keep command names stable (`smoke`, `check`, `test`, `recover`).
npx skills add https://github.com/broomva/agent-control-metalayer-skill --skill control-metalayer-loopAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 10 |
|---|---|
| repo stars | ★ 1 |
| Last updated | June 28, 2026 |
| Repository | broomva/agent-control-metalayer-skill ↗ |
What it does
Initialize or upgrade a repo with control primitives, policy governance, and harness so code agents operate safely.
Who is it for?
Bootstrapping repo-level control primitives, policy gates, and CI harnesses for code agents
When should I use this skill?
You need explicit control primitives, command/rule governance, and a scalable agent-safe topology
What you get
A repo scaffolded with control policy, commands, topology, git hooks, and control-loop CI
- AGENTS.md, PLANS.md, METALAYER.md, .control policy/commands/topology, git hooks, CI workflows
By the numbers
- 3 profiles (baseline, governed, autonomous)
- 5-step workflow
Files
Control Metalayer Loop
Use this skill to initialize or upgrade a repository into a control-loop driven agentic development system.
What To Load
references/control-primitives.mdfor the control model and minimal control law.references/rules-and-commands.mdfor policy/rules and command governance.references/topology-growth.mdfor repository topology and scale path.references/wizard-cli.mdfor command usage.
Primary Entry Point
Use the Typer wizard:
python3 scripts/control_wizard.py init <repo-path> --profile governedProfiles:
baseline: minimal harness and command surface.governed: baseline + policy/commands/topology + control loop + metrics + git hooks.autonomous: governed + recovery/nightly controls + web and CLI E2E primitives.
Workflow
1. Baseline current repo workflows and constraints. 2. Initialize baseline metalayer artifacts. 3. Add control primitives and governance rules. 4. Audit and close gaps. 5. Iterate based on run outcomes and metric drift.
Step 1: Baseline
- Identify canonical test/lint/typecheck/build commands.
- Identify high-risk actions requiring policy gates.
- Identify required observability IDs for agent runs.
Step 2: Initialize Metalayer
Run:
python3 scripts/control_wizard.py init <repo-path> --profile baselineThis creates stable operational interfaces:
AGENTS.md,PLANS.md,METALAYER.mdMakefile.controlandscripts/control/*docs/control/ARCHITECTURE.mdanddocs/control/OBSERVABILITY.md- CI workflow for control checks
Step 3: Add Control Primitives
Run:
python3 scripts/control_wizard.py init <repo-path> --profile governedThis adds the core control plane:
.control/policy.yaml.control/commands.yaml.control/topology.yamldocs/control/CONTROL_LOOP.mdevals/control-metrics.yaml
For a fully self-sustaining loop:
python3 scripts/control_wizard.py init <repo-path> --profile autonomousAdds:
scripts/control/install_hooks.sh+.githooks/*scripts/control/recover.shscripts/control/web_e2e.shscripts/control/cli_e2e.sh.github/workflows/web-e2e.yml.github/workflows/cli-e2e.ymltests/e2e/web/*+playwright.config.tstests/e2e/cli/smoke.sh.control/state.json.github/workflows/control-nightly.yml
Step 4: Validate
Run:
python3 scripts/control_wizard.py audit <repo-path>
python3 scripts/control_wizard.py audit <repo-path> --strictTreat audit failures as blocking until corrected.
Step 5: Operate And Grow
- Keep command names stable (
smoke,check,test,recover). - Keep E2E command names stable (
web-e2e,cli-e2e). - Keep policy and command catalog synchronized with actual behavior.
- Track control metrics and adjust setpoints deliberately.
- Prune stale rules/scripts/docs to prevent entropy growth.
Adaptation Rules
- Do not overwrite existing project conventions without explicit reason.
- Prefer wrappers and policy files over ad-hoc command execution.
- Make every major behavior observable and auditable.
- Keep human escalation rules explicit and easy to trigger.
Related Skills
agent-consciousness— Architectural synthesis of how the control metalayer, knowledge graph, and conversation logs form a persistent consciousness for agents.knowledge-graph-memory— Bridge script that transforms Claude Code conversation logs into Obsidian-compatible session documents, creating episodic memory for the knowledge graph.
interface:
display_name: "Control Metalayer Loop"
short_description: "Control-loop harness for autonomous code agents"
default_prompt: "Set up this repository with a control-system metalayer, policy rules, commands, and folder topology for stable autonomous agent development."
version: 1
commands:
- id: smoke
command: make smoke
preconditions:
- dependencies_installed
on_failure: fix_environment
- id: check
command: make check
preconditions:
- smoke_passed
on_failure: fix_static_issues
- id: test
command: make test
preconditions:
- check_passed
on_failure: diagnose_and_retry
- id: recover
command: make recover
preconditions:
- failure_detected
on_failure: escalate_human
version: 1
controller:
gate_sequence:
- smoke
- check
- test
retry_budget: 2
escalation:
trigger: retry_budget_exhausted
owner: human_oncall
rules:
- id: no-merge-with-failing-checks
type: hard
condition: "check == fail or test == fail"
action: block_merge
- id: require-plan-for-long-task
type: hard
condition: "task_duration_minutes > 30 and plan_missing"
action: block_execution
{
"version": 1,
"last_audit_at": null,
"last_entropy_review_at": null,
"controller_mode": "governed",
"notes": []
}
version: 1
zones:
product_code:
paths:
- src/
- app/
- packages/
control_plane:
paths:
- .control/
- docs/control/
- scripts/control/
- evals/
ownership:
policy_owner: engineering
command_owner: platform
observability_owner: sre
#!/usr/bin/env bash
set -euo pipefail
if [ -x ./scripts/control/check.sh ]; then
./scripts/control/check.sh
exit 0
fi
if command -v make >/dev/null 2>&1; then
make check
exit 0
fi
echo "No check command available for pre-commit." >&2
exit 1
#!/usr/bin/env bash
set -euo pipefail
if [ -x ./scripts/control/test.sh ]; then
./scripts/control/test.sh
exit 0
fi
if command -v make >/dev/null 2>&1; then
make test
exit 0
fi
echo "No test command available for pre-push." >&2
exit 1
name: CLI E2E
on:
pull_request:
workflow_dispatch:
jobs:
cli-e2e:
runs-on: ubuntu-latest
env:
APP_CLI_BIN: ${{ vars.APP_CLI_BIN }}
APP_CLI_VERSION_ARG: ${{ vars.APP_CLI_VERSION_ARG }}
steps:
- uses: actions/checkout@v4
- name: Run CLI e2e wrapper
run: ./scripts/control/cli_e2e.sh
name: Control Harness CI
on:
push:
branches: [main]
pull_request:
jobs:
control:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run control CI
run: make ci
name: Control Nightly Audit
on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Baseline audit
run: scripts/audit_control.sh .
- name: Strict audit
run: scripts/audit_control.sh . --strict
name: Web E2E
on:
pull_request:
workflow_dispatch:
jobs:
web-e2e:
runs-on: ubuntu-latest
env:
APP_BASE_URL: ${{ vars.APP_BASE_URL }}
PLAYWRIGHT_BASE_URL: ${{ vars.PLAYWRIGHT_BASE_URL }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Node dependencies (if present)
run: |
if [ -f package-lock.json ]; then
npm ci
elif [ -f package.json ]; then
npm install
fi
- name: Install Playwright browser deps (if configured)
run: |
if [ -f playwright.config.ts ] || [ -f playwright.config.js ]; then
npx playwright install --with-deps
fi
- name: Run web e2e wrapper
run: ./scripts/control/web_e2e.sh
AGENTS.md
Project Goal
- Product objective:
- Quality objective:
- Reliability objective:
Control Commands
| Intent | Command |
|---|---|
| Quick environment and build sanity | make smoke |
| Static quality gates | make check |
| Full verification | make test |
| Web integration E2E | make web-e2e |
| CLI integration E2E | make cli-e2e |
| Install git hooks | make hooks-install |
| Recovery playbook | make recover |
| Metalayer audit | make control-audit |
Rules
- Never bypass
checkortestwithout explicit escalation. - Do not merge browser or CLI features without corresponding E2E coverage.
- Keep changes scoped to one plan objective at a time.
- Update control docs and policy when behavior changes.
- Escalate to human when retry budget is exhausted.
Execution Plans
- For tasks > 30 minutes, update
PLANS.mdbefore coding. - Record checkpoints and final verification commands.
Observability
- Include
run_id,trace_id, andtask_idin major workflow logs.
Control-Aware Architecture
Boundaries
- Interface boundary: parse/validate external input.
- Domain boundary: operate on internal typed models.
- Persistence boundary: serialize state transitions.
Ownership
- Product modules own product behavior.
- Control modules own governance and reliability behavior.
Control Loop
Loop Definition
1. Measure sensor outputs. 2. Compare against setpoints. 3. Select control action. 4. Execute command/action. 5. Verify and persist results.
Escalation
Escalate when retries exceed budget or when hard policy rules are violated.
Control Observability
Required Fields
- run_id
- trace_id
- task_id
- command_id
- status
- duration_ms
Required Events
- control.step.start
- control.step.success
- control.step.failure
- control.escalation
version: 1
metrics:
pass_at_1:
target: 0.70
alert_below: 0.55
retry_rate:
target: 0.20
alert_above: 0.40
merge_cycle_time_hours:
target: 24
alert_above: 48
revert_rate:
target: 0.03
alert_above: 0.08
human_intervention_rate:
target: 0.20
alert_above: 0.40
.PHONY: smoke check test recover hooks-install web-e2e cli-e2e ci-e2e control-audit ci
smoke:
@./scripts/control/smoke.sh
check:
@./scripts/control/check.sh
test:
@./scripts/control/test.sh
recover:
@if [ -x ./scripts/control/recover.sh ]; then ./scripts/control/recover.sh; else echo "recover primitive not installed"; exit 2; fi
hooks-install:
@if [ -x ./scripts/control/install_hooks.sh ]; then ./scripts/control/install_hooks.sh; else echo "hooks primitive not installed"; exit 2; fi
web-e2e:
@if [ -x ./scripts/control/web_e2e.sh ]; then ./scripts/control/web_e2e.sh; else echo "web primitive not installed"; exit 2; fi
cli-e2e:
@if [ -x ./scripts/control/cli_e2e.sh ]; then ./scripts/control/cli_e2e.sh; else echo "cli primitive not installed"; exit 2; fi
control-audit:
@./scripts/audit_control.sh .
ci: smoke check test
ci-e2e: ci web-e2e cli-e2e
METALAYER
This repository operates as a control loop for autonomous agent development.
Setpoints
- pass_at_1 target:
- merge_cycle_time target:
- revert_rate target:
- human_intervention_rate target:
Sensors
- CI checks
- Test outcomes
- Web E2E outcomes
- CLI E2E outcomes
- Static checks
- Runtime traces/logs
Controller Policy
- Gate sequence: smoke -> check -> test
- Retry budget:
- Escalation conditions:
Actuators
- Code edits
- Script updates
- Policy updates
- Documentation updates
- Hook and workflow updates
Feedback Loop
1. Measure 2. Compare 3. Decide 4. Act 5. Verify
PLANS.md
Objective
- Outcome:
- Scope:
- Non-goals:
Constraints
- Technical:
- Policy:
- Risk:
Steps
1. Step 2. Step 3. Step
Verification
make smokemake checkmake test
Decisions
- Date / decision / reason
import { defineConfig } from "@playwright/test";
export default defineConfig({
testDir: "tests/e2e/web",
timeout: 45_000,
use: {
baseURL: process.env.PLAYWRIGHT_BASE_URL || process.env.APP_BASE_URL || "http://127.0.0.1:3000",
trace: "retain-on-failure",
},
reporter: [["line"]],
});
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'USAGE'
Usage: scripts/audit_control.sh [repo_path] [--strict]
Audit repository for control metalayer artifacts.
USAGE
}
repo_path="."
strict=0
while [ $# -gt 0 ]; do
case "$1" in
--strict)
strict=1
;;
-h|--help)
usage
exit 0
;;
*)
if [ "$repo_path" != "." ]; then
echo "error: multiple repo paths provided" >&2
exit 1
fi
repo_path="$1"
;;
esac
shift
done
if [ ! -d "$repo_path" ]; then
echo "error: repo path not found: $repo_path" >&2
exit 1
fi
repo_path=$(cd "$repo_path" && pwd)
failures=0
ok() { echo "[ok] $1"; }
fail() {
echo "[missing] $1"
failures=$((failures + 1))
}
check_file() {
local rel="$1"
if [ -f "$repo_path/$rel" ]; then
ok "$rel"
else
fail "$rel"
fi
}
check_contains() {
local rel="$1"
local pattern="$2"
local label="$3"
local f="$repo_path/$rel"
if [ ! -f "$f" ]; then
fail "$label (file missing: $rel)"
return
fi
if grep -Eq "$pattern" "$f"; then
ok "$label"
else
fail "$label"
fi
}
check_hooks_path() {
if [ ! -d "$repo_path/.git" ]; then
ok "git hooks path check skipped (not a git repo)"
return
fi
local hooks_path
hooks_path=$(git -C "$repo_path" config --get core.hooksPath || true)
if [ "$hooks_path" = ".githooks" ]; then
ok "git core.hooksPath configured"
else
fail "git core.hooksPath configured (.githooks expected)"
fi
}
echo "Auditing control metalayer: $repo_path"
echo
baseline=(
"AGENTS.md"
"PLANS.md"
"METALAYER.md"
"Makefile.control"
"scripts/audit_control.sh"
"scripts/control/smoke.sh"
"scripts/control/check.sh"
"scripts/control/test.sh"
"docs/control/ARCHITECTURE.md"
"docs/control/OBSERVABILITY.md"
".github/workflows/control-harness.yml"
)
for rel in "${baseline[@]}"; do
check_file "$rel"
done
echo
check_contains "AGENTS.md" "Harness Commands|Control Commands" "AGENTS.md command section"
check_contains "METALAYER.md" "Setpoints" "METALAYER setpoint section"
check_contains "Makefile.control" "^control-audit:" "Makefile.control control-audit target"
check_contains ".github/workflows/control-harness.yml" "make ci" "control harness workflow invokes make ci"
if [ "$strict" -eq 1 ]; then
echo
strict_files=(
".control/policy.yaml"
".control/commands.yaml"
".control/topology.yaml"
".control/state.json"
"docs/control/CONTROL_LOOP.md"
"evals/control-metrics.yaml"
"scripts/control/install_hooks.sh"
".githooks/pre-commit"
".githooks/pre-push"
"scripts/control/recover.sh"
"scripts/control/web_e2e.sh"
"scripts/control/cli_e2e.sh"
"tests/e2e/web/smoke.spec.ts"
"tests/e2e/cli/smoke.sh"
"playwright.config.ts"
".github/workflows/web-e2e.yml"
".github/workflows/cli-e2e.yml"
".github/workflows/control-nightly.yml"
)
for rel in "${strict_files[@]}"; do
check_file "$rel"
done
check_hooks_path
fi
echo
if [ "$failures" -gt 0 ]; then
echo "Control audit failed: $failures issue(s)."
exit 1
fi
echo "Control audit passed."
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ -n "${CONTROL_CHECK_CMD:-}" ]; then
eval "$CONTROL_CHECK_CMD"
exit 0
fi
if [ -f Cargo.toml ] && command -v cargo >/dev/null 2>&1; then
cargo clippy --all-targets --all-features -- -D warnings
exit 0
fi
if [ -f package.json ] && command -v npm >/dev/null 2>&1; then
npm run -s lint
npm run -s typecheck || true
exit 0
fi
if [ -f pyproject.toml ]; then
if command -v ruff >/dev/null 2>&1; then
ruff check .
fi
if command -v mypy >/dev/null 2>&1; then
mypy .
fi
exit 0
fi
echo "No check command detected. Set CONTROL_CHECK_CMD."
exit 1
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ -n "${CONTROL_CLI_E2E_CMD:-}" ]; then
eval "$CONTROL_CLI_E2E_CMD"
exit 0
fi
if [ -x ./tests/e2e/cli/smoke.sh ]; then
./tests/e2e/cli/smoke.sh
exit 0
fi
cli_bin="${APP_CLI_BIN:-}"
if [ -n "$cli_bin" ]; then
"$cli_bin" --help >/dev/null
echo "CLI reachable: $cli_bin"
exit 0
fi
echo "No CLI e2e command configured. Set CONTROL_CLI_E2E_CMD or APP_CLI_BIN." >&2
exit 1
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ ! -d .git ]; then
echo "error: not a git repository: $root" >&2
exit 1
fi
mkdir -p .githooks
chmod +x .githooks/pre-commit .githooks/pre-push
git config core.hooksPath .githooks
echo "Git hooks installed: core.hooksPath=.githooks"
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
echo "Recovery workflow"
echo "1) Re-run smoke"
echo "2) Re-run check"
echo "3) Capture failing tests and open escalation if needed"
./scripts/control/smoke.sh || true
./scripts/control/check.sh || true
./scripts/control/test.sh || true
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ -n "${CONTROL_SMOKE_CMD:-}" ]; then
eval "$CONTROL_SMOKE_CMD"
exit 0
fi
if [ -f Cargo.toml ] && command -v cargo >/dev/null 2>&1; then
cargo check --quiet
exit 0
fi
if [ -f package.json ] && command -v npm >/dev/null 2>&1; then
npm run -s build || npm run -s smoke
exit 0
fi
if [ -f pyproject.toml ] && command -v pytest >/dev/null 2>&1; then
pytest -q -k smoke || pytest -q -k "not integration and not e2e"
exit 0
fi
echo "No smoke command detected. Set CONTROL_SMOKE_CMD."
exit 1
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ -n "${CONTROL_TEST_CMD:-}" ]; then
eval "$CONTROL_TEST_CMD"
exit 0
fi
if [ -f Cargo.toml ] && command -v cargo >/dev/null 2>&1; then
cargo test --quiet
exit 0
fi
if [ -f package.json ] && command -v npm >/dev/null 2>&1; then
npm run -s test
exit 0
fi
if [ -f pyproject.toml ] && command -v pytest >/dev/null 2>&1; then
pytest -q
exit 0
fi
echo "No test command detected. Set CONTROL_TEST_CMD."
exit 1
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$root"
if [ -n "${CONTROL_WEB_E2E_CMD:-}" ]; then
eval "$CONTROL_WEB_E2E_CMD"
exit 0
fi
base_url="${APP_BASE_URL:-${PLAYWRIGHT_BASE_URL:-}}"
if [ -f package.json ] && command -v npm >/dev/null 2>&1; then
if node -e 'const p=require("./package.json"); process.exit(p.scripts&&p.scripts["e2e:web"]?0:1)' >/dev/null 2>&1; then
npm run -s e2e:web
exit 0
fi
fi
if [ -f playwright.config.ts ] && command -v npx >/dev/null 2>&1; then
npx playwright test tests/e2e/web --reporter=line
exit 0
fi
if [ -n "$base_url" ] && command -v curl >/dev/null 2>&1; then
curl -fsS "$base_url" >/dev/null
echo "Web deployment reachable: $base_url"
exit 0
fi
echo "No web e2e command configured. Set CONTROL_WEB_E2E_CMD or APP_BASE_URL, or install Playwright config/tests." >&2
exit 1
#!/usr/bin/env bash
set -euo pipefail
cli_bin="${APP_CLI_BIN:-}"
if [ -z "$cli_bin" ]; then
echo "Set APP_CLI_BIN for CLI E2E smoke." >&2
exit 1
fi
"$cli_bin" --help >/dev/null
if [ -n "${APP_CLI_VERSION_ARG:-}" ]; then
"$cli_bin" "$APP_CLI_VERSION_ARG" >/dev/null
fi
echo "CLI smoke test passed for $cli_bin"
import { expect, test } from "@playwright/test";
test("home page loads", async ({ page }) => {
await page.goto("/");
await expect(page.locator("body")).toBeVisible();
});
Control Primitives
Use this map to reason about autonomous repo development as a dynamic control system.
Mapping
- Plant: repository + CI + runtime behavior.
- Controller: policy rules + decision logic + supervising humans.
- Actuators: agent edits, command execution, PR operations.
- Sensors: tests, static checks, logs, traces, eval outcomes.
- Setpoints: target quality, reliability, speed, autonomy.
- Disturbances: requirement changes, dependency updates, outages, flaky tests.
Minimal Control Law
1. Run smoke. 2. If smoke fails, stop and fix environment/build issues only. 3. Run check (lint + typecheck). 4. If check fails, block merge and repair static issues. 5. Run test. 6. If test fails, allow bounded retries; then escalate. 7. If failures persist across runs, tighten policy or reduce change surface.
Required Metrics
- pass_at_1
- retry_rate
- time_to_actionable_failure
- merge_cycle_time
- revert_rate
- human_intervention_rate
Stability Criteria
- Bounded retries.
- Decreasing regression frequency.
- Consistent audit pass rate.
- Controlled entropy (docs/scripts/rules in sync).
Rules And Commands
Keep command and rule governance explicit and versioned.
Rule Types
- Hard gates: non-negotiable checks.
- Soft policies: preferred behavior with override paths.
- Escalation rules: when autonomy must hand off to human.
- Recovery rules: rollback, retry, or de-scope actions.
Command Governance
Expose a stable command surface through wrappers:
make smokemake checkmake testmake web-e2emake cli-e2emake hooks-installmake recovermake control-audit
Keep direct tooling (cargo, npm, pytest) behind wrapper scripts for portability and deterministic behavior.
Command Contract Pattern
For each command:
- Preconditions
- Expected outputs
- Failure modes
- Recovery action
- Escalation path
Store this in .control/commands.yaml.
End-To-End Validation
- Web changes require browser-level E2E checks against deployed or preview URLs.
- CLI changes require binary-level E2E checks using real command invocations.
- Keep these checks in dedicated workflows so failures are isolated and actionable.
Topology And Growth
This skill uses a split between product code and control-plane artifacts.
Recommended Topology
- Product code: existing repo structure.
- Control plane:
.control/for policy, command catalog, topology, and state.docs/control/for architecture, observability, and loop docs.scripts/control/for deterministic command wrappers..githooks/for local gate enforcement.tests/e2e/web/andtests/e2e/cli/for integration checks.evals/for control metrics and drift tracking.
Growth Path
1. Baseline: command wrappers + AGENTS/PLANS. 2. Governed: explicit policy, commands, topology, and metrics. 3. Autonomous: recovery scripts, nightly audits, entropy controls.
Scaling Pattern
- Keep policy declarations data-driven (
yaml/json) rather than hardcoded in prompts. - Keep orchestration deterministic and inspectable.
- Add specialized primitives per domain, but preserve common command interface.
Wizard CLI
Main tool: scripts/control_wizard.py
Init
python3 scripts/control_wizard.py init <repo-path> --profile baseline
python3 scripts/control_wizard.py init <repo-path> --profile governed
python3 scripts/control_wizard.py init <repo-path> --profile autonomousgovernedinstalls policy/commands/topology + hooks primitives.autonomousinstalls governed + recovery + web/cli E2E primitives.
Audit
python3 scripts/control_wizard.py audit <repo-path>
python3 scripts/control_wizard.py audit <repo-path> --strictStatus
python3 scripts/control_wizard.py status <repo-path>Primitive Operations
python3 scripts/control_wizard.py primitive list
python3 scripts/control_wizard.py primitive add policy loop hooks --repo <repo-path>
python3 scripts/control_wizard.py primitive add web cli --repo <repo-path>#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'USAGE'
Usage: audit_control.sh [repo_path] [--strict]
Audit repository for control metalayer artifacts.
USAGE
}
repo_path="."
strict=0
while [ $# -gt 0 ]; do
case "$1" in
--strict)
strict=1
;;
-h|--help)
usage
exit 0
;;
*)
if [ "$repo_path" != "." ]; then
echo "error: multiple repo paths provided" >&2
exit 1
fi
repo_path="$1"
;;
esac
shift
done
if [ ! -d "$repo_path" ]; then
echo "error: repo path not found: $repo_path" >&2
exit 1
fi
repo_path=$(cd "$repo_path" && pwd)
failures=0
ok() { echo "[ok] $1"; }
fail() {
echo "[missing] $1"
failures=$((failures + 1))
}
check_file() {
local rel="$1"
if [ -f "$repo_path/$rel" ]; then
ok "$rel"
else
fail "$rel"
fi
}
check_contains() {
local rel="$1"
local pattern="$2"
local label="$3"
local f="$repo_path/$rel"
if [ ! -f "$f" ]; then
fail "$label (file missing: $rel)"
return
fi
if grep -Eq "$pattern" "$f"; then
ok "$label"
else
fail "$label"
fi
}
check_hooks_path() {
if [ ! -d "$repo_path/.git" ]; then
ok "git hooks path check skipped (not a git repo)"
return
fi
local hooks_path
hooks_path=$(git -C "$repo_path" config --get core.hooksPath || true)
if [ "$hooks_path" = ".githooks" ]; then
ok "git core.hooksPath configured"
else
fail "git core.hooksPath configured (.githooks expected)"
fi
}
echo "Auditing control metalayer: $repo_path"
echo
baseline=(
"AGENTS.md"
"PLANS.md"
"METALAYER.md"
"Makefile.control"
"scripts/audit_control.sh"
"scripts/control/smoke.sh"
"scripts/control/check.sh"
"scripts/control/test.sh"
"docs/control/ARCHITECTURE.md"
"docs/control/OBSERVABILITY.md"
".github/workflows/control-harness.yml"
)
for rel in "${baseline[@]}"; do
check_file "$rel"
done
echo
check_contains "AGENTS.md" "Harness Commands|Control Commands" "AGENTS.md command section"
check_contains "METALAYER.md" "Setpoints" "METALAYER setpoint section"
check_contains "Makefile.control" "^control-audit:" "Makefile.control control-audit target"
check_contains ".github/workflows/control-harness.yml" "make ci" "control harness workflow invokes make ci"
if [ "$strict" -eq 1 ]; then
echo
strict_files=(
".control/policy.yaml"
".control/commands.yaml"
".control/topology.yaml"
".control/state.json"
"docs/control/CONTROL_LOOP.md"
"evals/control-metrics.yaml"
"scripts/control/install_hooks.sh"
".githooks/pre-commit"
".githooks/pre-push"
"scripts/control/recover.sh"
"scripts/control/web_e2e.sh"
"scripts/control/cli_e2e.sh"
"tests/e2e/web/smoke.spec.ts"
"tests/e2e/cli/smoke.sh"
"playwright.config.ts"
".github/workflows/web-e2e.yml"
".github/workflows/cli-e2e.yml"
".github/workflows/control-nightly.yml"
)
for rel in "${strict_files[@]}"; do
check_file "$rel"
done
check_hooks_path
fi
echo
if [ "$failures" -gt 0 ]; then
echo "Control audit failed: $failures issue(s)."
exit 1
fi
echo "Control audit passed."
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'USAGE'
Usage: bootstrap_control.sh [repo_path] [--force]
Install baseline control metalayer templates into a target repository.
USAGE
}
repo_path="."
force=0
while [ $# -gt 0 ]; do
case "$1" in
--force)
force=1
;;
-h|--help)
usage
exit 0
;;
*)
if [ "$repo_path" != "." ]; then
echo "error: multiple repo paths provided" >&2
exit 1
fi
repo_path="$1"
;;
esac
shift
done
if [ ! -d "$repo_path" ]; then
echo "error: repo path not found: $repo_path" >&2
exit 1
fi
repo_path=$(cd "$repo_path" && pwd)
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
skill_dir=$(cd "$script_dir/.." && pwd)
template_dir="$skill_dir/assets/templates"
copy_template() {
local rel="$1"
local src="$template_dir/$rel"
local dst="$repo_path/$rel"
if [ ! -f "$src" ]; then
echo "[error] missing template: $rel" >&2
exit 1
fi
mkdir -p "$(dirname "$dst")"
if [ -f "$dst" ] && [ "$force" -ne 1 ]; then
echo "[skip] $rel"
return
fi
cp "$src" "$dst"
echo "[write] $rel"
}
baseline=(
"AGENTS.md"
"PLANS.md"
"METALAYER.md"
"Makefile.control"
"scripts/audit_control.sh"
"scripts/control/smoke.sh"
"scripts/control/check.sh"
"scripts/control/test.sh"
"docs/control/ARCHITECTURE.md"
"docs/control/OBSERVABILITY.md"
".github/workflows/control-harness.yml"
)
for rel in "${baseline[@]}"; do
copy_template "$rel"
done
makefile="$repo_path/Makefile"
if [ ! -f "$makefile" ]; then
cat > "$makefile" <<'MAKEFILE'
-include Makefile.control
MAKEFILE
echo "[write] Makefile"
elif ! grep -Eq '(^|[[:space:]])-?include[[:space:]]+Makefile\.control([[:space:]]|$)' "$makefile"; then
cat >> "$makefile" <<'MAKEFILE'
# Control metalayer targets
-include Makefile.control
MAKEFILE
echo "[update] Makefile"
else
echo "[skip] Makefile already includes Makefile.control"
fi
chmod +x \
"$repo_path/scripts/audit_control.sh" \
"$repo_path/scripts/control/smoke.sh" \
"$repo_path/scripts/control/check.sh" \
"$repo_path/scripts/control/test.sh"
echo
echo "Baseline control metalayer bootstrap complete."
echo "Next: run python3 scripts/control_wizard.py audit $repo_path"
#!/usr/bin/env python3
"""Typer wizard for control metalayer setup in agent-operated repositories."""
from __future__ import annotations
import subprocess
from enum import Enum
from pathlib import Path
from typing import Dict, Iterable, List, Tuple
try:
import typer
except ImportError as exc: # pragma: no cover - import guard
raise SystemExit(
"Missing dependency: typer. Install with `python3 -m pip install typer`."
) from exc
app = typer.Typer(help="Control metalayer wizard for agentic repository setup.")
primitive_app = typer.Typer(help="Manage control primitives.")
app.add_typer(primitive_app, name="primitive")
SCRIPT_DIR = Path(__file__).resolve().parent
SKILL_DIR = SCRIPT_DIR.parent
TEMPLATE_DIR = SKILL_DIR / "assets" / "templates"
BOOTSTRAP_SCRIPT = SCRIPT_DIR / "bootstrap_control.sh"
AUDIT_SCRIPT = SCRIPT_DIR / "audit_control.sh"
BASELINE_FILES: Tuple[str, ...] = (
"AGENTS.md",
"PLANS.md",
"METALAYER.md",
"Makefile.control",
"scripts/audit_control.sh",
"scripts/control/smoke.sh",
"scripts/control/check.sh",
"scripts/control/test.sh",
"docs/control/ARCHITECTURE.md",
"docs/control/OBSERVABILITY.md",
".github/workflows/control-harness.yml",
)
class Profile(str, Enum):
baseline = "baseline"
governed = "governed"
autonomous = "autonomous"
class Primitive(str, Enum):
policy = "policy"
commands = "commands"
topology = "topology"
loop = "loop"
metrics = "metrics"
hooks = "hooks"
recovery = "recovery"
state = "state"
nightly = "nightly"
web = "web"
cli = "cli"
PRIMITIVE_FILES: Dict[Primitive, Tuple[str, ...]] = {
Primitive.policy: (".control/policy.yaml",),
Primitive.commands: (".control/commands.yaml",),
Primitive.topology: (".control/topology.yaml",),
Primitive.loop: ("docs/control/CONTROL_LOOP.md",),
Primitive.metrics: ("evals/control-metrics.yaml",),
Primitive.hooks: (
"scripts/control/install_hooks.sh",
".githooks/pre-commit",
".githooks/pre-push",
),
Primitive.recovery: ("scripts/control/recover.sh",),
Primitive.state: (".control/state.json",),
Primitive.nightly: (".github/workflows/control-nightly.yml",),
Primitive.web: (
"scripts/control/web_e2e.sh",
".github/workflows/web-e2e.yml",
"tests/e2e/web/smoke.spec.ts",
"playwright.config.ts",
),
Primitive.cli: (
"scripts/control/cli_e2e.sh",
".github/workflows/cli-e2e.yml",
"tests/e2e/cli/smoke.sh",
),
}
GOVERNED_PRIMITIVES: Tuple[Primitive, ...] = (
Primitive.policy,
Primitive.commands,
Primitive.topology,
Primitive.loop,
Primitive.metrics,
Primitive.hooks,
)
AUTONOMOUS_PRIMITIVES: Tuple[Primitive, ...] = (
*GOVERNED_PRIMITIVES,
Primitive.recovery,
Primitive.state,
Primitive.nightly,
Primitive.web,
Primitive.cli,
)
def _resolve_repo(path: Path) -> Path:
repo = path.expanduser().resolve()
if not repo.exists() or not repo.is_dir():
typer.secho(f"error: repo path does not exist: {repo}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=2)
return repo
def _run(script: Path, args: List[str]) -> None:
if not script.exists():
typer.secho(f"error: script not found: {script}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=2)
result = subprocess.run([str(script), *args], check=False)
if result.returncode != 0:
raise typer.Exit(code=result.returncode)
def _copy_template(relative_path: str, repo: Path, force: bool) -> str:
source = TEMPLATE_DIR / relative_path
target = repo / relative_path
if not source.exists():
typer.secho(f"error: missing template: {source}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=2)
target.parent.mkdir(parents=True, exist_ok=True)
if target.exists() and not force:
return "skip"
target.write_bytes(source.read_bytes())
if target.suffix == ".sh" or relative_path.startswith(".githooks/"):
target.chmod(0o755)
return "write"
def _activate_hooks(repo: Path) -> None:
install_script = repo / "scripts" / "control" / "install_hooks.sh"
if not install_script.exists():
return
result = subprocess.run([str(install_script)], cwd=str(repo), check=False)
if result.returncode != 0:
typer.secho(
" [warn] failed to activate git hooks automatically; run scripts/control/install_hooks.sh manually.",
fg=typer.colors.YELLOW,
)
def _apply_primitives(repo: Path, primitives: Iterable[Primitive], force: bool) -> None:
for primitive in primitives:
typer.secho(f"\n[{primitive.value}]", fg=typer.colors.CYAN)
for relative_path in PRIMITIVE_FILES[primitive]:
state = _copy_template(relative_path, repo, force)
label = "write" if state == "write" else "skip "
typer.echo(f" [{label}] {relative_path}")
if primitive == Primitive.hooks:
_activate_hooks(repo)
@app.command()
def init(
repo_path: Path = typer.Argument(Path("."), help="Target repository path."),
profile: Profile = typer.Option(Profile.governed, "--profile", "-p", help="Setup profile."),
force: bool = typer.Option(False, "--force", help="Overwrite existing files."),
) -> None:
"""Initialize control metalayer in a repository."""
repo = _resolve_repo(repo_path)
typer.secho(f"Initializing control metalayer in {repo}", fg=typer.colors.GREEN)
args = [str(repo)]
if force:
args.append("--force")
_run(BOOTSTRAP_SCRIPT, args)
if profile == Profile.baseline:
return
primitives = GOVERNED_PRIMITIVES if profile == Profile.governed else AUTONOMOUS_PRIMITIVES
_apply_primitives(repo, primitives, force)
typer.secho("\nInitialization complete.", fg=typer.colors.GREEN)
@app.command()
def audit(
repo_path: Path = typer.Argument(Path("."), help="Target repository path."),
strict: bool = typer.Option(False, "--strict", help="Require governed/autonomous primitives."),
) -> None:
"""Run control metalayer audit."""
repo = _resolve_repo(repo_path)
args = [str(repo)]
if strict:
args.append("--strict")
_run(AUDIT_SCRIPT, args)
@app.command()
def status(
repo_path: Path = typer.Argument(Path("."), help="Target repository path."),
) -> None:
"""Show baseline and primitive coverage."""
repo = _resolve_repo(repo_path)
typer.secho(f"Control metalayer status for {repo}", fg=typer.colors.GREEN)
typer.echo()
baseline_present = sum(1 for rel in BASELINE_FILES if (repo / rel).exists())
typer.echo(f"baseline: {baseline_present}/{len(BASELINE_FILES)}")
for rel in BASELINE_FILES:
marker = "OK " if (repo / rel).exists() else "MISS"
typer.echo(f" [{marker}] {rel}")
typer.echo()
typer.echo("primitives:")
for primitive in Primitive:
files = PRIMITIVE_FILES[primitive]
present = sum(1 for rel in files if (repo / rel).exists())
marker = "OK " if present == len(files) else "PARTIAL" if present > 0 else "MISS"
typer.echo(f" [{marker}] {primitive.value}: {present}/{len(files)}")
@primitive_app.command("list")
def primitive_list() -> None:
"""List primitive names and files."""
for primitive in Primitive:
typer.echo(primitive.value)
for rel in PRIMITIVE_FILES[primitive]:
typer.echo(f" - {rel}")
@primitive_app.command("add")
def primitive_add(
primitives: List[Primitive] = typer.Argument(..., help="Primitive names to add."),
repo: Path = typer.Option(Path("."), "--repo", "-r", help="Target repository path."),
force: bool = typer.Option(False, "--force", help="Overwrite existing files."),
) -> None:
"""Add selected primitives incrementally."""
repo_path = _resolve_repo(repo)
_apply_primitives(repo_path, primitives, force)
typer.secho("\nPrimitive update complete.", fg=typer.colors.GREEN)
if __name__ == "__main__":
app()
Related skills
FAQ
What profiles does the wizard support?
baseline (minimal harness), governed (policy plus control loop plus metrics plus git hooks), and autonomous (adds recovery, nightly controls, and web/CLI E2E).
How do you initialize it?
Run python3 scripts/control_wizard.py init <repo-path> --profile governed, then audit with the same script.