# Cross-Code Review Report — Job 7cc8f208

- **Reviewer**: cline (session: `herdr:canary-projects-multi-agent-mux-creator-cline`)
- **Date**: 2026-08-13
- **Commit reviewed**: Working tree changes (uncommitted, diff against HEAD `29f3a33`)
- **Diff scope**: 6 production files, +108/-35 lines
- **Task**: Cross-code review of multi-agent abstraction layer interfaces — lint, behavior, lossage perspectives
- **Prior review**: Job `2ac5b3df` identified 5 findings (F-1 through F-5). This review verifies fixes and checks for regressions.

---

## 1. Changeset Overview

| # | File | Lines Changed | Summary |
|---|------|--------------|---------|
| 1 | `.agents/skills/lib.sh` | +47/-35 | `kind` detection refactored to `case` with role-based suffixes; `derive_session_name` adds `[role]` parameter **with lowercasing**; `verify_session_uuid` adds CWD verification for hermes/cline |
| 2 | `.agents/skills/multi-agent-mux-create/scripts/create_session.sh` | +7/-1 | Agent validation; role passed to `derive_session_name`; `CMD_FULL` fix for wrapper path |
| 3 | `.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh` | +43/-7 | Agent detection loop over roles+agents with `MAM_MANAGED` env fallback; `role` field added to entry |
| 4 | `.agents/skills/multi-agent-mux-orc-onboard/scripts/orc_onboard.sh` | +3/-0 | Hermes case in `detect_nearest_agent` |
| 5 | `.agents/skills/multi-agent-mux-status/scripts/status.sh` | +35/-6 | `resume_on_disk` refactored to role-aware agent detection loop with `endswith` patterns; hermes DB query; cline per-session file check |
| 6 | `.agents/skills/multi-agent-mux-stop/scripts/stop_session.sh` | +8/-4 | Agent inference extended to planner/reviewer roles |

**Key difference from prior review (job `2ac5b3df`)**: This changeset includes fixes for F-1 (CRITICAL), F-2 (Low), and F-4 (Low) identified in the prior review. The `status.sh` changes are substantially expanded (+35 lines vs +14 in prior) with a proper agent detection loop and hermes/cline support.

---

## 2. Syntax Validation

| File | Check | Result |
|------|-------|--------|
| `lib.sh` | `bash -n` | PASS |
| `create_session.sh` | `bash -n` | PASS |
| `stop_session.sh` | `bash -n` | PASS |
| `orc_onboard.sh` | `bash -n` | PASS |
| `reconcile.sh` | `bash -n` | PASS |
| `status.sh` | `bash -n` | PASS |
| `tests/conftest.py` | `py_compile` | PASS |
| `.mam/shim/herdr` | kind detection sync with `lib.sh` | Verified identical (diff empty) |

All syntax checks pass. The shim (`.mam/shim/herdr`) `kind` detection code is byte-identical to `lib.sh` — sync is maintained.

---

## 3. Test Results

| Test File | Tests | Result |
|-----------|-------|--------|
| `test_herdr_shim_contract.py` | 5 | 5/5 PASS |
| `test_tier1_unit.py` | 29 | 29/29 PASS |
| `test_o2_race_free_lock.py` | 22 | 22/22 PASS |
| `test_orc_onboard.py` | 22 | 22/22 PASS |
| `test_o1_rebuttal.py` + `test_o3_scoped_guard.py` + `test_deploy_layout.py` | 39 | 39/39 PASS |
| `test_sanity.py` | 2 | 2/2 PASS (includes previously failing `test_create_session_full`) |
| `test_tier2_component.py` | — | Previously failing `test_comp_create_sqlite_tables_created` confirmed PASS individually; full suite timed out (tmux/reconcile overhead) |
| `test_tier3_integration.py` | — | Timed out (tmux overhead; uses `--role Creator` — expected PASS with F-1 fix) |
| `test_tier4_e2e.py` | — | Not run (tmux overhead; uses `--role Creator` — expected PASS with F-1 fix) |
| `test_uuid_target.py` | — | Timed out (tmux overhead; uses `--role creator` lowercase — expected PASS) |

**Total confirmed**: 99 PASS, 0 FAIL

### Critical test verification

The two tests that FAILED in the prior review (`2ac5b3df`) due to F-1 (role casing bug) now PASS:

```
tests/test_sanity.py::test_create_session_full PASSED
tests/test_tier2_component.py::test_comp_create_sqlite_tables_created PASSED
2 passed in 28.18s
```

This confirms the F-1 fix (`role=$(echo "$role" | tr '[:upper:]' '[:lower:]')`) resolves the role casing mismatch.

---

## 4. Prior Findings Resolution (Job 2ac5b3df)

