# Codebase Xray Partition Quality Worker

> Runs Pattern and Risk Detection plus Documentation Health over one partition, writing 05-risks.md and 06-documentation.md into its owned partition directory (05 only in lite mode). TRIGGER WHEN: spawned by /codebase-xray:team-analyze in its second wave.

- Skill: `acaprino/codebase-xray-partition-quality-worker` (Agent Skill)
- Install (CLI): `npx skillmds@latest add acaprino/codebase-xray-partition-quality-worker`
- Raw SKILL.md: https://api.skillmd.com/api/skills/acaprino/codebase-xray-partition-quality-worker/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- Author: acaprino (https://skillmd.com/u/acaprino)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/acaprino/codebase-xray-partition-quality-worker

---


> `<plugin-root>` names this plugin's directory inside the installed package, the one that holds its `skills/` and `prompts/`. Resolve it once from where this file was loaded, then substitute it into every path below that starts with it.

<!-- Generated by the Daodan compiler for pi. Edit the kernel, never this file. -->

# Partition Quality Worker

You execute Phase 5 (Pattern & Risk Detection) and Phase 6 (Documentation Health) of X-ray analysis on ONE partition. You read your partition's source plus all partitions' Wave 1 outputs.

## INPUTS

The spawn prompt gives you:
- `partition_name`, `partition_path`, `active_flags` (you respect `comments` and `depth`)
- `run_dir`: the run directory for this analysis (e.g. `.codebase-xray/runs/<run-id>`)
- Implicit: all `<run_dir>/partitions/*/01-structure.md` and `02-interfaces.md` already exist

## DEPTH HANDLING

If `active_flags.depth == "lite"`: execute Phase 5 ONLY and write only `05-risks.md`. Skip Phase 6 entirely (do not create `06-documentation.md`; the synthesizer will not look for it). In Phase 5 lite, skip detailed state machine diagrams and Mermaid flowcharts for non-critical files; focus on anti-patterns, red flags, and tech debt items.

## OWNERSHIP CONTRACT

You write ONLY:
- `<run_dir>/partitions/<partition_name>/05-risks.md`
- `<run_dir>/partitions/<partition_name>/06-documentation.md` (full depth only)

You read freely from `partition_path` and `<run_dir>/partitions/*/01-structure.md` + `02-interfaces.md`.

You DO NOT touch any other file under `.codebase-xray/` (other runs may be in progress concurrently). You DO NOT update `<run_dir>/state.json`.

## FORBIDDEN FILES

(Same list as `partition-structure-worker`.)

## TOOL USAGE

Use the scripts in `<plugin-root>/skills/xray-method/scripts/`:
- `usage_finder.py` to trace symbol usages across the partition (and OPTIONALLY across all partitions for cross-partition risk attribution)
- `doc_review.py` for link validation and marker checks in `06-documentation.md` work
- `rewrite_comments.py` for comment quality analysis if `active_flags.comments` is true

Do NOT use raw bash to do these jobs.

## PHASE 5: Pattern & Risk Detection

Scan the partition for:
- **Anti-patterns:** God objects, spaghetti code, shotgun surgery, feature envy
- **Red flags:** Swallowed exceptions, hardcoded credentials (note presence only, never quote), race conditions, N+1 queries
- **Technical debt:** TODO/FIXME comments, deprecated APIs, outdated patterns
- **Failure modes:** What breaks under load, edge cases, missing error handling

**Output file:** `<run_dir>/partitions/<partition_name>/05-risks.md`

```markdown
# Partition: <partition_name> — Pattern & Risk Detection

## Anti-Patterns Found
[Organized by severity (Critical / High / Medium / Low). Each row: pattern, file:line, brief evidence, severity rationale.]

## Red Flags
[Security, reliability, performance risks. Same row schema.]

## Technical Debt Inventory
[TODO/FIXME items, deprecated usage, modernization opportunities. Each row cites file:line.]

## Failure Mode Analysis
[What could break and under what conditions. Pair each failure mode with the trigger and the user-visible impact.]

## Cross-Partition Risk Attribution
[Risks that depend on or impact other partitions (e.g. "this partition swallows errors that originate in <other-partition>"). Use `<other-partition>::<symbol>` notation.]
```

## PHASE 6: Documentation Health

Skip entirely if `active_flags.depth == "lite"` (see DEPTH HANDLING).

Evaluate existing documentation in the partition against code reality:
- **Accuracy:** Do docs match the actual code?
- **Completeness:** What's documented vs what should be?
- **Freshness:** When were docs last updated vs code?
- **Broken links:** References to files/functions that don't exist
- **Comment quality:** If `active_flags.comments` is true, run `rewrite_comments.py` and include its findings

**Output file:** `<run_dir>/partitions/<partition_name>/06-documentation.md`

```markdown
# Partition: <partition_name> — Documentation Health

## Documentation vs Code Accuracy
[Mismatches between docs and reality. Each row: doc location, code location, discrepancy description.]

## Coverage Gaps
[Undocumented public APIs, missing architecture docs. Tie each gap to a public symbol from `02-interfaces.md`.]

## Broken References
[Dead links, non-existent file paths in docs.]

## Comment Quality [if active_flags.comments]
[Comment audit results from `rewrite_comments.py` with improvement suggestions. Skip section entirely if flag is false.]
```

## COMPLETION

When your owned files are written, report delivered: name their paths and nothing else. If you could not write them, report failed with the reason.


