# CyberBrain26 – Complete Diagnostic Plan

**Plan ID:** `1793687720757-cyberbrain-complete-diagnostic`
**Target:** Orchestrator autonomous execution
**Authoritative Plan:** `.kilo/plans/CyberBrain26cil-031026-v2.md` (approved 2026-10-03)
**Gate Target:** Gate 1 verified → Gate 2 E2E flow evidence

---

## Goal

Produce a complete, evidence-based diagnostic of CyberBrain26 current state:
- What works, what doesn't, with [OVĚŘENO]/[NÁVRH]/[HYPOTÉZA] markers
- How the security chain (identity → policy → permission → approval → sandbox → audit) actually operates
- Model gateway routing (local vs cloud), EgressGate status
- Kilo integration status (config, agents, permissions)
- All open security gaps per PROJECT_STATUS.md
- Artifacts: markdown report, JSON health_check, structured evidence index

---

## Tasks (ordered, with dependencies)

### T0 – Baseline Capture
- **Action:** Read `PROJECT_STATUS.md`, `gate_report.txt`, `.kilo/plans/CyberBrain26cil-031026-v2.md`, `AGENTS.md`, `.kilo/kilo.jsonc`
- **Output:** Baseline summary (HEAD commit, uncommitted files, test counts, phase position)
- **Validation:** Matches `gate_report.txt:2` and `PROJECT_STATUS.md:83-109`

### T1 – Test Suite Execution & Evidence Collection
- **Action:** Run full test suite, capture output
- **Commands (via cyberbrain run):**
  - `PYTHONPATH=src python3 -m pytest -v --tb=short 2>&1 | head -200`
  - `PYTHONPATH=src python3 -m pytest -q tests/test_kilo_agent_policy.py`
  - `python3 -m ruff check --line-length=110 src/cyberbrain26/ tests/ .kilo/`
  - `PYTHONPATH=src python3 -m mypy --cache-dir=/tmp/cb26 src/cyberbrain26`
- **Output:** Test counts, pass/fail, coverage, lint/type status
- **Validation:** ≥ 591 tests pass, ruff clean, mypy 0 errors on 70+ files

### T2 – Security Chain Verification
- **Action:** Read security plane modules and their tests
- **Files:**
  - `src/cyberbrain26/security_plane/identity/__init__.py`
  - `src/cyberbrain26/security_plane/policy/__init__.py`
  - `src/cyberbrain26/security_plane/permission/__init__.py`
  - `src/cyberbrain26/security_plane/approval/__init__.py`
  - `src/cyberbrain26/execution_plane/secure_gateway.py` (AuthorizedExecutionService)
  - `src/cyberbrain26/execution_plane/bubblewrap_provider.py`
  - `src/cyberbrain26/security_plane/audit/__init__.py`
- **Tests:** `tests/test_security_*.py`, `tests/test_security_e2e.py`, `tests/test_execution_provider.py`
- **Output:** Evidence map for each link in chain, fail-closed behavior proof
- **Validation:** Each step has positive + negative test; `ExecutionRefused` on missing approval

### T3 – Model Gateway & Local Model Status
- **Action:** Read model gateway, router, clients; run health_check
- **Files:**
  - `src/cyberbrain26/control_plane/model_gateway/__init__.py`
  - `src/cyberbrain26/model_layer/router.py`
  - `src/cyberbrain26/model_layer/llama_cpp_client.py`
  - `src/cyberbrain26/control_plane/model_gateway/ollama_client.py`
  - `src/cyberbrain26/control_plane/model_gateway/litellm_client.py`
- **Command:** `PYTHONPATH=src python3 -c "from cyberbrain26.control_plane.model_gateway import ModelGateway; g=ModelGateway(); import json; print(json.dumps(g.health_check(), indent=2))"`
- **Output:** JSON health_check, route decision for local-first, EgressGate wiring status
- **Validation:** `prefer_local=True`, `free_only=True`, Ollama/llama.cpp providers registered

### T4 – Kilo Integration Status
- **Action:** Read Kilo config and agent declarations
- **Files:**
  - `.kilo/kilo.jsonc` (subagent_depth, default_agent, permissions, MCP disabled)
  - `.kilo/agent/promptmaster.md`, `.kilo/agent/orchestrator.md`
  - `.kilo/agent/verifier.md`, `.kilo/agent/code-reviewer.md`, etc.
