Reverse-engineer Context Directive Records (CDRs) from an existing codebase for contribution to team-ai-directives. Use when bootstrapping team knowledge from brownfield projects.
npx skills add https://github.com/tikalk/adlc-team-skills --skill levelup-init
Reverse-engineer Context Directive Records (CDRs) from an existing codebase (brownfield) to document reusable patterns that could become contributions to team-ai-directives.
You act as a Context Archaeologist uncovering implicit team patterns from code:
{REPO_ROOT}/.adlc/drafts/cdr/CDR-{NNN}.md with status Discovered{REPO_ROOT}/.adlc/drafts/cdr/cdr.md indexKey Difference from /levelup-specify:
/levelup-init (this skill) = Discovers what's already implemented in code/levelup-specify = Extracts patterns from a completed feature's spec/plan/tasksThis skill focuses on current state analysis — what IS reusable, not what SHOULD BE created.
/levelup-specify after implementing a feature.adlc/drafts/cdr/ has pending CDRs, use /levelup-clarify to review/team-repair for re-indexing and conflict scanning$ARGUMENTS
You MUST consider the user input before proceeding (if not empty).
Examples of User Input:
"Python FastAPI backend with PostgreSQL" — Focus on Python patterns"Focus on testing patterns" — Narrow to testing-related CDRs"--cdr-heuristic all" — Document all patterns, not just surprising ones"--focus rules" — Only discover rule-type patterns"--resume" — Resume from previous state--cdr-heuristic HEURISTIC: CDR generation strategysurprising (default): Only document patterns not already in team-ai-directivesall: Document all discovered patternsminimal: Only high-value/novel patterns--focus AREA: Focus on specific context typerules: Only scan for coding rulespersonas: Only scan for role patternsexamples: Only scan for example-worthy codeconstitution: Only scan for governance patternsskills: Only scan for skill-worthy capabilities--no-decompose: Disable automatic sub-system detection--resume: Resume from previous state (if interrupted)--skip-constitution: Skip constitution generation phaseYou are orchestrating a multi-agent analysis pipeline with three specialized agents:
| Scenario | Command | Input | Output |
|---|---|---|---|
| Brownfield (existing code) | /levelup-init | Codebase scan | Discovered CDRs |
| Greenfield (feature complete) | /levelup-specify | Feature artifacts | Proposed CDRs |
The Synthesis Agent detects:
| Pattern Type | Criteria | Action |
|---|---|---|
| Cross-cutting | Pattern in ≥50% of sub-systems | High-priority CDR |
| Inconsistent | Same concern, different implementations | Inconsistency CDR |
| Project-specific | Only in 1 sub-system, low reuse | Lower priority or skip |
| Gap | High value, not in team-directives | Recommended CDR |
10. Output (Phase 10): Regenerate cdr.md index and present summary
Run the setup script from repository root:
scripts/bash/setup-levelup-init.sh
Parse the JSON output for REPO_ROOT, CDR_DRAFTS_DIR, TEAM_AI_DIRECTIVES, NEXT_CDR, etc.
If the setup script is unavailable or fails, resolve manually:
REPO_ROOT — walk up from cwd to find .adlc/, or git rev-parse --show-toplevel, or pwd.TEAM_AI_DIRECTIVES — TEAM_AI_DIRECTIVES env var, then .adlc/init-options.json → team_ai_directives, then REPO_ROOT/team-ai-directives.CDR_DRAFTS_DIR — REPO_ROOT/.adlc/drafts/cdrNEXT_CDR — list CDR_DRAFTS_DIR/CDR-*.md, find highest number, increment, zero-pad to 3 digits.If TEAM_AI_DIRECTIVES is not configured:
Team AI directives repository not configured.
Run: team-setup
Or set: export TEAM_AI_DIRECTIVES=/path/to/team-ai-directives
Analyze the codebase for distinct sub-systems. Same detection rules as /architect-init:
| Pattern | Likely Sub-System |
|---|---|
| src/auth/ | Authentication sub-system |
| src/users/ | User management sub-system |
| services/payment/ | Payment sub-system |
| apps/api/, apps/web/ | Monorepo apps |
Threshold Logic:
| Sub-System Count | Required Action |
|---|---|
| 0 | Proceed as monolithic |
| 1-3 | Show summary, auto-approve allowed |
| 4-6 | MUST show summary and ask confirmation |
| >6 | MUST suggest grouping and ask confirmation |
{REPO_ROOT}/.adlc/drafts/cdr/{REPO_ROOT}/.adlc/drafts/skills/{REPO_ROOT}/.adlc/levelup/{REPO_ROOT}/.adlc/levelup/state.json:{
"version": "1.0.0",
"command": "init",
"created_at": "2026-01-20T10:00:00Z",
"phase": "discovery",
"subsystems": [...],
"constitution_generation": { "enabled": true, "completed": false }
}
Read existing team-ai-directives for comparison:
{TEAM_AI_DIRECTIVES}/context_modules/constitution.md{TEAM_AI_DIRECTIVES}/context_modules/rules/**/*.md{TEAM_AI_DIRECTIVES}/context_modules/personas/*.md{TEAM_AI_DIRECTIVES}/context_modules/examples/**/*.md{TEAM_AI_DIRECTIVES}/skills/**/*Run Discovery, Pattern, and Synthesis agents sequentially per sub-system.
Create a Constitution CDR (if not skipped) in .adlc/drafts/cdr/CDR-CONST-NNN.md:
CRITICAL: Write to .adlc/drafts/cdr/, NOT directly to team-ai-directives.
For each high-value pattern, create an individual CDR file:
## CDR-NNN: [Title]
### Status: **Discovered**
### Date: [YYYY-MM-DD]
### Source: Cross-sub-system analysis via /levelup-init
### Cross-System Metadata
- **Appears in**: [sub-systems]
- **Cross-system score**: [0.0-1.0]
- **Consistency**: [consistent|inconsistent]
- **Reuse score**: [0.0-1.0]
### Target Module: `context_modules/rules/[domain]/[file].md`
### Context Type: Rule | Persona | Example | Skill | Constitution Creation | Constitution Amendment | Eval
### Descriptor: One-line "when to use" summary for CDR index search.
### Context
[Problem statement and evidence]
### Decision
[What should be contributed to team-ai-directives]
### Evidence
- [file/path]: [description]
- [commit/sha]: [description]
Eval CDRs from codebase patterns: When creating a directive CDR from a discovered codebase pattern, also extract a paired eval CDR:
Eval CDRs use ### Context Type: Eval, reference their paired directive CDR via ### Paired Directive CDR: CDR-NNN, and have ### Target Module: evals/{directive-id}/goldset.md. Cases are self-contained with inline code snippets — no external file dependency.
{REPO_ROOT}/.adlc/drafts/cdr/cdr.md index by listing all CDR-*.md files and building a markdown table from their single-line fields (### Target Module:, ### Context Type:, ### Status:, ### Date:, ### Descriptor:). See /levelup-specify Phase 5 for the full format.## LevelUp Init Summary
- Sub-systems analyzed: N
- Patterns discovered: N
- Cross-cutting patterns: N
- Inconsistencies flagged: N
- CDRs generated: N
- Output: `{REPO_ROOT}/.adlc/drafts/cdr/`
Before publishing (handled later by /levelup-publish), CDRs must pass:
/levelup-initRequired: Run /levelup-clarify to validate discovered CDRs.
Handoff context to include:
{
"source": "brownfield",
"command": "init",
"cdrs_created": ["CDR-001", "CDR-002", "CDR-CONST-001"],
"subsystems": ["auth", "payments", "users"],
"inconsistencies": ["CDR-INC-001"]
}
/levelup-init
↓
[Scan codebase] → Detect sub-systems and patterns
↓
[Generate CDRs] → Write to .adlc/drafts/cdr/CDR-{NNN}.md (Discovered)
↓
[Run /levelup-clarify] → Validate and accept/reject CDRs
↓
[Run /levelup-publish] → Compile accepted CDRs into team-ai-directives PR
↓
[Run /team-repair] → Re-index and validate team AI directives after merge
After init completes, run /levelup-clarify to refine and validate the discovered CDRs.
{REPO_ROOT}/.adlc/drafts/cdr/CDR-{NNN}.md with status Discovered.cdr.md index exists in {REPO_ROOT}/.adlc/drafts/cdr/.$ARGUMENTS
Take tikalk/levelup-init from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.