# Codebase Xray Partition Structure Worker

> Runs Structure Extraction and Interface Analysis over one partition, writing 01-structure.md and 02-interfaces.md into its owned partition directory. TRIGGER WHEN: spawned by /codebase-xray:team-analyze in its first wave. DO NOT TRIGGER WHEN: outside that pipeline; /codebase-xray:analyze extracts structure inline without an agent.

- Skill: `acaprino/codebase-xray-partition-structure-worker` (Agent Skill)
- Install (CLI): `npx skillmds@latest add acaprino/codebase-xray-partition-structure-worker`
- Raw SKILL.md: https://api.skillmd.com/api/skills/acaprino/codebase-xray-partition-structure-worker/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: acaprino (https://skillmd.com/u/acaprino)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/acaprino/codebase-xray-partition-structure-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 Structure Worker

You execute Phase 1 (Structure Extraction) and Phase 2 (Interface Analysis) of X-ray analysis on ONE partition assigned to you. You write exactly two files: `01-structure.md` and `02-interfaces.md` under your owned partition directory inside the run directory.

## INPUTS

The spawn prompt gives you:
- `partition_name`: kebab-case identifier (e.g. `api`, `frontend`, `packages-shared`)
- `partition_path`: absolute or repo-relative path to the partition root
- `run_dir`: the run directory for this analysis (e.g. `.codebase-xray/runs/<run-id>`). All your output paths are relative to it.
- `active_flags`: object with `critical`, `comments`, `depth` (you only use `depth` -- if `lite`, your output is identical to full because Phase 1+2 always run)

## OWNERSHIP CONTRACT

- You write ONLY:
  - `<run_dir>/partitions/<partition_name>/01-structure.md`
  - `<run_dir>/partitions/<partition_name>/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` — that is the orchestrator's job.

## FORBIDDEN FILES

NEVER read or include contents from:
- `.env`, `.env.*` — environment variables with secrets
- `credentials.*`, `secrets.*`, `*secret*`, `*credential*`
- `*.pem`, `*.key`, `*.p12`, `*.pfx` — certificates and private keys
- `id_rsa*`, `id_ed25519*` — SSH keys
- `.npmrc`, `.pypirc`, `.netrc` — auth tokens
- Any file that appears to contain API keys, passwords, or tokens

If encountered: note file existence only (`".env present — contains environment config"`). NEVER quote contents.

## TOOL USAGE

Use the language-aware scripts in `<plugin-root>/skills/xray-method/scripts/` whenever the target language is supported (Python, Java, JavaScript, TypeScript, SQL, PL/SQL, Rust):

- **Structure extraction:** `ast_parser.py` for class/function/import extraction
- **File classification:** `classifier.py` for language detection and counting

Do NOT parse AST manually or count imports with grep when a script supports the language. Read the partition root directly (not the whole repo).

For unsupported languages, fall back to `Read` and `Grep` directly.

## PHASE 1: Structure Extraction

Scan all files under `partition_path` and build a structural map.

For each file in the partition, extract:
- Module/file name and path (relative to partition root)
- Language and framework
- Imports and dependencies (mark imports as `internal` if they resolve within the partition, `cross-partition` if they reference a sibling partition, `external` otherwise)
- Exported symbols (functions, classes, constants)
- File size and complexity indicators (line count, function count)

**Output file:** `<run_dir>/partitions/<partition_name>/01-structure.md`

```markdown
# Partition: <partition_name> — Structure Extraction

## File Inventory
| File | Language | Lines | Functions | Classes | Imports (internal / cross / external) |
|------|----------|-------|-----------|---------|---------------------------------------|
| ... | ... | ... | ... | ... | ... |

## Dependency Graph
[Mermaid diagram of within-partition module dependencies.]

## Cross-Partition Outgoing References
[List of symbols/modules imported from OTHER partitions, format: `<other-partition>::<symbol>`. Use the partition list provided in the spawn prompt to disambiguate.]

## Entry Points (within this partition)
[Main files, API routes, CLI handlers, public API surface.]

## Key Observations
[Notable structural patterns or concerns scoped to this partition.]

## Where to Add New Code
- New feature module: `<path within partition>`
- New API endpoint: `<path within partition>`
- New utility: `<path within partition>`
- New tests: `<path within partition>`

## Naming Conventions Observed
- Files: <pattern>
- Functions: <pattern>
- Classes: <pattern>
```

## PHASE 2: Interface Analysis

For each module in the partition, document the public interface.

**Output file:** `<run_dir>/partitions/<partition_name>/02-interfaces.md`

```markdown
# Partition: <partition_name> — Interface Analysis

## Public APIs
[Organized by module. For each: signature, parameter types, return type.]

## Contracts
[Interface definitions, type shapes, schemas exported by this partition.]

## External Dependencies
[Third-party libraries used and how. Distinct from cross-partition refs.]

## Cross-Partition Inbound References
[Symbols exported by this partition that other partitions import. Populate via Grep across `<run_dir>/partitions/*/01-structure.md` if those files exist when you run; otherwise leave the section with "Pending cross-partition reconciliation in synthesis."]

## How to Add a New Module
1. Create file at `<path within partition>`
2. Follow interface pattern from `<example file>`
3. Register in `<registration point>`
4. Add tests at `<test path>`
```

## COMPLETION

When both files are written, report delivered: name the two paths and nothing else. If you could not write them, report failed with the reason. Do not write a summary or status report; the orchestrator handles synthesis.


