[STAGE-0] Inventory
This stage is Python-executed via core.inventory. The orchestrator runs it automatically.
Context
See SKILL.md for configuration, execution rules, and MUST-GATEs.
Purpose
Create a comprehensive inventory of all code that needs to be analyzed. This becomes the source of truth for GATE-5 (FULL-COVERAGE) compliance.
How it works
The Python build_inventory() function:
- Enumerates all source files (12+ languages supported)
- Excludes test, mock, vendor, generated, and build output files
- Extracts all functions/methods per file (AST for Python, regex for others)
- Computes SHA-256 checksum per file
- Records excluded files with reasons
- Carries forward
checked_bycoverage from previous runs (unchanged files only)
Output Format
{
"generated_at": "ISO timestamp",
"target_path": "/path/to/repo",
"total_files": 200,
"total_items": 1920,
"total_functions": 1847,
"total_sloc": 42000,
"skipped_files": 15,
"excluded_files": [
{"path": "tests/test_auth.py", "reason": "pattern_match", "pattern_matched": "test_*"}
],
"files": [
{
"path": "relative/path/to/file.py",
"language": "python",
"lines": 150,
"sloc": 120,
"sha256": "a1b2c3...",
"items": [
{
"name": "function_name",
"kind": "function",
"line_start": 10,
"line_end": 25,
"signature": "def function_name(arg1, arg2)",
"checked_by": []
},
{
"name": "MAX_RETRIES",
"kind": "global",
"line_start": 3,
"line_end": 3,
"checked_by": []
}
]
}
]
}Output
OUTPUT: checklist.json
Binary targets
When the target is a compiled binary (magic-byte detection, never
extensions), the builder does not walk source — it discovers the RE
substrate RAPTOR already produced for that binary (co-located run
artifacts, project sibling run dirs, the project ghidra-attach
cache, then out/ghidra-import-<stem>/) and builds the inventory
over decompiled function units instead. Candidates are
identity-gated; a content-verified re-database (matching
binary_sha256 stamp) outranks any unverified one regardless of
recency, and an unverified (name-match-only) selection is flagged
sha_verified: false and labeled on every surface. Items carry
address
instead of line_start, source: "decompilation", the decompiler
tool, fid where minted, and a metadata.decomp_file +
decomp_line_start/decomp_line_end citation into the run's
decomp-tree. The checklist grows a top-level substrate block and
the run dir gets a binary-substrate.json discovery receipt. An
existing decomp-tree is pointed at; when only a re-database exists,
the tree is materialized into the RUN directory (never the target
dir). A matching binary-validation-handoff.json is imported into
attack-paths.json (source binary:handoff, missing evidence as
blockers). No substrate → stage 0 refuses with the searched
locations and the commands that produce one (raptor-ghidra import --decompile-all, /project ghidra add, /understand <binary> --study). Nothing executes the target.
Findings import dedup
A --findings import collapses PROVABLE duplicates (same sink — file,
line, function, canonical vuln_type — AND every vector field equal) so
they are validated once; the canonical finding's verdict fans out to
each duplicate in the report. Among provably-same rows the
evidence-richer one survives as the canonical (ties keep the earlier
row), so a stripped-evidence decoy cannot displace the evidenced
finding from paid analysis. Conservative by contract: any doubt
(a vector field present on only one row, differing hypothesis/title,
incomplete sink identity) keeps both rows — the later one is flagged
potential_dup:<canonical-id>. Every decision is recorded in
dedup-report.json; the import marker carries the deduped count.
Nothing here changes a status or verdict.
Capability preflight
Stage 0 ends with a warning-only capability preflight
(capability-preflight.json, fresh-or-absent: the previous run's
artifact is removed before the probe body, then rewritten). When the
run has no binary (none detected under the target, no usable
persisted project
binary) and no build-execution consent, and memory-corruption findings
(or native-language files, in sweep mode) are in scope, it prints a
loud banner BEFORE any LLM spend naming the mechanical ceiling —
memory-corruption findings can reach at most confirmed_unverified —
and the escape hatches (--binary <path>, /project binary add,
/project trust build|dynamic). It never refuses the run and never
changes a verdict; the validation report renders the same warning in a
"Capability Preflight" section.
Shared with /understand
This inventory is the same checklist.json produced by /understand --map (MAP-0 step). Coverage tracking (checked_by) is cumulative across both skills. SHA-256 checksums detect file changes between runs.
Validation
The orchestrator verifies:
- All source files enumerated (not just sampled)
- Test/mock files explicitly excluded (with reasons recorded)
- Each file has functions extracted
- JSON is valid and parseable
NOTICE: This analysis is performed for defensive purposes, in a lab environment. Full permission has been provided.