diff --git a/chezmoi/dot_agents/handoff-graph.yaml b/chezmoi/dot_agents/handoff-graph.yaml new file mode 100644 index 0000000..b5f3a3e --- /dev/null +++ b/chezmoi/dot_agents/handoff-graph.yaml @@ -0,0 +1,83 @@ +# AthenaOS — directed handoff graph (Phase 7, Local Agent Contract) +# Engine-agnostic: Claude Code and Codex follow the same graph; only the runner adapter differs. +# A pipeline without an allowed-transition graph is a draft, not production. +# Validated by smoke/agent-contract.sh (passport + integrity gates). + +version: 1 + +# Entry boundary (the input door, not an agent). +entry: intake + +# Runtime agents. Each id must have a passport in role-passports/.md. +agents: + - id: athena-router + role: route officer + input: job envelope + output: route card + tools: [capability-plan, route-skills, project-yaml] + - id: athena-guard + role: intake census + input: raw inputs + output: census + risk score + tools: [shasum, find, secret-scan] + - id: athena-runner + role: provider adapter + input: run_job + output: outbox artifacts + tools: [claude-adapter, codex-adapter, git-worktree] + - id: athena-reconciler + role: coverage ledger + input: expected vs produced + output: coverage marker + tools: [ledger, grep] + - id: athena-reviewer + role: eval / release gate + input: artifacts + eval_spec + output: verdict + tools: [eval_spec, report-quality-gate, agent-architecture-audit] + - id: athena-librarian + role: knowledge curator + input: approved artifacts + output: vault note + indexes + tools: [knowledge-ops, graphify, kb-embed] + - id: athena-steward + role: weekly governance + input: eval records + output: improvement candidates + tools: [registry, drift-check] + +# Allowed transitions. Every edge MUST carry a `when`. +handoffs: + - { from: intake, to: athena-guard, when: always, payload: raw inputs } + - { from: athena-guard, to: athena-router, when: census passed, payload: census + risk } + - { from: athena-guard, to: athena-reconciler, when: census passed, payload: expected-artifact set } + - { from: athena-router, to: athena-runner, when: route approved, payload: run_job envelope } + - { from: athena-runner, to: athena-reviewer, when: artifacts produced, payload: outbox artifacts } + - { from: athena-runner, to: rescue-runner, when: runner stuck, payload: handoff pack (no secrets) } + - { from: rescue-runner, to: athena-reviewer, when: rescue produced, payload: outbox artifacts } + - { from: athena-reconciler, to: athena-reviewer, when: coverage complete, payload: coverage marker } + - { from: athena-reviewer, to: athena-librarian, when: verdict pass, payload: approved artifacts } + - { from: athena-librarian, to: report, when: vault written, payload: visual report + tail } + - { from: athena-steward, to: report, when: weekly, payload: improvement candidates } + +# Disallowed transitions. Every entry MUST carry a `why`. +forbidden: + - { from: athena-runner, to: deliver, why: medium/high risk needs reviewer verdict first } + - { from: athena-router, to: external, why: no external action without human approval } + - { from: athena-runner, to: vault, why: vault writes go through the librarian, not the runner } + - { from: rescue-runner, to: rescue-runner, why: one rescue attempt only, no loop before human review } + - { from: athena-librarian, to: enrich, why: a storage role does not enrich or transform content } + - { from: any, to: secret-path, why: no agent touches secret/auth/session/cache paths } + +# Gates run by smoke/agent-contract.sh. +gates: + - after: graph + name: handoff-integrity + checks: + - every agent has a passport + - every handoff has a when + - every forbidden has a why + - no orphan agent (each appears in handoffs) + - after: librarian + name: final-learning-tail + checks: [brief_md, agent_trace, self_reflection, most_important] diff --git a/chezmoi/dot_agents/role-passports/_index.md b/chezmoi/dot_agents/role-passports/_index.md new file mode 100644 index 0000000..fc60f8e --- /dev/null +++ b/chezmoi/dot_agents/role-passports/_index.md @@ -0,0 +1,15 @@ +# Role Passports — index + +Engine-agnostic agent contracts read by **both Claude Code and Codex**. One file per agent; format `Soul · Does · Tools · Model · Contract · Won't · Parity`. The directed handoff graph (`../handoff-graph.yaml`) wires them; `smoke/agent-contract.sh` enforces passport + graph integrity. + +| Agent | Role | Model | Gate it owns | +|---|---|---|---| +| [athena-router](athena-router.md) | route officer | Sonnet | route card + stage-preflight | +| [athena-guard](athena-guard.md) | intake census | Haiku | inputs accounted, secret-path blocked | +| [athena-runner](athena-runner.md) | provider adapter | Haiku→Opus | sandboxed run, outbox-only | +| [athena-reconciler](athena-reconciler.md) | coverage ledger | Sonnet | `unaccounted == 0` | +| [athena-reviewer](athena-reviewer.md) | eval / release gate | Sonnet→Opus | verdict before deliver | +| [athena-librarian](athena-librarian.md) | knowledge curator | Haiku→Sonnet | synthesis-only vault | +| [athena-steward](athena-steward.md) | weekly governance | Sonnet | budgeted proposals | + +`reconciler` and `reviewer` are **separate gates** — accounting inputs ≠ judging quality. Never merge. diff --git a/smoke/agent-contract.sh b/smoke/agent-contract.sh new file mode 100755 index 0000000..409fe22 --- /dev/null +++ b/smoke/agent-contract.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# Phase 7 — Local Agent Contract smoke. +# Validates role passports + the directed handoff graph. Zero deps (grep/awk). +# A pipeline without a valid passport+graph contract is a draft, not production. +# Usage: smoke/agent-contract.sh [REPO_ROOT] (default: repo root from script path) + +ROOT="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" +PASS_DIR="$ROOT/chezmoi/dot_agents/role-passports" +GRAPH="$ROOT/chezmoi/dot_agents/handoff-graph.yaml" + +AGENTS="athena-router athena-guard athena-runner athena-reconciler athena-reviewer athena-librarian athena-steward" +fail=0 +bad() { echo " ✗ $1" >&2; fail=1; } + +echo "[agent-contract] passports + handoff graph" + +# 1. Passports exist and carry the canon fields. +for a in $AGENTS; do + f="$PASS_DIR/$a.md" + if [ ! -f "$f" ]; then bad "passport missing: $a"; continue; fi + for field in 'Soul' 'Does:' 'Tools:' 'Model:' 'Contract:' "Won't:" 'Parity:'; do + grep -q "$field" "$f" || bad "$a: missing field '$field'" + done +done + +# 2. Graph exists with the required top-level keys. +if [ ! -f "$GRAPH" ]; then + bad "handoff-graph.yaml missing" +else + for key in entry agents handoffs forbidden gates; do + grep -q "^$key:" "$GRAPH" || bad "graph missing key: $key" + done + + # 3. Each agent is declared and appears in handoffs (no orphan). + handoff_block=$(awk '/^handoffs:/{f=1;next} /^[a-z]/{f=0} f' "$GRAPH") + for a in $AGENTS; do + grep -q "id: $a" "$GRAPH" || bad "agent not declared: $a" + printf '%s\n' "$handoff_block" | grep -q "$a" || bad "orphan agent (absent from handoffs): $a" + done + + # 4. Every handoff edge carries a `when` (each edge is one inline line). + n_edge=$(printf '%s\n' "$handoff_block" | grep -c 'from:') + n_when=$(printf '%s\n' "$handoff_block" | grep -c 'when:') + [ "$n_edge" = "$n_when" ] || bad "handoffs: $n_edge edges but $n_when 'when:' (every edge needs a when)" + + # 5. Every forbidden entry carries a `why`. + forbid_block=$(awk '/^forbidden:/{f=1;next} /^[a-z]/{f=0} f' "$GRAPH") + n_forbid=$(printf '%s\n' "$forbid_block" | grep -c 'from:') + n_why=$(printf '%s\n' "$forbid_block" | grep -c 'why:') + [ "$n_forbid" = "$n_why" ] || bad "forbidden: $n_forbid entries but $n_why 'why:'" + + # 6. The final-learning-tail gate names all four mandatory tail outputs. + for t in brief_md agent_trace self_reflection most_important; do + grep -q "$t" "$GRAPH" || bad "final-learning-tail missing output: $t" + done +fi + +if [ "$fail" -ne 0 ]; then + echo "AGENT-CONTRACT FAIL" >&2 + exit 1 +fi +echo " ✓ 7 passports · graph integrity · learning-tail" +echo "agent-contract OK" diff --git a/smoke/smoke.sh b/smoke/smoke.sh index 372e008..39c4e63 100755 --- a/smoke/smoke.sh +++ b/smoke/smoke.sh @@ -181,5 +181,10 @@ if [ -x "$HERE/smoke/git-leak-guard.test.sh" ]; then chk "git-leak-guard 5 кейсов" "'$HERE/smoke/git-leak-guard.test.sh' >/dev/null 2>&1" else echo " · git-leak-guard.test.sh нет (skip)"; fi +echo "[agent-contract] Фаза 7: паспорта + handoff-граф integrity" +if [ -x "$HERE/smoke/agent-contract.sh" ]; then + chk "agent-contract (7 паспортов + граф)" "'$HERE/smoke/agent-contract.sh' '$HERE' >/dev/null 2>&1" +else echo " · agent-contract.sh нет (skip)"; fi + [ "$fail" = 0 ] && echo "SMOKE OK" || echo "SMOKE FAIL" exit "$fail" diff --git a/specs/00-roadmap.md b/specs/00-roadmap.md index d0adac7..47a1714 100644 --- a/specs/00-roadmap.md +++ b/specs/00-roadmap.md @@ -89,9 +89,9 @@ Generic chezmoi-source собран (чистая пересборка, НЕ д Самопроверяемый агентный слой: роли · handoff-граф · post-run · eval-loop · gates. Job завершён не текстом, а контрактом. Спец: `specs/07-local-agent-contract.md`. Источник идей: `docs/MNEMAZINE-AGENTOS-TRANSFER.ru.md` (скелет) ⊕ канон vault (привиты 6 контрактов, сверка 2026-06-23). - [x] План + сверка (Б) ролей/handoff repo-дока против мастер-дока vault → 6 athena-* → **7** (reviewer ≠ reconciler), привиты job-lifecycle FSM / eval-loop→router / project.yaml / security+emergency / per-class матрица. -- [ ] Шаг 1 — `chezmoi/dot_agents/role-passports/` (7 паспортов, канон-формат). -- [ ] Шаг 2 — `chezmoi/dot_agents/handoff-graph.yaml` (машиночитаемый + forbidden + learning-tail gate). -- [ ] Шаг 3 — `smoke/agent-contract.sh` (passports + handoff integrity). +- [x] Шаг 1 — `chezmoi/dot_agents/role-passports/` (7 паспортов English + `_index.md`, канон-формат). +- [x] Шаг 2 — `chezmoi/dot_agents/handoff-graph.yaml` (машиночитаемый: agents/handoffs/forbidden/gates + learning-tail). +- [x] Шаг 3 — `smoke/agent-contract.sh` (passports + handoff integrity; негатив-тесты ловят when/why/tail/passport; врезан в smoke.sh). - [ ] Шаги 4–6 — session-review · postrun-report · report-quality-gate. - [ ] Шаги 7–8 — job-lifecycle + project.yaml + eval-loop→router + стартовая матрица. - [ ] Шаг 9 — smoke++ · FEATURES maturity layers. Шаг 10 — dashboard (thin UI) — позже. diff --git a/specs/07-local-agent-contract.md b/specs/07-local-agent-contract.md index 8b51b2c..5bbf419 100644 --- a/specs/07-local-agent-contract.md +++ b/specs/07-local-agent-contract.md @@ -81,8 +81,8 @@ All paths on `$HOME` / chezmoi `.tmpl`; zero hardcoded `/Users` or `/srv`. ## Implementation order (10 steps, amended) 1. `role-passports/` — 7 passports (canon format: model/tools/contract/won't). **[done]** -2. `handoff-graph.yaml` — machine-readable (per-edge `when/payload`, forbidden ⊕ rescue/secret, `final-learning-tail` gate). -3. `smoke/agent-contract.sh` — passport schema + handoff integrity (orphan/when/forbidden/tail). +2. `handoff-graph.yaml` — machine-readable (per-edge `when/payload`, forbidden ⊕ rescue/secret, `final-learning-tail` gate). **[done]** +3. `smoke/agent-contract.sh` — passport schema + handoff integrity (orphan/when/forbidden/tail). **[done]** 4. `skills/agent-session-review` (or workflow) — local session tail (brief/trace/reflection/most-important). 5. `scripts/athena-postrun-report.mjs` — Markdown/HTML/JSON report after a meaningful run (`results-json {group_id,outcome,helps,next_action}`). 6. `scripts/athena-report-quality-gate.mjs` — no raw OCR / local filenames / secrets.