AGENT SKILL

role-coherence-protocol

Audit a composed role against the user's project context for contradictions and interference, producing free-form findings with proposed fixes. Use when launched as a role-auditing role (role-auditor, role-judge, or sibling) whose first user message contains the target role's composed text plus the project context to audit against it.

License 许可
MIT
所属仓库
muratovv/ai-hats
最近更新
2026-11-05
Stars
★ 3
Forks
1

01 前言 Front Matter

name
role-coherence-protocol
license
MIT
description
Audit a composed role against the user's project context for contradictions and interference, producing free-form findings with proposed fixes. Use when launched as a role-auditing role (role-auditor, role-judge, or sibling) whose first user message contains the target role's composed text plus the project context to audit against it.

03 SKILL.md 正文

Role Coherence Protocol

Audit method for any role-auditing role (role-auditor, role-judge, and future role-audit family). Verifies that a target role's composed instructions are internally consistent and do not interfere with the user's project files (./CLAUDE.md, .agent/ai-hats/user-rules/*.md). Run by ai-hats reflect role <name> and ai-hats reflect roles.

The skill defines what to audit and how to structure findings. Mutation policy and dialogue contract are set by the composing role's base trait — base-auditor (no CLI / no dialogue) vs base-judge (CLI ops + HITL dialogue, governed by judge-role-protocol).

When to Use

You were launched as a role-auditing role (role-auditor, role-judge, or sibling). The first user message contains the target role's composed text plus the project context that should be audited against it. Apply this protocol end-to-end and deliver the report per §Step 3 — the delivery branch (markers vs Write tool) is chosen by your composing base trait.

Inputs

The first user message points at three groups of files on disk. Read them via the Read / Glob tools — do not ask the user to paste content; the harness has already materialized everything.

1. Target role composition (layered)

Path: provided to you in the supervisor's first message via the {composed_dir} interpolation — use that path verbatim. Do not reconstruct it. Typical shape (per-session): <project>/<ai_hats_dir>/sessions/runs/pipeline_runs/reflect-role/<session_id>/composed/<target_role>/. Layout:

  • manifest.yaml — start here. Contains name, identity (the expression composed, e.g. maintainer + leader), priorities, the names of bundled traits / rules / skills, and trace: one row per term with brought_by — the role, the trait, or an override layer (overrides::global from ~/.ai-hats/customizations.yaml, overrides::project from the project's ai-hats.yaml) — and removed_by for a term an override dropped. Attribution is a chain: a rule's row names the trait that declares it, and the trait's row names who brought the trait — follow brought_by until it reaches the role or an override layer.
  • role-injection.md — the role's own injection text (if non-empty).
  • overlay-injection.md — each override layer's injection_append, global then project (if any).
  • traits/<name>.md — per-trait injection text (deduped: a trait whose text already appeared elsewhere is omitted but still listed in the manifest).
  • rules/<name>.md — full body of each bundled rule.md.
  • skills/<name>.md — full body of each bundled SKILL.md.

This is the composition the user's session runs — the built-in role with the user's overrides applied, the same thing ai-hats config show-prompt --role <name> renders — broken down by source so every instruction traces back to the component and the layer that brought it.

2. Project CLAUDE.md

Path: <project_dir>/CLAUDE.md — user-owned root prompt. May not exist on fresh projects.

3. User rules overlay

Path: <project_dir>/.agent/ai-hats/user-rules/*.md — project-specific overrides. Use Glob to enumerate. Directory may be empty or absent.

If a group is empty / missing, note it and continue (a missing user-rules layer is normal for fresh projects).

Procedure

Step 1 — Read the manifest, then walk components

Read <composed_dir>/manifest.yaml first to get the structure (priorities + component names). Then:

  • Read role-injection.md (and overlay-injection.md if present) for the role's intent.
  • For every name in composition.traits, read traits/<name>.md.
  • For every name in composition.rules, read rules/<name>.md.
  • For every name in composition.skills, read skills/<name>.md.
  • Read <project_dir>/CLAUDE.md if it exists.
  • Glob <project_dir>/.agent/ai-hats/user-rules/*.md and read each.

Extract concrete instructions / forbidden patterns / required behaviours from each component. Track them by source name — you'll cite the source in every finding.

Step 2 — Find conflicts

Walk the audit view component-by-component (use the manifest as the checklist). For each pair of components, ask: do their instructions agree? Categories of conflict to flag:

  • Forbidden-token conflicts. A trait or skill recommends a tool that a bundled rule forbids (canonical example: a ## SHELL trait recommends rg/fd while dev_rule_tool_call_hygiene forbids them).
  • Internal contradictions. Two instructions inside the role contradict each other (e.g. one trait says "be terse", another says "always include rationale").
  • User-context interference. A role instruction conflicts with something the user wrote in their CLAUDE.md or user-rules overlay, or with a term whose trace chain ends in overrides::global / overrides::project — those are the user's context too. Route the fix by where the chain ends: at the role, a library fix; at an override layer, a change to the customization.
  • Off-purpose components. A bundled trait/rule/skill is unrelated to the role's stated purpose (priorities + role injection). Flag as a finding so the role author can drop it or justify it.

For each conflict capture:

  • Source — name the component(s) involved (e.g. trait: dev::shell, rule: dev_rule_tool_call_hygiene, skill: judge-protocol, role injection, user-rules:<filename>).
  • Location — section heading or short quote of each side.
  • Nature — what contradicts what, in one sentence.
  • Recommendation — concrete fix proposal (rephrase, drop, override, split into role variant, etc.).

Step 3 — Write the report

Delivery decision (read first, then template):

Composed with `base-auditor`? → emit between BEGIN_REFLECT / END_REFLECT.
Composed with `base-judge`?    → Write tool to declared report path. No markers.

Pick the branch matching your composition and follow only that branch below. The wrong branch ships markers the pipeline does not extract (or vice versa).

Report template (used by both branches):

# Role coherence report — <target_role> · <UTC ts>

## Findings
1. **<short label>** — <Source(s)>. <Location>. <Nature>.
   **Fix:** <recommendation>.
2. ...

## Notes
<free-form observations, structural smell, anything outside finding scope>

Empty findings are valid — write (none) under ## Findings and explain why in ## Notes (e.g. "role contains only trait-analyst-base, nothing to conflict with").

Branch A — base-auditor (batch, no pipeline interaction): emit the report between BEGIN_REFLECT / END_REFLECT markers in your output. The pipeline's extract_marker + save_artifact steps capture and persist it. Used by future batch QA gates; no current pipeline relies on this path.

Branch B — base-judge (HITL pipeline / manual interactive): use the Write tool to save the report directly to the path declared in your role injection (typically <ai_hats_dir>/sessions/retros/role-coherence/<UTC-ISO-ts>-<target>.md). Do NOT emit BEGIN_REFLECT / END_REFLECT markers — the pipeline does not extract them on this path. Entered through ai-hats reflect role or manual ai-hats execute --role role-judge.

Edge Cases

  • Empty user context. If both ./CLAUDE.md and user-rules/ are empty, audit the role for self-consistency only and note in ## Notes that no project context was available.
  • Same recommendation surfaces multiple places. Group by Fix in ## Findings; do not list duplicates.
  • Missing target role. If the target-role block is empty, fail loudly: write a single ## Findings entry pointing to the empty composition and exit.

Scope

Mutation policy is defined by your composing base trait, not by this skill. See the level declared there for what is allowed:

  • base-auditor → L0 (audit only): no CLI, no dialogue, single report artifact. Source-file edits unavailable.
  • base-judge → L1 (analysis + ack'd mutations): CLI verbs per judge-role-protocol whitelist, HITL dialogue, file tasks via rack create. Source-file edits gated by L2 activation (supervisor-authorized; see base-judge §L2).

This skill defines the audit method and report shape only. For default L0 / L1 behaviour, defer to the base trait. For L2 source-file edits, defer to base-judge §L2.

The pipeline's save_artifact step persists your report (Branch A) or your direct Write lands it (Branch B) — emitting clean markdown is your primary deliverable.

04 同仓库更多 Skills

muratovv
muratovv/ai-hats

tool-evaluation-protocol

Time-bounded protocol for evaluating new tools, libraries, or methodologies before adoption. Use when evaluating a candidate dependency for the project, researching a methodology (e.g. ML/LLM frameworks, testing approaches), or following up on a hype-driven recommendation.

★ 3
muratovv
muratovv/ai-hats

systematic-debugging

4-phase bug-fix protocol (evidence, pattern, hypothesis, verify). Use when investigating any error, failure, or unexpected behavior, handling bug reports from users or monitoring, or diagnosing test failures with non-obvious causes.

★ 3
muratovv
muratovv/ai-hats

skill-template

Canonical template and validation guide for ai-hats skills. Use when creating a new skill, reviewing an existing one for structural compliance, or deciding which pattern fits a new behavior.

★ 3
muratovv
muratovv/ai-hats

skill-optimization

Audit and refactor library components to eliminate redundancy and staleness. Use during periodic library maintenance, after adding multiple new skills or rules, when a role's token budget is too high, or after retrospectives identify component issues.

★ 3
muratovv
muratovv/ai-hats

silent-fallback-gate

PreToolUse hook — refuses an Edit or Write that adds an inert broad except. Use when a Python edit was blocked for a silent fallback.

★ 3
muratovv
muratovv/ai-hats

retro-to-framework

Convert an observation about agent behavior — from a retrospective or from a single incident — into a framework-level change (hook, rule, skill, skill update). Use after a retrospective identifies problems that are not project-specific, after an incident where an agent misapplied a component it had read, when CLAUDE.md band-aids accumulate (more than 3 per-project rules that could be generic), or when the same problem recurs across multiple projects.

★ 3