Merge pull request #3 from zarubinphil/phase7-steps7-10

feat: Фаза 7 шаги 7-10 — job-lifecycle FSM + project passport + parity-smoke
This commit was merged in pull request #3.
This commit is contained in:
2026-06-23 22:18:11 +03:00
committed by GitHub
7 changed files with 318 additions and 2 deletions
+79
View File
@@ -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
@@ -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`. - **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. - **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. - **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.
+43
View File
@@ -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
@@ -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"}}
+46
View File
@@ -101,9 +101,55 @@ else
command -v node >/dev/null 2>&1 || echo " → node not found; skipping report+gate smoke" command -v node >/dev/null 2>&1 || echo " → node not found; skipping report+gate smoke"
fi 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 if [ "$fail" -ne 0 ]; then
echo "AGENT-CONTRACT FAIL" >&2 echo "AGENT-CONTRACT FAIL" >&2
exit 1 exit 1
fi fi
echo " ✓ 7 passports · graph integrity · learning-tail · session-review skill · report+gate" 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" echo "agent-contract OK"
+112
View File
@@ -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"
+7 -2
View File
@@ -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" 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 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 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 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" [ "$fail" = 0 ] && echo "SMOKE OK" || echo "SMOKE FAIL"
exit "$fail" exit "$fail"