From 09a6cbe0a4ecdce050e4d43b12b63f1109b6234a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=80=D1=83=D0=B1=D0=B8=D0=BD=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BF=D0=BF?= <289370046+zarubinphil@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:16:08 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A4=D0=B0=D0=B7=D0=B0=207=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=207-10=20=E2=80=94=20job-lifecycle=20FSM=20+?= =?UTF-8?q?=20project=20passport=20+=20parity-smoke?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - chezmoi/dot_agents/job-lifecycle.yaml: FSM 13 состояний (Draft→Archived + Failed→Retry), invariants (retry-once, delivered/archived gates), ledger_fields. - claude-starter/project.yaml: шаблон project passport (data_policy, capabilities, agents.preferred_pair, steward.max_proposals_per_week). - claude-starter/routing-evals.example.jsonl: формат eval-записей (3 примера: code-edit/arch/legal с полями ts/job_id/task_class/primary/reviewer/outcome/correction). - athena-router.md: добавлен start matrix 10 классов + eval feedback loop. - smoke/parity-smoke.sh: synthetic parity-smoke — сравнение schema route-card Claude vs Codex + drift-check ~/.claude↔~/.codex если оба развёрнуты. - smoke/agent-contract.sh: +5 проверок (job-lifecycle/project.yaml/routing-evals/ start-matrix/parity-smoke). - smoke/smoke.sh: секция [parity]. - shellcheck -S warning: 0 warnings · smoke: SMOKE OK. --- chezmoi/dot_agents/job-lifecycle.yaml | 79 ++++++++++++ .../role-passports/athena-router.md | 28 +++++ claude-starter/project.yaml | 43 +++++++ claude-starter/routing-evals.example.jsonl | 3 + smoke/agent-contract.sh | 46 +++++++ smoke/parity-smoke.sh | 112 ++++++++++++++++++ smoke/smoke.sh | 9 +- 7 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 chezmoi/dot_agents/job-lifecycle.yaml create mode 100644 claude-starter/project.yaml create mode 100644 claude-starter/routing-evals.example.jsonl create mode 100755 smoke/parity-smoke.sh diff --git a/chezmoi/dot_agents/job-lifecycle.yaml b/chezmoi/dot_agents/job-lifecycle.yaml new file mode 100644 index 0000000..29fad35 --- /dev/null +++ b/chezmoi/dot_agents/job-lifecycle.yaml @@ -0,0 +1,79 @@ +# AthenaOS — Job lifecycle FSM (Phase 7, Local Agent Contract) +# Declarative state machine; no runtime engine required. +# The ledger records current_state; agents read it and enforce transitions. +# Validated by smoke/agent-contract.sh. + +version: 1 + +initial_state: Draft + +states: + Draft: + description: Job envelope created, inputs not yet validated. + transitions: [Staging, Failed] + Staging: + description: athena-guard running input census (sha256 + secret scan). + transitions: [ProjectDetection, Failed] + ProjectDetection: + description: Project identity resolved; data_policy loaded from project.yaml. + transitions: [RouteProposed, Failed] + RouteProposed: + description: athena-router emitted route card; awaiting human approval. + transitions: [Approved, Failed] + Approved: + description: Route approved (human or auto-policy); ready to queue. + transitions: [Queued] + Queued: + description: Waiting for execution slot. + transitions: [Running] + Running: + description: athena-runner executing on primary provider (local-first). + transitions: [NeedsInput, ReviewReady, Failed] + NeedsInput: + description: Execution paused; human response required before continuing. + transitions: [Running, Failed] + ReviewReady: + description: Artifacts produced; athena-reconciler coverage complete; awaiting reviewer. + transitions: [Delivered, Failed] + Delivered: + description: athena-reviewer verdict pass; athena-librarian vault write complete. + transitions: [Archived] + Archived: + description: Terminal. final-learning-tail written; durable in vault. + transitions: [] + Failed: + description: Transition failure, execution error, or gate rejection. + transitions: [Retry] + Retry: + description: One rescue attempt via rescue-runner. Second failure → Failed (terminal). + transitions: [Running, Failed] + +terminal_states: [Archived, Failed] + +# Invariants — enforced by gates, not just convention. +invariants: + - id: retry-once + rule: Retry is allowed at most once per job_id. A second failure goes to Failed (terminal). + - id: review-ready-gate + rule: ReviewReady is only reachable after athena-reconciler emits coverage_complete marker. + - id: delivered-gate + rule: Delivered is only reachable after athena-reviewer emits verdict:pass. + - id: archived-gate + rule: Archived requires final-learning-tail (brief_md + agent_trace + self_reflection + most_important). + - id: no-skip-approval + rule: Running is only reachable from Queued; Queued only from Approved. RouteProposed never skips to Running. + - id: no-vault-bypass + rule: Delivered requires the librarian path; runner may not write to vault directly. + +# Ledger fields written per-job. +ledger_fields: + - job_id # unique identifier + - project_id # from project.yaml + - current_state # one of the states above + - provider # claude | codex + - entered_at # ISO-8601 timestamp of current state entry + - history # list of {state, entered_at} + - route_card # emitted by athena-router + - coverage_marker # emitted by athena-reconciler + - reviewer_verdict # emitted by athena-reviewer + - tail_written # boolean; set by athena-librarian diff --git a/chezmoi/dot_agents/role-passports/athena-router.md b/chezmoi/dot_agents/role-passports/athena-router.md index 03ac239..3d7927b 100644 --- a/chezmoi/dot_agents/role-passports/athena-router.md +++ b/chezmoi/dot_agents/role-passports/athena-router.md @@ -8,3 +8,31 @@ - **Contract:** emits a route card `{primary, reviewer, capabilities, risk, confidence, why[], alternatives, requires_approval[]}`. No evidence → `confidence: low, status: hypothesis`. Logs every route to `routing-evals.jsonl`. - **Won't:** execute work; take external action or deliver on medium/high risk without approval; reuse one skill set for the whole job. - **Parity:** identical route-card schema for Claude Code and Codex; the per-class matrix maps task → primary engine, only the runner adapter differs. + +## Start matrix (10 classes) + +Default routing hypothesis. Refined by `routing-evals.jsonl` over time. +`project.yaml:agents.preferred_pair` overrides per-project. + +| Class | Primary | Reviewer | Why | +|---|---|---|---| +| code-edit | codex | claude | execution-heavy; Codex optimized for code generation | +| debug | codex | claude | trace-first; Codex strong on stack analysis | +| arch | claude | codex | synthesis-first; Claude stronger on reasoning + design | +| docs | claude | codex | language-first; Claude stronger on writing quality | +| legal | claude | codex | reasoning-critical; Claude mandatory for judgment calls | +| obsidian | claude | codex | knowledge-graph; Claude for synthesis + linking | +| deploy | codex | claude | command-heavy; Codex for shell + CI sequences | +| ui | codex | claude | code-gen dominant; Codex for component output | +| security | claude | codex | judgment-first; Claude for threat modeling + review | +| steward | claude | codex | governance; Claude for weekly improvement loop | + +> Matrix is a hypothesis, not a rule. Correction events in `routing-evals.jsonl` shift weights. +> Format: `{ts, job_id, task_class, primary, reviewer, confidence, why[], outcome, correction}`. + +## Eval feedback loop + +Wrong project → apply matching penalty to that project-signal. +Always one provider → flag project.yaml `preferred_pair` policy divergence. +Bad artifact → label eval record + surface to athena-steward weekly. +The loop is closed: every route decision is a falsifiable prediction. diff --git a/claude-starter/project.yaml b/claude-starter/project.yaml new file mode 100644 index 0000000..3aac444 --- /dev/null +++ b/claude-starter/project.yaml @@ -0,0 +1,43 @@ +# project.yaml — Athena project passport template +# Copy to your project root; fill in the values marked {{PLACEHOLDER}}. +# Validated by athena-guard (data_policy) and athena-router (capabilities + preferred_pair). +# Spec: specs/07-local-agent-contract.md §project.yaml + +version: 1 + +project: + id: "{{PROJECT_ID}}" # unique slug, kebab-case, e.g. "my-app" + name: "{{PROJECT_NAME}}" # human-readable name + description: "{{ONE_LINE_DESCRIPTION}}" + +# Data policy — governs how agents handle project content. +# athena-guard enforces this before any cloud API call. +data_policy: + sensitivity: low # low | medium | high | critical + allow_cloud: true # send content to cloud LLM APIs (Claude, Codex) + allow_embeddings: true # generate vector embeddings of project content + retention_days: 90 # job artifact retention before deletion pipeline runs + require_upload_manifest: false # require explicit manifest before any upload + +# Capabilities — what agent task classes are permitted for this project. +# athena-router will not propose blocked classes. +capabilities: + allowed: + - code-edit + - debug + - arch + - docs + - ui + blocked: [] # e.g. [deploy, legal] if those should not run here + +# Preferred agent pair (overrides the global start matrix for this project). +# Leave primary/reviewer empty to use the global matrix defaults. +agents: + preferred_pair: + primary: "" # "codex" | "claude" | "" (use matrix) + reviewer: "" # "claude" | "codex" | "" (use matrix) + +# Steward governance — weekly improvement loop. +steward: + max_proposals_per_week: 3 # improvement proposals athena-steward may surface + owner_review_required: true # proposals need explicit owner sign-off before applying diff --git a/claude-starter/routing-evals.example.jsonl b/claude-starter/routing-evals.example.jsonl new file mode 100644 index 0000000..5ecb38e --- /dev/null +++ b/claude-starter/routing-evals.example.jsonl @@ -0,0 +1,3 @@ +{"ts":"2026-06-23T10:00:00Z","job_id":"job-001","task_class":"code-edit","primary":"codex","reviewer":"claude","confidence":"high","why":["code-edit class → Codex primary per start matrix","project.yaml preferred_pair: empty (matrix default used)"],"outcome":"delivered","correction":null} +{"ts":"2026-06-23T11:00:00Z","job_id":"job-002","task_class":"arch","primary":"claude","reviewer":"codex","confidence":"high","why":["arch class → Claude primary per start matrix","synthesis-first task favors Claude"],"outcome":"delivered","correction":null} +{"ts":"2026-06-23T12:00:00Z","job_id":"job-003","task_class":"legal","primary":"claude","reviewer":"codex","confidence":"medium","why":["legal class → Claude primary","reasoning-critical domain"],"outcome":"needs-revision","correction":{"field":"primary","was":"claude","should_be":"claude","note":"primary was correct; reviewer should escalate to claude for final pass on legal"}} diff --git a/smoke/agent-contract.sh b/smoke/agent-contract.sh index ecf2fcf..3c35b43 100755 --- a/smoke/agent-contract.sh +++ b/smoke/agent-contract.sh @@ -101,9 +101,55 @@ else command -v node >/dev/null 2>&1 || echo " → node not found; skipping report+gate smoke" fi +# 11. job-lifecycle.yaml exists and carries required FSM keys. +LIFECYCLE="$ROOT/chezmoi/dot_agents/job-lifecycle.yaml" +if [ ! -f "$LIFECYCLE" ]; then + bad "job-lifecycle.yaml missing" +else + for key in initial_state states terminal_states invariants; do + grep -q "^$key:" "$LIFECYCLE" || bad "job-lifecycle.yaml missing top-level key: $key" + done + REQUIRED_STATES="Draft Staging ProjectDetection RouteProposed Approved Queued Running NeedsInput ReviewReady Delivered Archived Failed Retry" + for s in $REQUIRED_STATES; do + grep -q "^ $s:" "$LIFECYCLE" || bad "job-lifecycle.yaml missing state: $s" + done +fi + +# 12. project.yaml template exists in claude-starter with required fields. +PROJECT_YAML="$ROOT/claude-starter/project.yaml" +if [ ! -f "$PROJECT_YAML" ]; then + bad "claude-starter/project.yaml missing" +else + for field in data_policy capabilities agents steward sensitivity allow_cloud retention_days preferred_pair max_proposals_per_week; do + grep -q "$field" "$PROJECT_YAML" || bad "project.yaml missing field: $field" + done +fi + +# 13. routing-evals.example.jsonl exists in claude-starter. +EVALS_EXAMPLE="$ROOT/claude-starter/routing-evals.example.jsonl" +[ -f "$EVALS_EXAMPLE" ] || bad "claude-starter/routing-evals.example.jsonl missing" + +# 14. athena-router passport carries start matrix (10 classes). +ROUTER_PASSPORT="$ROOT/chezmoi/dot_agents/role-passports/athena-router.md" +MATRIX_CLASSES="code-edit debug arch docs legal obsidian deploy ui security steward" +if [ -f "$ROUTER_PASSPORT" ]; then + for cls in $MATRIX_CLASSES; do + grep -q "$cls" "$ROUTER_PASSPORT" || bad "athena-router.md start matrix missing class: $cls" + done +fi + +# 15. parity-smoke.sh exists and passes. +PARITY="$ROOT/smoke/parity-smoke.sh" +if [ ! -f "$PARITY" ]; then + bad "smoke/parity-smoke.sh missing" +elif [ -x "$PARITY" ]; then + "$PARITY" "$ROOT" >/dev/null 2>&1 || bad "parity-smoke.sh failed" +fi + if [ "$fail" -ne 0 ]; then echo "AGENT-CONTRACT FAIL" >&2 exit 1 fi echo " ✓ 7 passports · graph integrity · learning-tail · session-review skill · report+gate" +echo " ✓ job-lifecycle FSM · project.yaml template · routing-evals format · start matrix · parity-smoke" echo "agent-contract OK" diff --git a/smoke/parity-smoke.sh b/smoke/parity-smoke.sh new file mode 100755 index 0000000..1b9893f --- /dev/null +++ b/smoke/parity-smoke.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# Phase 7 — Synthetic parity smoke. +# Verifies that a route card produced for Claude Code and one for Codex +# carry identical schema fields. Does NOT call any LLM — uses fixtures. +# Also drift-checks live ~/.claude vs ~/.codex if both are deployed. +# Usage: smoke/parity-smoke.sh [REPO_ROOT] + +fail=0 +bad() { echo " ✗ $1" >&2; fail=1; } +ok() { echo " ✓ $1"; } + +echo "[parity-smoke] route-card schema + drift-check" + +# ── 1. Fixture route cards ──────────────────────────────────────────────── +# Both cards come from the same synthetic task (code-edit). +# The schema (field set) must be identical; only provider + primary differ. +TMPDIR_PS="$(mktemp -d /tmp/athena-parity-XXXXXX)" +trap 'rm -rf "$TMPDIR_PS"' EXIT + +cat > "$TMPDIR_PS/claude-route.json" <<'EOF' +{ + "job_id": "smoke-parity-001", + "task_class": "code-edit", + "provider": "claude", + "primary": "claude", + "reviewer": "codex", + "capabilities": ["code-edit"], + "risk": "low", + "confidence": "high", + "why": ["smoke fixture — claude engine"], + "alternatives": [], + "requires_approval": [] +} +EOF + +cat > "$TMPDIR_PS/codex-route.json" <<'EOF' +{ + "job_id": "smoke-parity-001", + "task_class": "code-edit", + "provider": "codex", + "primary": "codex", + "reviewer": "claude", + "capabilities": ["code-edit"], + "risk": "low", + "confidence": "high", + "why": ["smoke fixture — codex engine"], + "alternatives": [], + "requires_approval": [] +} +EOF + +# ── 2. Schema field comparison ──────────────────────────────────────────── +# Extract sorted field names from each card. Compare sets. +# Requires only grep/sed — no jq dependency. +fields_of() { + grep -oE '"[a-z_]+"[[:space:]]*:' "$1" | sed 's/[[:space:]]*://' | sort -u +} + +CLAUDE_FIELDS="$(fields_of "$TMPDIR_PS/claude-route.json")" +CODEX_FIELDS="$(fields_of "$TMPDIR_PS/codex-route.json")" + +if [ "$CLAUDE_FIELDS" = "$CODEX_FIELDS" ]; then + ok "route-card schema: identical ($(echo "$CLAUDE_FIELDS" | wc -l | tr -d ' ') fields)" +else + ONLY_CLAUDE="$(comm -23 <(echo "$CLAUDE_FIELDS") <(echo "$CODEX_FIELDS"))" + ONLY_CODEX="$(comm -13 <(echo "$CLAUDE_FIELDS") <(echo "$CODEX_FIELDS"))" + bad "route-card schema: divergent" + [ -n "$ONLY_CLAUDE" ] && echo " claude-only fields: $ONLY_CLAUDE" >&2 + [ -n "$ONLY_CODEX" ] && echo " codex-only fields: $ONLY_CODEX" >&2 +fi + +# ── 3. Required fields present in both cards ────────────────────────────── +REQUIRED="job_id task_class provider primary reviewer risk confidence why" +for field in $REQUIRED; do + for card in "$TMPDIR_PS/claude-route.json" "$TMPDIR_PS/codex-route.json"; do + grep -q "\"$field\"" "$card" \ + || bad "route-card missing required field '$field' in $(basename "$card")" + done +done +ok "required fields present in both route cards" + +# ── 4. Drift-check live ~/.claude vs ~/.codex (skip if not deployed) ────── +CLAUDE_DIR="$HOME/.claude" +CODEX_DIR="$HOME/.codex" + +if [ -d "$CLAUDE_DIR" ] && [ -d "$CODEX_DIR" ]; then + echo " [drift] both engines deployed — checking registry parity" + + # AGENTS.md must exist in both (registry entrypoint). + [ -f "$CLAUDE_DIR/AGENTS.md" ] \ + || bad "drift: ~/.claude/AGENTS.md missing" + [ -f "$CODEX_DIR/AGENTS.md" ] \ + || bad "drift: ~/.codex/AGENTS.md missing" + + # Both must reference the shared skills/workflows registry. + grep -q 'SHARED-SKILLS-WORKFLOWS' "$CLAUDE_DIR/AGENTS.md" \ + || bad "drift: ~/.claude/AGENTS.md does not reference SHARED-SKILLS-WORKFLOWS" + grep -q 'SHARED-SKILLS-WORKFLOWS' "$CODEX_DIR/AGENTS.md" \ + || bad "drift: ~/.codex/AGENTS.md does not reference SHARED-SKILLS-WORKFLOWS" + + ok "drift-check: AGENTS.md present and references shared registry in both engines" +else + echo " · engines not both deployed — drift-check skipped" +fi + +# ── Result ──────────────────────────────────────────────────────────────── +if [ "$fail" -ne 0 ]; then + echo "PARITY-SMOKE FAIL" >&2 + exit 1 +fi +echo " ✓ parity-smoke: identical schema · required fields · drift-check" +echo "parity-smoke OK" diff --git a/smoke/smoke.sh b/smoke/smoke.sh index 1d2cd32..41d832d 100755 --- a/smoke/smoke.sh +++ b/smoke/smoke.sh @@ -190,10 +190,15 @@ 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" +echo "[agent-contract] Фаза 7: паспорта + handoff-граф integrity + FSM + project-template + parity" if [ -x "$HERE/smoke/agent-contract.sh" ]; then - chk "agent-contract (7 паспортов + граф)" "'$HERE/smoke/agent-contract.sh' '$HERE' >/dev/null 2>&1" + chk "agent-contract (полный)" "'$HERE/smoke/agent-contract.sh' '$HERE' >/dev/null 2>&1" else echo " · agent-contract.sh нет (skip)"; fi +echo "[parity] синтетический route-card + drift-check" +if [ -x "$HERE/smoke/parity-smoke.sh" ]; then + chk "parity-smoke (schema + required fields)" "'$HERE/smoke/parity-smoke.sh' '$HERE' >/dev/null 2>&1" +else echo " · parity-smoke.sh нет (skip)"; fi + [ "$fail" = 0 ] && echo "SMOKE OK" || echo "SMOKE FAIL" exit "$fail"