| Finding | Severity | Status | Details |
|---------|----------|--------|---------|
| **F-1** | CRITICAL | **FIXED** | `derive_session_name` now lowercases role via `tr '[:upper:]' '[:lower:]'` (lib.sh:990). Previously failing tests now PASS. |
| **F-2** | Low | **FIXED** | `status.sh` hermes branch now queries `SELECT 1 FROM sessions WHERE id=?` instead of just checking `state.db` existence (status.sh:87). Per-session verification. |
| **F-3** | Low | **ACCEPTED** | `kind` detection fallback still doesn't check for "cline". Deemed acceptable trade-off in prior review — more correct than defaulting to "cline". No fix needed. |
| **F-4** | Low | **FIXED** | `status.sh` now uses proper `endswith` loop: `any(name.endswith(f'-{r}-{a}') for r in ('creator', 'planner', 'reviewer'))` as primary check (status.sh:57). Fallback uses `f"-{a}" in name` (more precise than previous `'claude' in name`). |
| **F-5** | Info | **ACCEPTED** | `reconcile.sh` env marker fallback still uses macOS-specific `ps eww`. No impact on target platform (macOS). No fix needed. |

**Summary**: 3 of 5 findings fixed (F-1 CRITICAL + F-2/F-4 Low). 2 findings accepted as-is (F-3/F-5 — no fix needed).

---

## 5. Detailed Review by File

### 5.1 `lib.sh` — `derive_session_name` (lines 988-999) — F-1 FIX VERIFIED

**Change**: Added `[role]` parameter (default `"creator"`) with lowercasing via `tr '[:upper:]' '[:lower:]'` before use in `printf`.

```bash
derive_session_name() {
  local workspace="${1:-$PWD}" agent="${2:-}" role="${3:-creator}"
  role=$(echo "$role" | tr '[:upper:]' '[:lower:]')    # <-- FIX for F-1
  ...
  printf '%s-%s-%s' "$slug" "$role" "$agent"
}
```

**Assessment**: The fix is correct and complete. The `tr '[:upper:]' '[:lower:]'` is POSIX-compliant and works on macOS. With this fix:
- `--role Creator` -> `role="creator"` -> session name `...-creator-claude` (correct)
- `--role Planner` -> `role="planner"` -> session name `...-planner-claude` (correct)
- `--role creator` -> `role="creator"` -> session name `...-creator-claude` (unchanged, backward compatible)
- 2-arg calls (no role) -> default `"creator"` -> `...-creator-claude` (unchanged, backward compatible)

**No new issues introduced.**

### 5.2 `lib.sh` — kind detection (lines 268-283)

**Change**: `case` statement with role-based suffixes, grep fallback for non-standard names.