- **Output:** Config verification, delegation matrix, MCP status
- **Validation:** `subagent_depth: 1`, `default_agent: "promptmaster"`, `bash: deny`, `task: deny` globally, MCP `enabled: false`

### T5 – Lifecycle & Persistence
- **Action:** Read control plane (task_queue, approval), audit, SQLite
- **Files:**
  - `src/cyberbrain26/control_plane/task_queue/__init__.py`
  - `src/cyberbrain26/control_plane/approval/__init__.py`
  - `src/cyberbrain26/security_plane/audit/__init__.py`
  - `src/cyberbrain26/data_plane/sqlite_store.py`
- **Tests:** `tests/test_control_plane.py`, `tests/test_sqlite_persistence.py`, `tests/test_audit_chain.py`
- **Output:** Durable job handling, approval flow, audit chain verification, prune_expired safety
- **Validation:** 12/12 mutation tests fail, `prune_expired` writes chained event

### T6 – Open Security Gaps Inventory
- **Action:** Extract from `PROJECT_STATUS.md` lines 203-218 and cross-reference with code
- **Output:** Structured list with code references for each gap
- **Validation:** Each gap has file:line or test showing why it's open

### T7 – Phase Position & Gate Status
- **Action:** Read `.kilo/plans/CyberBrain26cil-031026-v2.md` §5 and §8
- **Output:** Current phase (F2), Gate 1/2/3 criteria, what's blocking next gate
- **Validation:** Matches `corrections.md` memory: "Currently at F2 (minimal complete agent flow...)"

### T8 – Produce Diagnostic Artifacts
- **Action:** Write three files
  1. `YYYYMMDD-cyberbrain-diagnostic.md` – full report per template in prompt
  2. `YYYYMMDD-model-gateway-health.json` – ModelGateway.health_check() output
  3. `YYYYMMDD-evidence-index.txt` – structured list: component | status | file:line | test
- **Validation:** All [OVĚŘENO] claims have file:line or test name; [HYPOTÉZA]/[NÁVRH] clearly separated

---

## Dependencies

```
T0 → T1, T2, T3, T4, T5, T6, T7 (all depend on baseline)
T1, T2, T3, T4, T5, T6, T7 → T8 (artifacts need all evidence)
```

---

## Validation Criteria (Exit Gates)

| Gate | Criterion | How Verified |
|------|-----------|--------------|
| Gate 1 | All quality gates green | T1 output matches `gate_report.txt` |
| Gate 1 | Security chain fail-closed | T2: each link has negative test |
| Gate 1 | Model gateway local-first | T3: health_check shows local providers |
| Gate 1 | Kilo config enforced | T4: subagent_depth=1, bash=deny, MCP disabled |
| Gate 2 | E2E diagnostic complete | T8: artifacts exist with evidence refs |
| Gate 2 | No silent cloud fallback | T3: free_only=True, EgressGate opt-in |

---

## Risk / Open Questions

| # | Question | Recommended Resolution |
|---|----------|------------------------|
| R1 | Is Ollama/llama.cpp actually running on ports 11434/8080? | T3 health_check will show; if not running, mark as [HYPOTÉZA] "configured but not verified live" |
| R2 | Should we attempt a live model call to prove routing? | No – diagnostic is read-only; live call would need approval + EgressGate |
| R3 | Are there uncommitted changes in src/ that affect diagnostic? | T0 captures git status; T1 runs against current working tree |
| R4 | Does `cyberbrain run` work for executing the health_check command? | Yes – it's the authorized execution path (D4). Use it for T1, T3 commands. |

---

## Out of Scope

- Fixing any discovered gaps (that's F3+ work)
- Implementing EgressGate wiring (F4)
- Customer discovery (F5 blocker)
- Adding cgroup/memory quotas (F6)
- Any source code modifications

---

## Execution Notes for Orchestrator

- Use `cyberbrain run` for all command execution (authorized path)
- Delegate read_file tasks to appropriate subagents (verifier, security-auditor, deep-research)
- Each subagent produces evidence; orchestrator aggregates into T8 artifacts
- Maintain [OVĚŘENO]/[NÁVRH]/[HYPOTÉZA] discipline throughout
- Final report must be readable by owner without code access – include file:line refs for every claim