{"slug":"team-repair","title":"team-repair","summary":"Re-index OKF v0.2 index.md/log.md files, derive CDR.md, rebuild .skills.json and AGENTS.md in team-ai-directives, migrate v0.1→v0.2 frontmatter, scan for rule conflicts, and verify directive freshness. Use when indexes are inconsistent, orphans are detected, after bulk changes, o","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-06T17:21:39.560369Z","repo":{"url":"https://github.com/tikalk/adlc-team-skills","stars":139,"forks":1,"license":"MIT","updatedAt":"2026-09-30T13:59:46Z"},"bodyHtml":"<hr>\n<h2>name: team-repair\ndescription: Re-index OKF v0.2 index.md/log.md files, derive CDR.md, rebuild .skills.json and AGENTS.md in team-ai-directives, migrate v0.1→v0.2 frontmatter, scan for rule conflicts, and verify directive freshness. Use when indexes are inconsistent, orphans are detected, after bulk changes, or for periodic team AI directives health validation.\ndisable-model-invocation: true</h2>\n<h1>team-repair</h1>\n<h2>Overview</h2>\n<p>Re-indexes OKF v0.2 artifacts (<code>index.md</code>, <code>log.md</code>), derives the flat <code>CDR.md</code> inject, rebuilds <code>.skills.json</code> and <code>AGENTS.md</code> in team-ai-directives to fix inconsistencies, detect orphaned files, and auto-repair issues. Migrates OKF v0.1 frontmatter to v0.2 on every run (always-on, no opt-out). Begins with a health-check phase (Phase 0) that verifies the directives framework is installed, configured, and aligned before performing any repairs.</p>\n<p><strong>Input</strong>: team-ai-directives repository</p>\n<p><strong>Output</strong>:\n0. Health check report (7 checks: team AI directives configured, context modules exist, skills registry, OKF log tracking, constitution alignment, OKF v0.2 type field presence, project AGENTS.md directive)</p>\n<ol>\n<li>Repaired AGENTS.md (if missing or corrupted)</li>\n<li>Migrated all context module frontmatter from OKF v0.1 to v0.2 (always-on)</li>\n<li>Rebuilt per-directory <code>index.md</code> files (OKF §8 catalog)</li>\n<li>Rebuilt per-directory <code>log.md</code> files (OKF §9 audit trail)</li>\n<li>Derived <code>CDR.md</code> flat table from <code>index.md</code> files (for team-boot system prompt injection)</li>\n<li>Rebuilt .skills.json manifest from skills/</li>\n<li>Auto-added OKF v0.2 YAML frontmatter to orphan context modules</li>\n<li>Auto-generated .skills.json entries for orphan skills</li>\n<li>Conflict scan across rules (creates conflict CDRs if issues found)</li>\n<li>Freshness verification (updates <code>verified</code> timestamps, flags stale directives)</li>\n<li>Summary report of all repairs</li>\n</ol>\n<p>You are acting as an <strong>Index Repair Specialist</strong> ensuring team-ai-directives indexes are consistent and complete. Your role involves:</p>\n<ul>\n<li><strong>Verifying</strong> health checks before repair (Phase 0)</li>\n<li><strong>Scanning</strong> context_modules/ and skills/ directories</li>\n<li><strong>Detecting</strong> orphan files (missing frontmatter/manifest entries)</li>\n<li><strong>Auto-repairing</strong> issues by generating missing metadata</li>\n<li><strong>Rebuilding</strong> index files to reflect actual content</li>\n<li><strong>Reporting</strong> all changes made</li>\n</ul>\n<h3>Repair Targets</h3>\n<table>\n<thead>\n<tr>\n<th>Target</th>\n<th>Location</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>AGENTS.md</strong></td>\n<td><code>{TEAM_AI_DIRECTIVES}/AGENTS.md</code></td>\n<td>Main instruction file for AI agents</td>\n</tr>\n<tr>\n<td><strong>index.md</strong></td>\n<td><code>{TEAM_AI_DIRECTIVES}/context_modules/**/index.md</code></td>\n<td>OKF §8 per-directory catalogs (progressive disclosure)</td>\n</tr>\n<tr>\n<td><strong>log.md</strong></td>\n<td><code>{TEAM_AI_DIRECTIVES}/context_modules/**/log.md</code></td>\n<td>OKF §9 per-directory audit trails</td>\n</tr>\n<tr>\n<td><strong>CDR.md</strong></td>\n<td><code>{TEAM_AI_DIRECTIVES}/CDR.md</code></td>\n<td>Derived flat table for team-boot system prompt injection (auto-generated from index.md files)</td>\n</tr>\n<tr>\n<td><strong>.skills.json</strong></td>\n<td><code>{TEAM_AI_DIRECTIVES}/.skills.json</code></td>\n<td>Skills manifest registry</td>\n</tr>\n</tbody>\n</table>\n<h2>When to Use</h2>\n<h3>User Input</h3>\n<pre><code>$ARGUMENTS\n</code></pre>\n<p>You <strong>MUST</strong> consider the user input before proceeding (if not empty).</p>\n<p><strong>Examples of User Input</strong>:</p>\n<ul>\n<li><code>\"\"</code> - Repair all three indexes (default)</li>\n<li><code>\"--dry-run\"</code> - Report only, don't write changes</li>\n<li><code>\"--index-only\"</code> - Only rebuild OKF index.md + log.md + derive CDR.md</li>\n<li><code>\"--skills-only\"</code> - Only repair .skills.json</li>\n<li><code>\"--agents-only\"</code> - Only repair AGENTS.md</li>\n<li>Empty input: Repair all indexes with auto-fix (includes v0.1→v0.2 migration)</li>\n</ul>\n<h3>Flags</h3>\n<table>\n<thead>\n<tr>\n<th>Flag</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>--dry-run</code></td>\n<td>Report only, don't write changes</td>\n</tr>\n<tr>\n<td><code>--health-only</code></td>\n<td>Run Phase 0 health check only, then stop.</td>\n</tr>\n<tr>\n<td><code>--validate</code></td>\n<td>Run conflict scan + freshness verification only (Phases 8-9)</td>\n</tr>\n<tr>\n<td><code>--conflicts</code></td>\n<td>Scan for rule conflicts only</td>\n</tr>\n<tr>\n<td><code>--freshness</code></td>\n<td>Verify directive freshness only</td>\n</tr>\n<tr>\n<td><code>--build-to-delete</code></td>\n<td>Run evals without directives to identify candidates for removal (Factor XII)</td>\n</tr>\n<tr>\n<td><code>--index-only</code></td>\n<td>Only rebuild OKF index.md + log.md + derive CDR.md</td>\n</tr>\n<tr>\n<td><code>--skills-only</code></td>\n<td>Only repair .skills.json</td>\n</tr>\n<tr>\n<td><code>--agents-only</code></td>\n<td>Only repair AGENTS.md</td>\n</tr>\n<tr>\n<td>(default)</td>\n<td>Repair all indexes + migrate v0.1→v0.2 + validate conflicts and freshness</td>\n</tr>\n</tbody>\n</table>\n<h2>Core Process</h2>\n<h3>Phase 0: Health Check</h3>\n<p><strong>Objective</strong>: Run a non-destructive health check against the team directives framework before proceeding with repairs. If any check returns <code>[FAIL]</code>, present the report and stop — the framework is not healthy enough to repair safely.</p>\n<p>Execute all seven checks below. Each check prints a status line. If any check is <code>[FAIL]</code>, abort repair.</p>\n<h4>Check 1: Team AI Directives Configured</h4>\n<ol>\n<li>Read <code>.adlc/init-options.json</code></li>\n<li>Verify <code>team_ai_directives</code> field exists and points to valid path</li>\n<li>Check the team AI directives path exists</li>\n</ol>\n<p>Output: <code>[OK]</code> or <code>[FAIL]</code> with reason</p>\n<h4>Check 2: Context Modules Exist</h4>\n<ol>\n<li>Read <code>.adlc/init-options.json</code> → get team AI directives path</li>\n<li>Verify:\n<ul>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/constitution.md</code></li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/personas/</code></li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/rules/</code></li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/examples/</code></li>\n</ul>\n</li>\n</ol>\n<p>Output: <code>[OK]</code> or <code>[FAIL]</code> with reason</p>\n<h4>Check 3: Skills Registry</h4>\n<ul>\n<li><code>{TEAM_AI_DIRECTIVES}/.skills.json</code> exists and is valid JSON</li>\n</ul>\n<p>Output: <code>[OK]</code> or <code>[FAIL]</code> with reason</p>\n<h4>Check 4: OKF Log Tracking</h4>\n<ul>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/rules/log.md</code> exists</li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/personas/log.md</code> exists</li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/examples/log.md</code> exists</li>\n<li><code>{TEAM_AI_DIRECTIVES}/CDR.md</code> exists (derived artifact)</li>\n</ul>\n<p>Output: <code>[OK]</code> or <code>[FAIL]</code> with reason</p>\n<h4>Check 5: Constitution Alignment</h4>\n<ol>\n<li>Read team constitution from <code>{TEAM_AI_DIRECTIVES}/context_modules/constitution.md</code></li>\n<li>Locate project constitution: the project root (where <code>.adlc/</code> lives) → <code>{REPO_ROOT}/.adlc/memory/constitution.md</code></li>\n<li>If project constitution exists:\n<ul>\n<li>Check if it references team-ai-directives (e.g., \"Based on team-ai-directives\", \"Inherits from\")</li>\n<li>Check if team principles are present in project constitution (compare principle titles)</li>\n<li>Output:\n<ul>\n<li><code>[OK]</code> — Project constitution exists and inherits team principles</li>\n<li><code>[WARN]</code> — Project constitution exists but missing team inheritance</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>If project constitution doesn't exist:\n<ul>\n<li><code>[INFO]</code> — Project constitution doesn't exist yet (first-time setup)</li>\n</ul>\n</li>\n</ol>\n<h4>Check 6: OKF v0.2 Conformance</h4>\n<ol>\n<li>Scan all <code>.md</code> files in <code>context_modules/</code> (excluding <code>index.md</code>, <code>log.md</code>)</li>\n<li>Parse YAML frontmatter from each file</li>\n<li>Verify <code>type</code> field is present and has a valid value:\n<ul>\n<li>Valid types: <code>Constitution</code>, <code>Persona</code>, <code>Rule</code>, <code>Example</code>, <code>Skill</code></li>\n</ul>\n</li>\n<li>Verify OKF v0.2 fields (migrate if v0.1 detected):\n<ul>\n<li><code>generated: { by, at }</code> present (not legacy <code>timestamp</code>)</li>\n<li><code>verified</code> is a list format (not bare string)</li>\n<li><code>status</code> present (e.g., <code>stable</code>, <code>draft</code>, <code>deprecated</code>)</li>\n<li><code>stale_after</code> present (e.g., <code>180d</code>)</li>\n</ul>\n</li>\n<li>Output:\n<ul>\n<li><code>[OK]</code> — All concept files have valid <code>type</code> fields and v0.2 families</li>\n<li><code>[WARN]</code> — Some files missing v0.2 fields or still carry v0.1 fields (will be migrated in Phase 4)</li>\n</ul>\n</li>\n</ol>\n<h4>Check 7: Project AGENTS.md Directive</h4>\n<ol>\n<li>Read <code>{REPO_ROOT}/AGENTS.md</code> (the project-level agent instructions file)</li>\n<li>Check if it contains the <code>&lt;!-- TEAM_AI_DIRECTIVES START --&gt;</code> marker</li>\n<li>If the marker exists, verify the managed section includes:\n<ul>\n<li>A <code>team-boot</code> invocation directive</li>\n<li>A reference to team AI directives context (constitution, CDR index)</li>\n</ul>\n</li>\n<li>Output:\n<ul>\n<li><code>[OK]</code> — Project AGENTS.md contains a valid team AI directives managed section</li>\n<li><code>[WARN]</code> — Project AGENTS.md exists but is missing the managed section (agents won't auto-invoke <code>team-boot</code>)</li>\n<li><code>[INFO]</code> — Project AGENTS.md doesn't exist yet (first-time setup)</li>\n</ul>\n</li>\n</ol>\n<h4>Health Check Output</h4>\n<p>Print verification status for each check:</p>\n<ul>\n<li><code>[OK]</code> — Check passed</li>\n<li><code>[FAIL]</code> — Check failed with reason (abort repair)</li>\n<li><code>[WARN]</code> — Check passed with warnings (non-blocking)</li>\n<li><code>[INFO]</code> — Informational only</li>\n</ul>\n<p>If any check is <code>[FAIL]</code>, print the report, set exit code 1, and <strong>STOP</strong>. Do not proceed to Phase 1.</p>\n<h4>Health Check Red Flags</h4>\n<ul>\n<li><strong><code>[FAIL]</code> on Check 1 or Check 2</strong>: the directives framework is effectively absent — agents have nothing to inherit from. Stop and reinstall before repairing.</li>\n<li><strong>Team AI Directives path resolves outside the repo</strong> or to a temp/scratch location: the project is pointing at a transient or shared team AI directives that may vanish or diverge.</li>\n<li><strong><code>{TEAM_AI_DIRECTIVES}/.skills.json</code> is missing or not valid JSON</strong>: skill discovery is broken; agents cannot find team skills even if the files exist.</li>\n<li><strong>Project constitution exists but shows no team inheritance</strong> (<code>[WARN]</code> on Check 5): the project was bootstrapped without the team AI directives, or the constitution was hand-edited and the inheritance markers were removed.</li>\n<li><strong>Multiple checks return <code>[WARN]</code> simultaneously</strong>: systemic drift, usually from a moved <code>.adlc/</code> directory or a reconfigured team AI directives path. Treat as a <code>[FAIL]</code>-equivalent and re-init.</li>\n</ul>\n<hr>\n<h3>Phase 1: Environment Setup</h3>\n<p><strong>Objective</strong>: Resolve paths and validate infrastructure</p>\n<p>Run <code>$(dirname \"$0\")/team-helpers.sh --json</code> (or the PowerShell equivalent) to resolve paths and parse JSON output:</p>\n<pre><code>{\n  \"REPO_ROOT\": \"/path/to/project\",\n  \"TEAM_AI_DIRECTIVES\": \"/path/to/team-ai-directives\",\n  \"BRANCH\": \"current-branch\"\n}\n</code></pre>\n<p><code>{REPO_ROOT}</code> is the project root (where <code>.adlc/</code> lives). Subsequent references use <code>{REPO_ROOT}</code>.</p>\n<h3>Phase 2: Validate Environment</h3>\n<p><strong>Objective</strong>: Ensure team-ai-directives is configured</p>\n<p>Check if TEAM_AI_DIRECTIVES has a value from script output.</p>\n<p>If empty, <strong>STOP</strong>:</p>\n<pre><code>Team AI directives repository not configured.\nRun: /team-setup\nOr set: export TEAM_AI_DIRECTIVES=/path/to/team-ai-directives\n</code></pre>\n<h3>Phase 3: Repair AGENTS.md</h3>\n<p><strong>Objective</strong>: Ensure AGENTS.md exists with required structure</p>\n<p><strong>Skip if</strong>: <code>--index-only</code> or <code>--skills-only</code> flag provided</p>\n<h4>Step 1: Check AGENTS.md Exists</h4>\n<pre><code>test -f \"{TEAM_AI_DIRECTIVES}/AGENTS.md\" &amp;&amp; echo \"EXISTS\" || echo \"MISSING\"\n</code></pre>\n<h4>Step 2: Validate Structure (if exists)</h4>\n<p>Required sections:</p>\n<ul>\n<li><code># Agent Instructions</code> (title)</li>\n<li><code>## Structure</code></li>\n<li><code>## Loading Order</code></li>\n<li><code>## Functional Categories (Rules)</code></li>\n<li><code>## Using Skills</code></li>\n<li><code>## CDR.md</code></li>\n</ul>\n<p>Check for each required section:</p>\n<pre><code>grep -q \"^# Agent Instructions\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\ngrep -q \"^## Structure\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\ngrep -q \"^## Loading Order\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\ngrep -q \"^## Functional Categories\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\ngrep -q \"^## Using Skills\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\ngrep -qiE \"##.*CDR\\.md\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\n</code></pre>\n<h4>Step 3: Auto-Repair</h4>\n<table>\n<thead>\n<tr>\n<th>Status</th>\n<th>Action</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Missing</strong></td>\n<td>Create from <code>templates/agents-template.md</code></td>\n</tr>\n<tr>\n<td><strong>Corrupted</strong> (missing sections)</td>\n<td>Overwrite with template</td>\n</tr>\n<tr>\n<td><strong>Valid</strong></td>\n<td>No changes</td>\n</tr>\n</tbody>\n</table>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### AGENTS.md Status: {MISSING|CORRUPTED|VALID}\n\n**Action**: {Would create|Would overwrite|No changes needed}\n</code></pre>\n<p>Otherwise, execute repair:</p>\n<pre><code>cp \"templates/agents-template.md\" \"{TEAM_AI_DIRECTIVES}/AGENTS.md\"\n</code></pre>\n<h4>Step 4: Track Results</h4>\n<p>Store for summary:</p>\n<pre><code>{\n  \"agents_md\": {\n    \"status\": \"VALID|CREATED|OVERWRITTEN\",\n    \"action\": \"No changes|Created from template|Re-created from template\"\n  }\n}\n</code></pre>\n<h4>Step 5: Inject Project-Level AGENTS.md Directive</h4>\n<p>After repairing the team AI directives' own <code>AGENTS.md</code>, also ensure the <strong>project-level</strong> <code>AGENTS.md</code> (at <code>{REPO_ROOT}/AGENTS.md</code>) contains the team-boot strict-compliance directive. This is what tells agents to invoke <code>team-boot</code> at session start.</p>\n<p>If Check 8 returned <code>[WARN]</code> or <code>[INFO]</code>, run the injection:</p>\n<pre><code>bash \"$(dirname \"$0\")/team-helpers.sh\" --inject-agents \"{REPO_ROOT}\"\n# or: pwsh \"$(Split-Path $PSCommandPath -Parent)/team-helpers.ps1\" -InjectAgents \"{REPO_ROOT}\"\n</code></pre>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### Project AGENTS.md Status: {WARN|INFO}\n\n**Action**: Would inject team AI directives managed section into {REPO_ROOT}/AGENTS.md\n</code></pre>\n<p>Otherwise, execute the injection. The function is idempotent — if the managed section already exists (between <code>&lt;!-- TEAM_AI_DIRECTIVES START --&gt;</code> and <code>&lt;!-- TEAM_AI_DIRECTIVES END --&gt;</code> markers), it replaces the section in place rather than duplicating.</p>\n<p>Store for summary:</p>\n<pre><code>{\n  \"project_agents_md\": {\n    \"status\": \"VALID|INJECTED|UPDATED\",\n    \"action\": \"No changes|Created with managed section|Updated managed section\"\n  }\n}\n</code></pre>\n<h3>Phase 4: Scan Context Modules for CDR.md Reindex</h3>\n<p><strong>Objective</strong>: Find all context modules and extract metadata</p>\n<p><strong>Skip if</strong>: <code>--skills-only</code> or <code>--agents-only</code> flag provided</p>\n<h4>Step 1: Find All Context Module Files</h4>\n<pre><code>find \"{TEAM_AI_DIRECTIVES}/context_modules/rules\" -name \"*.md\" -type f 2&gt;/dev/null\nfind \"{TEAM_AI_DIRECTIVES}/context_modules/personas\" -name \"*.md\" -type f 2&gt;/dev/null\nfind \"{TEAM_AI_DIRECTIVES}/context_modules/examples\" -name \"*.md\" -type f 2&gt;/dev/null\n</code></pre>\n<p>Skip <code>constitution.md</code> (not indexed in CDR.md).</p>\n<h4>Step 2: Extract YAML Frontmatter</h4>\n<p>For each file, parse YAML frontmatter (OKF v0.2 form after migration):</p>\n<pre><code>---\ntype: Rule\ntitle: Python error handling\ndescription: Python error handling patterns and best practices\ntags: [python, error-handling]\nresource: ./context_modules/rules/python/error-handling.md\ngenerated: { by: agent:legacy, at: 2026-04-15T00:00:00Z }\nid: rule-python-error-handling\ncdr_ref: CDR-2026-001\ncreated: 2026-04-15\nverified:\n  - { by: process:team-repair, at: 2026-05-18T00:00:00Z }\nstatus: stable\nstale_after: 180d\nsources:\n  - id: commit-abc123\n    resource: src/errors.py\n    title: Error handling implementation\n---\n</code></pre>\n<p>Extraction logic:</p>\n<ol>\n<li>Read file content</li>\n<li>Check if starts with <code>---</code></li>\n<li>Parse YAML between <code>---</code> markers</li>\n<li>Extract: <code>id</code>, <code>cdr_ref</code>, <code>created</code>, <code>type</code>, <code>title</code>, <code>description</code>, <code>tags</code>, <code>generated.at</code>, <code>verified</code> (latest <code>at</code>), <code>status</code></li>\n</ol>\n<h4>Step 2a: Build CDR Lookup from Existing CDR.md</h4>\n<p>Before generating new frontmatter, read the existing CDR.md to find pre-existing CDR references for orphan files.</p>\n<p>Parse the CDR.md index table to build a mapping of <code>{relative_file_path → cdr_ref}</code>:</p>\n<pre><code># Read existing CDR.md and extract file path -&gt; CDR reference mappings\nCDR_LOOKUP=()\nif [[ -f \"{TEAM_AI_DIRECTIVES}/CDR.md\" ]]; then\n    while IFS='|' read -r _ id module _ _ _ _ _; do\n        id=\"${id// /}\"\n        module=\"${module// /}\"\n        if [[ -n \"$id\" &amp;&amp; -n \"$module\" &amp;&amp; \"$id\" =~ ^CDR- ]]; then\n            CDR_LOOKUP[\"$module\"]=\"$id\"\n        fi\n    done &lt; &lt;(grep \"| CDR-\" \"{TEAM_AI_DIRECTIVES}/CDR.md\")\nfi\n</code></pre>\n<p>This creates an associative array:</p>\n<pre><code>context_modules/rules/style-guides/java/google_style_guide.md → CDR-2026-023\n</code></pre>\n<h4>Step 3: Detect Orphans (No Frontmatter)</h4>\n<p>Files with <code>.md</code> extension but no YAML frontmatter.</p>\n<p>For each orphan:</p>\n<ol>\n<li>Generate <code>id</code> from filename:\n<ul>\n<li>Strip the context type directory prefix (<code>rules/</code>, <code>personas/</code>, <code>examples/</code>)</li>\n<li>Remove <code>.md</code> extension, replace <code>/</code> with <code>-</code>, prepend type prefix</li>\n<li>Example: <code>rules/python/new-pattern.md</code> → strip <code>rules/</code> → <code>python/new-pattern.md</code> → <code>rule-python-new-pattern</code></li>\n<li>Example: <code>personas/architect.md</code> → strip <code>personas/</code> → <code>architect.md</code> → <code>persona-architect</code></li>\n</ul>\n</li>\n<li>Determine context type from path:\n<ul>\n<li><code>rules/</code> → <code>Rule</code></li>\n<li><code>personas/</code> → <code>Persona</code></li>\n<li><code>examples/</code> → <code>Example</code></li>\n</ul>\n</li>\n<li>Compute the file's relative path from <code>TEAM_AI_DIRECTIVES</code> and look it up in <code>CDR_LOOKUP</code>:\n<ul>\n<li>If found, use the existing <code>cdr_ref</code></li>\n<li>If not found, set <code>cdr_ref: null</code></li>\n</ul>\n</li>\n<li>Generate <code>title</code> from filename (humanize the basename)</li>\n<li>Generate <code>description</code> from first paragraph or filename</li>\n<li>Generate <code>tags</code> from path segments (e.g., <code>rules/python/</code> → <code>[python]</code>)</li>\n<li>Set default metadata:\n<pre><code>type: {context-type}\ntitle: {generated-title}\ndescription: {generated-description}\ntags: {generated-tags}\nresource: {relative-path}\ngenerated: { by: agent:team-repair, at: {today}T00:00:00Z }\nid: {generated-id}\ncdr_ref: {from CDR_LOOKUP or null}\ncreated: {today}\nverified:\n  - { by: agent:team-repair, at: {today}T00:00:00Z }\nstatus: stable\nstale_after: 180d\n</code></pre>\n</li>\n</ol>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### Orphan Files Detected\n\n| File | Generated ID | Existing CDR Ref | Action |\n|------|--------------|-----------------|--------|\n| rules/python/new-pattern.md | rule-python-new-pattern | CDR-2026-023 | Would add frontmatter (preserving CDR ref) |\n| personas/architect.md | persona-architect | null | Would add frontmatter |\n</code></pre>\n<p>Otherwise, auto-fix:</p>\n<ol>\n<li>Read file content</li>\n<li>Prepend generated YAML frontmatter</li>\n<li>Write back to file</li>\n</ol>\n<h4>Step 3b: Migrate v0.1 Frontmatter to v0.2 (Always-On)</h4>\n<p>For every <code>.md</code> file in <code>context_modules/</code> (excluding <code>index.md</code>, <code>log.md</code>) that has existing frontmatter, detect and migrate v0.1 fields to v0.2. This runs on every <code>team-repair</code> invocation — no flag, no opt-out.</p>\n<p><strong>Migration rules</strong> (idempotent — skip if already v0.2):</p>\n<table>\n<thead>\n<tr>\n<th>Detection</th>\n<th>Action</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>timestamp:</code> present, <code>generated:</code> absent</td>\n<td>Rewrite to <code>generated: { by: agent:legacy, at: &lt;timestamp value&gt; }</code>, delete <code>timestamp</code></td>\n</tr>\n<tr>\n<td><code>timestamp:</code> present, <code>generated:</code> present</td>\n<td>Delete <code>timestamp</code> (v0.2 takes precedence)</td>\n</tr>\n<tr>\n<td><code>verified:</code> is a bare string (not a list)</td>\n<td>Rewrite to <code>verified: [{ by: process:team-repair, at: &lt;value&gt;T00:00:00Z }]</code></td>\n</tr>\n<tr>\n<td><code>evidence:</code> present with entries</td>\n<td>Map each entry to <code>sources[]</code> entry (<code>id</code>, <code>resource</code>, <code>title</code>), delete <code>evidence</code></td>\n</tr>\n<tr>\n<td><code>evidence: []</code> (empty list)</td>\n<td>Delete field, omit <code>sources</code></td>\n</tr>\n<tr>\n<td><code>modified:</code> present</td>\n<td>Delete (redundant with <code>generated.at</code>)</td>\n</tr>\n<tr>\n<td><code>age_days:</code> present</td>\n<td>Delete (derived at render time)</td>\n</tr>\n<tr>\n<td><code>status:</code> absent</td>\n<td>Add <code>status: stable</code></td>\n</tr>\n<tr>\n<td><code>stale_after:</code> absent</td>\n<td>Add <code>stale_after: 180d</code></td>\n</tr>\n<tr>\n<td><code>resource:</code> absent</td>\n<td>Add from file relative path</td>\n</tr>\n<tr>\n<td><code>generated</code> already present, no v0.1 fields</td>\n<td>Skip (already v0.2)</td>\n</tr>\n</tbody>\n</table>\n<p>Preserve custom fields (<code>id</code>, <code>cdr_ref</code>, <code>created</code>, <code>type</code>, <code>title</code>, <code>description</code>, <code>tags</code>) as-is per OKF §4.1.</p>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### v0.1 → v0.2 Migration Preview\n\n| File | Fields Migrated | Fields Added | Fields Removed |\n|------|----------------|--------------|----------------|\n| rules/security/sql_injection_prevention.md | timestamp→generated, verified→list | status, stale_after, resource | modified, age_days, evidence |\n</code></pre>\n<p>Otherwise, rewrite frontmatter in place for each file.</p>\n<h4>Step 4: Build Context Module Index</h4>\n<p>Create index structure:</p>\n<pre><code>{\n  \"context_modules\": [\n    {\n      \"file\": \"context_modules/rules/python/error-handling.md\",\n      \"id\": \"rule-python-error-handling\",\n      \"cdr_ref\": \"CDR-2026-001\",\n      \"type\": \"Rule\",\n      \"created\": \"2026-04-15\",\n      \"generated_at\": \"2026-04-15T00:00:00Z\",\n      \"verified_at\": \"2026-05-18T00:00:00Z\",\n      \"status\": \"stable\",\n      \"stale_after\": \"180d\",\n      \"descriptor\": \"Python error handling patterns and best practices\"\n    }\n  ],\n  \"orphans\": [\n    {\n      \"file\": \"context_modules/rules/python/new-pattern.md\",\n      \"id\": \"rule-python-new-pattern\",\n      \"repaired\": true\n    }\n  ]\n}\n</code></pre>\n<h3>Phase 5: Scan Skills for .skills.json Reindex</h3>\n<p><strong>Objective</strong>: Find all skills and build manifest entries</p>\n<p><strong>Skip if</strong>: <code>--index-only</code> or <code>--agents-only</code> flag provided</p>\n<h4>Step 1: Find All Skill Directories</h4>\n<pre><code>find \"{TEAM_AI_DIRECTIVES}/skills\" -mindepth 1 -maxdepth 1 -type d\n</code></pre>\n<h4>Step 2: Check Each Skill</h4>\n<p>For each skill directory:</p>\n<ol>\n<li>Check <code>SKILL.md</code> exists (required)</li>\n<li>Check <code>.skills-entry.json</code> exists (optional)</li>\n<li>Parse SKILL.md for metadata</li>\n</ol>\n<h4>Step 3: Extract Skill Metadata</h4>\n<p>From <code>SKILL.md</code>:</p>\n<ul>\n<li><strong>Description</strong>: First paragraph after title</li>\n<li><strong>Categories</strong>: Look for <code>## Categories</code> or <code>## Trigger Keywords</code> section</li>\n<li><strong>Instruction Type</strong>: Look for <code>**Instruction Type**:</code> line</li>\n</ul>\n<h4>Step 4: Generate .skills.json Entry</h4>\n<pre><code>{\n  \"local:./skills/{skill-name}\": {\n    \"version\": \"1.0.0\",\n    \"description\": \"{extracted from SKILL.md first paragraph}\",\n    \"categories\": [\"{from SKILL.md}\"],\n    \"instruction_type\": \"{from SKILL.md}\"\n  }\n}\n</code></pre>\n<h4>Step 5: Detect Orphans</h4>\n<p>Skills with <code>SKILL.md</code> but no entry in <code>.skills.json</code>.</p>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### Orphan Skills Detected\n\n| Skill | Action |\n|-------|--------|\n| code-review | Would add to .skills.json |\n| deployment | Would add to .skills.json |\n</code></pre>\n<p>Otherwise, auto-generate entry.</p>\n<h4>Step 6: Detect Missing Files</h4>\n<p>Entries in <code>.skills.json</code> where skill directory doesn't exist.</p>\n<p>Auto-remove invalid entries.</p>\n<h4>Step 7: Build Skills Index</h4>\n<pre><code>{\n  \"skills\": [\n    {\n      \"name\": \"code-review\",\n      \"path\": \"skills/code-review/\",\n      \"has_skill_md\": true,\n      \"has_entry\": false,\n      \"repaired\": true\n    }\n  ],\n  \"missing_removed\": 1\n}\n</code></pre>\n<h3>Phase 6: Rebuild OKF index.md + log.md + Derive CDR.md</h3>\n<p><strong>Objective</strong>: Generate OKF v0.2 per-directory <code>index.md</code> (§8) and <code>log.md</code> (§9) files from scanned context modules, then derive the flat <code>CDR.md</code> table from the index.md data for team-boot system prompt injection.</p>\n<p><strong>Skip if</strong>: <code>--skills-only</code> or <code>--agents-only</code> flag provided</p>\n<h4>Step 1: Rebuild Per-Directory index.md (OKF §8)</h4>\n<p>For each subdirectory (<code>rules/</code>, <code>personas/</code>, <code>examples/</code>) and the <code>context_modules/</code> root, generate an <code>index.md</code> file in OKF §8 list format.</p>\n<p><strong><code>context_modules/index.md</code></strong> (root — carries <code>okf_version</code>):</p>\n<pre><code>---\nokf_version: \"0.2\"\n---\n\n# Context Modules\n\n* [Rules](rules/index.md) - Team rules and workflows\n* [Personas](personas/index.md) - Team personas\n* [Examples](examples/index.md) - Team examples\n</code></pre>\n<p><strong><code>context_modules/rules/index.md</code></strong> (per-type catalog):</p>\n<pre><code># Rules\n\n* [Prevent SQL Injection](security/sql_injection_prevention.md) - Standards for preventing SQL injection vulnerabilities across all languages\n* [Dependency Injection](architecture/dependency_injection.md) - Dependency injection patterns for maintainable code\n</code></pre>\n<p>Entries are derived from each module's frontmatter <code>title</code> and <code>description</code>. Sort alphabetically by title within each directory. If a module lacks <code>description</code>, derive from first body paragraph.</p>\n<p>Personas and Examples follow the same pattern with <code># Personas</code> and <code># Examples</code> headings.</p>\n<h4>Step 2: Rebuild Per-Directory log.md (OKF §9)</h4>\n<p>For each subdirectory, generate a <code>log.md</code> file in OKF §9 date-grouped format (newest first).</p>\n<p><strong><code>context_modules/rules/log.md</code></strong>:</p>\n<pre><code># Rules Update Log\n\n## 2026-05-23\n* **Creation**: Added [Dependency Injection](architecture/dependency_injection.md) — Dependency injection patterns for maintainable code. CDR: CDR-2026-008.\n* **Verification**: Verified [SQL Injection Prevention](security/sql_injection_prevention.md). CDR: CDR-2026-021.\n\n## 2026-05-21\n* **Creation**: Added [SQL Injection Prevention](security/sql_injection_prevention.md) — Standards for preventing SQL injection. CDR: CDR-2026-021.\n</code></pre>\n<p>Log entries are derived from:</p>\n<ol>\n<li>Git history: <code>git log --diff-filter=A --format=\"%ai %s\" -- &lt;file&gt;</code> for creation dates</li>\n<li>Frontmatter <code>verified</code> timestamps for verification entries</li>\n<li>Existing <code>log.md</code> content (preserve manual entries, append new)</li>\n</ol>\n<p><strong><code>context_modules/log.md</code></strong> (root — aggregate):</p>\n<pre><code># Context Modules Update Log\n\n## 2026-08-12\n* **Re-index**: Rebuilt all index.md and log.md files via /team-repair. Rules: {N} files, Personas: {N} files, Examples: {N} files.\n</code></pre>\n<h4>Step 3: Derive CDR.md (Flat Table for team-boot)</h4>\n<p>From the per-directory <code>index.md</code> data + module frontmatter, derive a flat <code>CDR.md</code> table for team-boot system prompt injection.</p>\n<p><strong><code>{TEAM_AI_DIRECTIVES}/CDR.md</code></strong>:</p>\n<pre><code># Context Directive Records (Derived Index)\n\n&gt; ⚠️ Auto-generated by `/team-repair`. Do not edit manually.\n&gt; Source of truth: `context_modules/*/index.md` + module frontmatter.\n&gt; Decision lifecycle (Accepted/Rejected) lives in project `.adlc/drafts/cdr/`.\n\n## CDR Index\n\n| ID | Path | Type | Description | Generated | Verified | Age | Status |\n|----|------|------|-------------|-----------|----------|-----|--------|\n| CDR-2026-021 | context_modules/rules/security/sql_injection_prevention.md | Rule | Standards for preventing SQL injection... | 2026-06-14 | 2026-05-21 | 46d | stable |\n| rule-frontend-routing | context_modules/rules/frontend/framework/frontend_routing.md | Rule | Client-side routing patterns... | 2026-06-15 | 2026-06-15 | 0d | stable |\n\n**Stats**: {N} entries | Last Updated: {date}\n</code></pre>\n<p><strong>Columns</strong>:</p>\n<ul>\n<li><code>ID</code>: <code>cdr_ref</code> from frontmatter (or <code>id</code> if <code>cdr_ref</code> is null)</li>\n<li><code>Path</code>: relative path from <code>TEAM_AI_DIRECTIVES</code></li>\n<li><code>Type</code>: <code>type</code> from frontmatter</li>\n<li><code>Description</code>: <code>description</code> from frontmatter (truncated to 80 chars)</li>\n<li><code>Generated</code>: <code>generated.at</code> date (YYYY-MM-DD)</li>\n<li><code>Verified</code>: latest <code>verified[].at</code> date (YYYY-MM-DD)</li>\n<li><code>Age</code>: days since <code>verified</code> date</li>\n<li><code>Status</code>: <code>status</code> from frontmatter (or <code>stable</code> if absent)</li>\n</ul>\n<h4>Step 4: Write Files</h4>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### OKF Files Preview\n\nWould write:\n- context_modules/index.md ({N} entries)\n- context_modules/log.md\n- context_modules/rules/index.md ({N} entries)\n- context_modules/rules/log.md\n- context_modules/personas/index.md ({N} entries)\n- context_modules/personas/log.md\n- context_modules/examples/index.md ({N} entries)\n- context_modules/examples/log.md\n- CDR.md ({N} derived entries)\n</code></pre>\n<p>Otherwise, write all 9 files.</p>\n<p><strong>Objective</strong>: Generate fresh .skills.json from scanned skills</p>\n<p><strong>Skip if</strong>: <code>--index-only</code> or <code>--agents-only</code> flag provided</p>\n<h4>Step 1: Generate Skills Manifest</h4>\n<pre><code>{\n  \"skills\": {\n    \"local:./skills/code-review\": {\n      \"version\": \"1.0.0\",\n      \"description\": \"Review code following team standards and best practices\",\n      \"categories\": [\"review\", \"quality\"],\n      \"instruction_type\": \"Review\"\n    }\n  }\n}\n</code></pre>\n<h4>Step 2: Write .skills.json</h4>\n<p>If <code>--dry-run</code>:</p>\n<pre><code>### .skills.json Preview\n\nWould write {N} skill entries\n</code></pre>\n<p>Otherwise:</p>\n<pre><code>cat &gt; \"{TEAM_AI_DIRECTIVES}/.skills.json\" &lt;&lt; 'EOF'\n{generated JSON}\nEOF\n</code></pre>\n<h3>Phase 8: Conflict Scanning</h3>\n<p><strong>Objective</strong>: Scan team-ai-directives rules for contradictions and overlaps.</p>\n<p><strong>Skip if</strong>: <code>--skills-only</code>, <code>--agents-only</code>, or <code>--freshness</code> flag provided.</p>\n<h4>Step 1: Load Rules and Constitution</h4>\n<p>Load:</p>\n<ul>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/constitution.md</code></li>\n<li><code>{TEAM_AI_DIRECTIVES}/context_modules/rules/**/*.md</code></li>\n</ul>\n<h4>Step 2: Detect Conflicts</h4>\n<p>Conflict levels:</p>\n<table>\n<thead>\n<tr>\n<th>Level</th>\n<th>Pattern</th>\n<th>Severity</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Direct Contradiction</td>\n<td><code>must X</code> vs <code>never X</code></td>\n<td>CRITICAL</td>\n</tr>\n<tr>\n<td>Implicit Contradiction</td>\n<td>Numeric/logical impossibility</td>\n<td>ERROR</td>\n</tr>\n<tr>\n<td>Exception Conflict</td>\n<td>Base rule vs exception</td>\n<td>WARNING</td>\n</tr>\n<tr>\n<td>Scope Overlap</td>\n<td>Overlapping rules</td>\n<td>INFO</td>\n</tr>\n<tr>\n<td>Constitution Conflict</td>\n<td>Rule vs principle</td>\n<td>CRITICAL</td>\n</tr>\n</tbody>\n</table>\n<p>Use <code>levelup-helpers.sh</code> conflict detection or implement inline:</p>\n<pre><code>skills/levelup/levelup-helpers.sh --conflicts \"$TEAM_AI_DIRECTIVES/context_modules/rules\"\n</code></pre>\n<h4>Step 3: Create Conflict CDRs</h4>\n<p>For each conflict, create a CDR in <code>{REPO_ROOT}/.adlc/drafts/cdr/CDR-{NNN}.md</code>:</p>\n<pre><code>## CDR-{NNN}: Resolve Rule Conflict: {title}\n\n### Status\n**Discovered**\n\n### Date\n{today}\n\n### Source\nRule conflict detection via /team-repair --validate\n\n### Target Module\n`context_modules/rules/{domain}/`\n\n### Context Type\nRule\n\n### Context\n**Conflict Details**:\n- Rule A: {path} — \"{statement}\"\n- Rule B: {path} — \"{statement}\"\n- Type: {critical|error|warning|info}\n\n### Decision\n**Proposed Resolution**:\n1. Add exception\n2. Edit rule to avoid conflict\n3. Mark intentional\n4. Deprecate one rule\n</code></pre>\n<p>Regenerate the local CDR index.</p>\n<p>Handoff: if conflict CDRs created, suggest <code>/levelup-clarify</code>.</p>\n<h3>Phase 9: Freshness Verification</h3>\n<p><strong>Objective</strong>: Update <code>verified</code> timestamps for valid directives and flag stale ones.</p>\n<p><strong>Skip if</strong>: <code>--skills-only</code>, <code>--agents-only</code>, or <code>--conflicts</code> flag provided.</p>\n<h4>Step 1: Identify Valid Directives</h4>\n<p>For each context module file (rules, personas, examples, constitution) and skill SKILL.md:</p>\n<ul>\n<li>If no conflicts detected for this file → eligible for verification update</li>\n<li>If conflicts detected → skip (will be resolved via conflict CDRs)</li>\n</ul>\n<h4>Step 2: Update Verification Metadata</h4>\n<p>For each eligible directive:</p>\n<ol>\n<li>Parse YAML frontmatter</li>\n<li>Append to <code>verified</code> list: <code>{ by: process:team-repair, at: {today}T00:00:00Z }</code></li>\n<li>Update <code>generated.at</code> if content changed during this repair run</li>\n<li>Append verification entry to per-directory <code>log.md</code>:</li>\n</ol>\n<pre><code>* **Verification**: Verified [{Title}](path) — no conflicts detected.\n</code></pre>\n<h4>Step 3: Report Stale Directives</h4>\n<p>Flag directives whose latest <code>verified[].at</code> is older than <code>stale_after</code> (default 180d), or whose <code>status</code> is <code>deprecated</code>.</p>\n<pre><code>### Stale Directives\n\n| File | Last Verified | Age | Stale After | Status |\n|---|---|---|---|---|\n| rules/old-pattern.md | 2026-04-01 | 190d | 180d | stale |\n</code></pre>\n<h3>Phase 10: Build to Delete (Factor XII)</h3>\n<p><strong>Objective</strong>: Identify directives that are no longer needed because baseline models handle them natively. This is the \"Harness Decay\" mechanism — run evals without directives; if the model passes independently, the directive is a candidate for removal.</p>\n<p><strong>Skip if</strong>: <code>--build-to-delete</code> flag is NOT provided.</p>\n<p><strong>This phase makes LLM calls</strong> — it runs goldenset cases against the agent to test whether directives are still needed.</p>\n<h4>Step 1: Load All Goldensets</h4>\n<p>Read all goldenset directories from <code>{TEAM_AI_DIRECTIVES}/evals/</code>:</p>\n<pre><code>ls -1 \"$TEAM_AI_DIRECTIVES/evals/\" 2&gt;/dev/null\n</code></pre>\n<p>For each <code>{directive-id}</code> directory, read:</p>\n<ul>\n<li><code>evals/{directive-id}/goldset.md</code> — human-readable cases</li>\n<li><code>evals/{directive-id}/goldset.json</code> — machine-readable cases</li>\n</ul>\n<p>If no goldensets exist, report: \"No evals found — run /levelup-specify to create eval CDRs first.\" and skip this phase.</p>\n<h4>Step 2: Identify Paired Directives</h4>\n<p>For each goldenset, identify its paired directive:</p>\n<ul>\n<li>Read <code>paired_directive</code> from the goldenset frontmatter</li>\n<li>Read the directive file from <code>context_modules/</code> (e.g., <code>rules/security/sql_injection_prevention.md</code>)</li>\n<li>If the directive file doesn't exist → skip (already deleted or orphaned eval)</li>\n</ul>\n<h4>Step 3: Run Goldenset Without Directive</h4>\n<p>For each directive+eval pair:</p>\n<ol>\n<li><strong>Temporarily remove the directive</strong> from the context that would be loaded (simulate: the agent works without the rule)</li>\n<li><strong>Run the goldenset cases</strong> against the agent via LLM calls:\n<ul>\n<li>For each pass case: present the scenario and input context, ask the agent to produce output, check if it follows the (removed) directive</li>\n<li>For each fail case: present the scenario and input context, ask the agent to produce output, check if it still makes the mistake</li>\n</ul>\n</li>\n<li><strong>Compute pass rate</strong>: <code>cases_passed / total_cases</code></li>\n</ol>\n<h4>Step 4: Classify Results</h4>\n<table>\n<thead>\n<tr>\n<th>Pass Rate</th>\n<th>Verdict</th>\n<th>Recommendation</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>100%</td>\n<td><strong>Delete candidate</strong></td>\n<td>Model handles this natively — directive is obsolete</td>\n</tr>\n<tr>\n<td>80-99%</td>\n<td><strong>Review candidate</strong></td>\n<td>Model mostly handles it — consider simplifying the directive</td>\n</tr>\n<tr>\n<td>&lt; 80%</td>\n<td><strong>Keep</strong></td>\n<td>Model still needs the directive</td>\n</tr>\n</tbody>\n</table>\n<h4>Step 5: Generate Harness Decay Report</h4>\n<pre><code>## Build to Delete Report\n\n### Candidates for Removal (model passes 100% without directive)\n\n| Directive | Eval | Pass Rate | Recommendation |\n|---|---|---|---|\n| rules/security/sql_injection.md | evals/CDR-001/ | 100% (6/6) | Delete — model handles this natively now |\n\n### Review Candidates (80-99%)\n\n| Directive | Eval | Pass Rate | Recommendation |\n|---|---|---|---|\n| rules/devops/helm_packaging.md | evals/CDR-008/ | 83% (5/6) | Simplify — model mostly handles it, 1 case failed |\n\n### Still Needed (&lt; 80%)\n\n| Directive | Eval | Pass Rate | Recommendation |\n|---|---|---|---|\n| rules/style/python_pep8.md | evals/CDR-015/ | 40% (2/5) | Keep — model still needs guidance |\n</code></pre>\n<h4>Step 6: Create Deletion CDRs</h4>\n<p>For each <strong>Delete candidate</strong> (100% pass rate), create a CDR in <code>{REPO_ROOT}/.adlc/drafts/cdr/CDR-{NNN}.md</code>:</p>\n<pre><code>## CDR-{NNN}: Delete Directive: [Title]\n\n### Status: **Discovered**\n\n### Date: [YYYY-MM-DD]\n\n### Source: Build to Delete via /team-repair --build-to-delete\n\n### Target Module: `context_modules/rules/{domain}/{file}.md` + `evals/{directive-id}/`\n\n### Context Type: Constitution Amendment\n\n### Descriptor: Directive is obsolete — model handles natively without the rule.\n\n### Context\nThe directive `{title}` was tested by running its goldenset cases without the directive loaded.\nThe model passed 100% of cases (N/N), indicating the baseline model now handles this pattern natively.\nThe directive is a candidate for Harness Decay removal.\n\n### Decision\nDelete both the directive file and its paired eval goldenset.\n\n### Evidence\n- Directive: context_modules/rules/{domain}/{file}.md\n- Eval: evals/{directive-id}/goldset.md\n- Pass rate: 100% (N/N cases passed without the directive)\n- Test date: [YYYY-MM-DD]\n</code></pre>\n<p>Regenerate the local CDR index. Handoff: suggest <code>/levelup-clarify</code> to review deletion candidates.</p>\n<h3>Phase 11: Summary Report</h3>\n<pre><code>## Team Repair Summary\n\n**Date**: {date}\n**Team Directives**: {path}\n**Mode**: {DRY RUN|LIVE}\n\n### AGENTS.md Repair\n\n| Status | Action |\n|--------|--------|\n| {VALID|CREATED|OVERWRITTEN} | {No changes needed|Created from template|Re-created from template} |\n\n### OKF index.md + log.md + CDR.md Repair\n\n| Action | Count |\n|--------|-------|\n| Files scanned | {n} |\n| v0.1→v0.2 migrated | {n} |\n| index.md files rebuilt | {n} |\n| log.md files rebuilt | {n} |\n| CDR.md derived entries | {n} |\n| Orphans repaired | {n} |\n| Missing removed | {n} |\n\n### .skills.json Repair\n\n| Action | Count |\n|--------|-------|\n| Skills scanned | {n} |\n| Valid entries | {n} |\n| Orphans repaired | {n} |\n| Missing removed | {n} |\n\n### Conflict Scanning\n\n| Metric | Count |\n|---|---|\n| Conflicts detected | {n} |\n| Conflict CDRs created | {n} |\n| Critical | {n} |\n| Error | {n} |\n| Warning | {n} |\n| Info | {n} |\n\n### Freshness Verification\n\n| Metric | Count |\n|---|---|---|\n| Directives updated | {n} |\n| Stale directives (&gt;30d) | {n} |\n| Skipped (has conflicts) | {n} |\n\n### Files Modified\n\n| File | Change |\n|------|--------|\n| {file} | {change description} |\n\n{If --dry-run:}\n&gt; **Note**: Dry run mode - no files were modified\n\n### Next Steps\n\n1. Review repaired files\n2. If conflict CDRs were created, run `/levelup-clarify` to resolve them\n3. Commit changes if satisfied\n</code></pre>\n<h3>Notes</h3>\n<ul>\n<li><strong>Auto-fix</strong>: Always repairs issues automatically (no confirmation needed)</li>\n<li><strong>Dry run</strong>: Use <code>--dry-run</code> to preview changes without writing</li>\n<li><strong>Selective repair</strong>: Use <code>--index-only</code>, <code>--skills-only</code>, or <code>--agents-only</code> for specific targets</li>\n<li><strong>Validation modes</strong>: <code>--validate</code> runs conflict scan + freshness; <code>--conflicts</code> and <code>--freshness</code> run each separately</li>\n<li><strong>YAML frontmatter</strong>: Auto-generated for orphan context modules</li>\n<li><strong>Skills entries</strong>: Auto-generated from SKILL.md content</li>\n<li><strong>AGENTS.md</strong>: Overwrites if corrupted (missing required sections)</li>\n<li><strong>Idempotent</strong>: Re-running produces same result</li>\n</ul>\n<h2>Common Rationalizations</h2>\n<table>\n<thead>\n<tr>\n<th>Rationalization</th>\n<th>Reality</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>\"The indexes look fine — no need to reindex.\"</td>\n<td>Orphaned files and missing frontmatter are invisible without a full directory scan.</td>\n</tr>\n<tr>\n<td>\"I'll just hand-edit CDR.md to add the missing row.\"</td>\n<td>Manual edits drift from actual content; a rebuild guarantees the index matches the filesystem.</td>\n</tr>\n<tr>\n<td>\"Dry run is unnecessary — just write the changes.\"</td>\n<td>A dry run surfaces unexpected orphans and null CDR refs before any file is mutated.</td>\n</tr>\n<tr>\n<td>\"AGENTS.md looks valid, so I'll skip Phase 2.\"</td>\n<td>Missing sections can be subtle (e.g., a renamed heading). Validation is cheap and idempotent.</td>\n</tr>\n<tr>\n<td>\"Skipping Step 5 — the project AGENTS.md is not my job.\"</td>\n<td>The team AI directives' own AGENTS.md describes structure; the project-level AGENTS.md is what tells agents to invoke <code>team-boot</code> at session start. Without it, the directives remain invisible.</td>\n</tr>\n<tr>\n<td>\"I can skip the CDR_LOOKUP step for orphans.\"</td>\n<td>Without the lookup, existing CDR refs are lost and orphaned entries get <code>cdr_ref: null</code>, breaking traceability.</td>\n</tr>\n<tr>\n<td>\"I'll just jump to the repair — no need for a health check first.\"</td>\n<td>Phase 0 exists precisely because an unhealthy framework makes repairs dangerous or meaningless. Run it.</td>\n</tr>\n<tr>\n<td>\"A <code>[WARN]</code> on Phase 0 is basically an <code>[OK]</code>.\"</td>\n<td>Warnings are non-blocking for exit code but often signal drift that becomes a <code>[FAIL]</code> later. Track warnings across runs.</td>\n</tr>\n</tbody>\n</table>\n<h2>Red Flags</h2>\n<ul>\n<li><strong>Overwriting AGENTS.md without validating structure first</strong> — a \"corrupted\" verdict should require evidence of missing sections, not a hunch; otherwise custom content is destroyed.</li>\n<li><strong>Generating <code>cdr_ref: null</code> when an existing CDR_LOOKUP entry exists</strong> — this silently severs the audit trail between a context module and its accepted CDR record.</li>\n<li><strong>Skipping the dry run when the orphan count is high</strong> — bulk auto-fix without review leads to fabricated IDs and metadata propagating into version control.</li>\n<li><strong>Writing <code>.skills.json</code> entries without parsing the actual <code>SKILL.md</code></strong> — fabricated descriptions and categories make skills unsearchable and misrepresent capabilities.</li>\n<li><strong>Proceeding past Phase 2 when <code>TEAM_AI_DIRECTIVES</code> is empty</strong> — operating without a configured repository writes to undefined paths and corrupts the wrong workspace.</li>\n<li><strong>Skipping Phase 0 Health Check</strong> — jumping straight into repairs without verifying the framework is installed risks writing to an absent or misconfigured workspace.</li>\n<li><strong>Skipping Step 5 (project AGENTS.md injection)</strong> — the team AI directives' own <code>AGENTS.md</code> describes its structure, but the <strong>project-level</strong> <code>AGENTS.md</code> is what tells agents to invoke <code>team-boot</code> at session start. Without it, agents have no session-start instruction and the team AI directives remains invisible until manually loaded.</li>\n</ul>\n<h2>Verification</h2>\n<ul>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Phase 0 Health Check passes all 8 checks (no <code>[FAIL]</code>) before any repair is attempted.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> AGENTS.md exists at <code>{TEAM_AI_DIRECTIVES}/AGENTS.md</code> and contains all six required sections.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Project-level <code>AGENTS.md</code> at <code>{REPO_ROOT}/AGENTS.md</code> contains the <code>&lt;!-- TEAM_AI_DIRECTIVES START --&gt;</code> managed section with the event-hook awareness note, fallback <code>team-boot</code> invocation, and the Team Context in Use output contract.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> CDR.md entry count equals the number of scanned context module <code>.md</code> files (excluding <code>constitution.md</code>).</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Every context module file under <code>context_modules/{rules,personas,examples}/</code> has YAML frontmatter with a non-empty <code>id</code> field.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Every <code>cdr_ref</code> in orphan frontmatter matches the pre-existing CDR lookup (no regression to <code>null</code> where a prior ref existed).</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Every skill directory containing a <code>SKILL.md</code> has a corresponding entry in <code>.skills.json</code>.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> No <code>.skills.json</code> entry references a skill directory that does not exist on disk.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> The summary report lists non-zero counts for \"Files scanned\" / \"Skills scanned\" and shows consistent totals.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Re-running the skill with no flags produces zero \"Files Modified\" entries (idempotency check).</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Conflict scan completed (if not skipped) and conflict CDRs created for any findings.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> Freshness verification completed (if not skipped) and stale directives reported.</li>\n<li><input disabled=\"disabled\" type=\"checkbox\"> No rule contradictions remain unreported after <code>--validate</code>.</li>\n</ul>\n<h2>Configuration</h2>\n<ul>\n<li><code>TEAM_AI_DIRECTIVES</code> — Path to the team AI directives (overrides <code>.adlc/init-options.json</code>).</li>\n<li><code>.adlc/init-options.json</code> — Project-level config file with <code>team_ai_directives</code> field.</li>\n<li>Default fallback: <code>team-ai-directives/</code> relative to project root.</li>\n<li><code>team-helpers.sh</code> / <code>team-helpers.ps1</code> — Shared scripts used for path resolution.</li>\n</ul>\n<h2>12-Factor Alignment</h2>\n<p>Factor XI (Directives as Code) — maintains integrity of version-controlled team directives.</p>\n","files":[{"path":"scripts/bash/setup-team.sh","sizeBytes":7780,"isText":true},{"path":"scripts/powershell/setup-team.ps1","sizeBytes":1408,"isText":false},{"path":"SKILL.md","sizeBytes":51414,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-30T15:24:17.083923Z","sha256":"A4C2718AEA6AC641CBA6236675321F07DB24F4EE7A9E0E23E1CE60BFB07E6B69","sizeBytes":19755},"review":null,"source":{"repositoryUrl":"https://github.com/tikalk/adlc-team-skills","path":"skills/team/team-repair","license":"MIT","commit":"249c1df30f916150d87a6f734d2bd2cb308cae8d","subtreeSha":"305D1952E9BEEB9B8471F348124E84EA54D640D282440944E66FC4019D3CF250","lastSyncedAt":"2026-09-30T15:23:42.806745Z"},"reviewedAt":"2026-09-30T15:27:58.11728Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/tikalk/adlc-team-skills/tree/main/skills/team/team-repair"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install tikalk-adlc-team-skills@llmmart"},{"target":"git","command":"git clone https://github.com/tikalk/adlc-team-skills.git"}]}