**Assessment**: Same as prior review. F-3 (fallback doesn't check "cline") is accepted as a trade-off. The `case` patterns correctly handle all standard session names produced by `derive_session_name` (which now always produces lowercase roles). **No new issues.**

### 5.3 `lib.sh` — `verify_session_uuid` CWD verification (lines 1510-1539)

**Change**: Hermes: `SELECT cwd FROM sessions WHERE id=?` + CWD comparison. Cline: `found_cwd` from JSON + CWD comparison.

**Assessment**: Security improvement. The `workspace_key()` normalization ensures path comparison is robust. The `if found_cwd and ...` guard maintains backward compatibility with older session formats. **No issues.**

### 5.4 `create_session.sh` — Agent validation + role passing + CMD_FULL (lines 85-88, 121, 175)

**Change**: Agent validation preflight; `"$ROLE"` passed to `derive_session_name`; `CMD_FULL` override for wrapper path.

**Assessment**: All three changes are correct. The agent validation catches invalid agent names early. The role is now passed through `derive_session_name` which lowercases it (F-1 fix). The `CMD_FULL` fix correctly removes `--session-id` when using the wrapper. **No issues.**

### 5.5 `status.sh` — `resume_on_disk` refactor (lines 55-98) — F-2/F-4 FIX VERIFIED

**Change**: Replaced single `endswith('-creator-claude')` check with a comprehensive agent detection loop:

```python
agent = None
for a in ('claude', 'agy', 'hermes', 'cline'):
    if any(name.endswith(f'-{r}-{a}') for r in ('creator', 'planner', 'reviewer')) or name.endswith(f'-{a}'):
        agent = a
        break
if not agent:
    for a in ('claude', 'agy', 'hermes', 'cline'):
        if f"-{a}" in name or f"_{a}" in name:
            agent = a
            break
```

**F-2 fix**: Hermes branch now queries `SELECT 1 FROM sessions WHERE id=?` (line 87) — per-session verification instead of just checking file existence.

**F-4 fix**: Primary check uses `endswith` with role-agent suffixes — precise matching. The fallback (lines 60-64) uses `f"-{a}" in name` which is more precise than the previous `'claude' in name` (requires hyphen/underscore prefix).

**New: cline branch** (lines 93-97): Per-session file check `{u}/{u}.json` — correct.

**Assessment**: The refactor is well-structured. The primary `endswith` loop handles all standard session names. The fallback handles legacy/non-standard names. The `name.endswith(f'-{a}')` check (line 57) handles sessions without a role suffix (backward compatibility). **No new issues.**

### 5.6 `reconcile.sh` — Agent detection loop + env fallback (lines 494-526)

**Change**: Nested loop over roles x agents with `endswith`; `MAM_MANAGED` env marker fallback using `ps eww`; `role` field in entry.

**Assessment**: The loop correctly handles all role-agent combinations. Role is extracted and stored (line 555). The env fallback is a good defensive measure. F-5 (macOS-specific `ps eww`) is accepted. **No new issues.**

### 5.7 `orc_onboard.sh` — Hermes detection (lines 125-127)

**Change**: Added `hermes)` case matching `(--resume|--session)[[:space:]=]+[^[:space:]]+`.

**Assessment**: Correct regex. Consistent with `resume_session.sh`. **No issues.**

### 5.8 `stop_session.sh` — Agent inference (lines 93-97)

**Change**: Extended case patterns to include planner/reviewer for each agent.

**Assessment**: Correct. With F-1 fixed, session names always have lowercase roles, so the lowercase case patterns will match. **No issues.**

---

## 6. New Issues Check

Reviewed all changes for regressions or new issues introduced by the fixes:

1. **`tr` portability**: `tr '[:upper:]' '[:lower:]'` is POSIX-compliant and works on macOS (BSD tr) and Linux (GNU tr). No portability issue.

2. **`status.sh` fallback residual broadness**: The fallback `f"-{a}" in name or f"_{a}" in name` (lines 61-63) could still match workspace slugs containing agent-like substrings (e.g., `my-claude-project-creator-agy` would match `-claude` in the fallback). However, this is only a fallback — the primary `endswith` check (lines 56-59) handles all standard session names correctly. The fallback only activates for non-standard names where precise detection is inherently ambiguous. **Acceptable — no fix needed.**

3. **`status.sh` `name.endswith(f'-{a}')` check**: Line 57 checks for names ending with just `-claude`, `-agy`, etc. (without a role). This handles legacy sessions without role suffixes. Since `derive_session_name` always includes a role, new sessions won't match this, but it's correct for backward compatibility. **No issue.**

4. **`reconcile.sh` env marker `split()` on spaces**: `env_output.split()` could break if `MAM_MANAGED` value contains spaces. Edge case, unlikely in practice (workspace paths with spaces are rare in this context). **Acceptable — noted but no fix needed.**

**No new issues or regressions found.**

---

## 7. Positive Findings

1. **F-1 fix is correct and complete** — `tr '[:upper:]' '[:lower:]'` in `derive_session_name` ensures all session names have lowercase roles, matching all downstream pattern matching.
2. **F-2 fix improves hermes status precision** — `SELECT 1 FROM sessions WHERE id=?` provides per-session verification instead of just checking file existence.
3. **F-4 fix improves agent detection** — `endswith` loop with role-agent suffixes is precise; fallback is more targeted than previous `'claude' in name`.
4. **`status.sh` cline support** — New cline branch with per-session file check `{u}/{u}.json` completes agent coverage.
5. **`status.sh` backward compatibility** — `name.endswith(f'-{a}')` check handles legacy sessions without role suffixes.
6. **`verify_session_uuid` CWD verification** — Security improvement preventing cross-workspace session hijacking.
7. **`create_session.sh` agent validation** — Defensive preflight check.
8. **`create_session.sh` `CMD_FULL` wrapper fix** — Correct removal of `--session-id` for wrapper path.
9. **`orc_onboard.sh` hermes detection** — Correct regex matching.
10. **`reconcile.sh` role extraction** — Correct nested loop and `role` field in entry.
11. **`reconcile.sh` env fallback** — Good defensive measure for non-standard session names.
12. **Shim sync** — `.mam/shim/herdr` kind detection is byte-identical to `lib.sh`.
13. **Backward compatibility** — `derive_session_name` 2-arg calls still work (default role `"creator"`).

---

## 8. Summary

This changeset addresses all actionable findings from the prior review (job `2ac5b3df`):

- **F-1 (CRITICAL)**: Fixed. `derive_session_name` now lowercases the role parameter, ensuring session names always use lowercase roles. The two previously failing tests (`test_sanity.py::test_create_session_full` and `test_tier2_component.py::test_comp_create_sqlite_tables_created`) now PASS.
- **F-2 (Low)**: Fixed. `status.sh` hermes branch now queries the database for per-session verification.
- **F-4 (Low)**: Fixed. `status.sh` uses precise `endswith` patterns for agent detection.
- **F-3 (Low)** and **F-5 (Info)**: Accepted as-is — no fix needed (acceptable trade-offs).

The changeset also adds new positive features:
- Cline support in `status.sh` `resume_on_disk`
- Hermes support in `orc_onboard.sh`
- CWD verification in `verify_session_uuid` for hermes and cline
- Agent validation in `create_session.sh`
- `CMD_FULL` fix for wrapper path
- Role extraction in `reconcile.sh`

**No new issues or regressions found.** All 99 confirmed tests PASS (including the 2 that previously failed). Syntax validation passes for all 6 modified files. Shim sync is maintained.

The changeset is ready for commit.

---

[VERDICT: PASS]