/aspect-generator:aspect-generatorfrom aspect-generator
Builds Endor Labs custom Bazel SCA aspects so endorctl can resolve dependencies for rule classes it doesn't natively support. Use when a `bazel`/`endorctl` scan fails to produce an SBOM for a target because its rule class is unsupported, when someone asks to "add aspect support for <rule>", "write a custom aspect", "support a custom Bazel rule in endorctl", "generate dependency_metadata for a Bazel rule", or mentions `.endorctl/aspects/custom` — also when treating an open-source ruleset as custom. Discovers a rule class's attributes via a `*`-traversing probe aspect on a single target, classifies which attributes carry the package name/version/dependency edges, then writes self-contained, independently-testable aspect files that plug into endorctl without relying on `external_target_json`.
Ships in aspect-generator. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
endorctl scans a Bazel workspace by running an aspect on each target; the aspect emits a small
JSON file per node (purl + direct dependency edges) that endorctl collects via the Build Event
Protocol to build the dependency graph. endorctl ships aspects for common OSS rulesets (Go, Java,
Python, Scala, Swift, Rust, JS, TS). For anything else — an in-house rule, a fork, or an OSS rule
you want to treat as custom — it looks for a custom aspect at
.endorctl/aspects/custom/{ecosystem}/{rule_class}/{rule_class}.bzl. This skill builds those files.
Everything produced is self-contained (loads only from a small common/ library this skill
installs in the workspace) and independently bazel test-able — which is why the aspect must
never read external_target_json: name, version, and edges all come from what the aspect sees
directly on the target.
endorctl will fail to find or run the aspect if any of these is violated. Full detail and rationale:
references/endorctl-contract.md — read it before authoring.
.endorctl/aspects/custom/{ecosystem}/{rule_class}/{rule_class}.bzl — dir and filename
equal the rule class exactly.endor_resolve_dependencies = aspect(...).ref, log_level, external_target_json (+ json_go_mod for golang);
Bazel errors on undeclared injected params. external_target_json is declared but never read.endor_sca_info, in a depset
alongside children's files.{ecosystem} ∈ golang, java, python, scala, rust, javascript, swift (drives purl type).//services/api:server) — enough to surface the rule class
and its attributes. Do not probe //....@//.endorctl/aspects. Only override if the user says their
endorctl config points elsewhere — don't go hunting.Copy assets/common/ to .endorctl/aspects/custom/common/ if not present. These three files
(provider.bzl, utils.bzl, BUILD.bazel) are reused verbatim by every generated aspect.
Copy assets/discovery/ to .endorctl/aspects/custom/_discovery/, then run the probe:
bazel build <target> \
--aspects=//.endorctl/aspects/custom/_discovery:discover.bzl%discover \
--aspects_parameters=nonce=$RANDOM \
--output_groups=endor_discovery --nobuild 2>&1 | grep ENDOR_DISCOVERY
attr_aspects=["*"] traverses every attribute edge (not just deps/srcs) and prints each node's
kind + ctx.rule.attr/ctx.attr dumps — the values give far more signal than dir(), which can't
enumerate custom providers. --nobuild stops after analysis (where the prints fire), so it's cheap.
nonce busts Bazel's analysis cache so re-runs re-emit. (scripts/inventory.sh sets it for you.)
* traversal also
surfaces dependency rule classes; note them but focus on the target's class.filegroup, genrule, alias, *_toolchain,
config_setting, proto scaffolding — they aren't packages.scripts/inventory.sh <target> dumps the dedup'd set of
every node reached. This is your completeness ledger for Phase 4.For the target's rule class, decide which attribute (or the label) yields each field. See
references/classification.md for per-ecosystem heuristics, purl formats, and the diff-tested
caveats — read them, they encode real failures observed against normal scans. You need:
_PACKAGE_KINDS: the rule kinds that are real packages (the target's kind
plus the library/import/store kinds it reaches). Everything else is gated out or becomes bogus.importpath/crate_name/module_name attr, a maven_coordinates tag, a package
attr, or parsed from the label.version/tag/commit/strip_prefix attr, else the injected ref for
first-party. If it lives only on a repository rule, use the injected map (json_go_mod for
golang) or flag the gap._EDGE_ATTRS: the attrs holding dependency labels across every kind in
_PACKAGE_KINDS (deps, embed, exports, runtime_deps, store links, …). Missing one
truncates the graph.If name/version genuinely live only in a custom provider you can't read, say so and stop — flag the gap rather than guessing a wrong purl.
From assets/templates/, generate into .endorctl/aspects/custom/{ecosystem}/{rule_class}/:
{rule_class}.bzl from rule.bzl — fill in _PACKAGE_KINDS, name/version expressions,
_EDGE_ATTRS, the ecosystem constant, and (golang only) the json_go_mod attr.{rule_class}_test.bzl from rule_test.bzl — assert the pure extraction functions produce the
right purl/version from attribute values seen in Phase 1.BUILD.bazel from BUILD.bazel — the bzl_library plus the test target.Skylib check: the test uses @bazel_skylib//lib:unittest.bzl. Grep MODULE.bazel and
WORKSPACE/WORKSPACE.bazel for bazel_skylib. If present, emit the test. If absent, skip the
test (still emit aspect + BUILD) and tell the user why.
bazel-bin):
bazel build <target> \
--aspects=//.endorctl/aspects/custom/{ecosystem}/{rule_class}:{rule_class}.bzl%endor_resolve_dependencies \
--output_groups=endor_sca_info \
--aspects_parameters=external_target_json={} --aspects_parameters=ref=local \
--build_event_json_file=/tmp/bep.json --nobuild_event_json_file_path_conversion 2>&1 | tail -5
(add --aspects_parameters=json_go_mod={} for golang.)python3 scripts/collect_bom.py /tmp/bep.json lists every emitted node
(internal purl label). Bogus purls (pkg:maven/:launcher) ⇒ kind gate too loose; far fewer
nodes than expected ⇒ missing edge attr; uniform @<ref> versions on third-party ⇒ missing
version source. Then diff the Phase-1 inventory against emitted labels and confirm every
node in (inventory − emitted) was deliberately skipped, not dropped.bazel test //.endorctl/aspects/custom/{ecosystem}/{rule_class}:{rule_class}_test.custom/ renamed aside (OSS aspects), fetch each PackageVersion
(endorctl api get -r PackageVersion --uuid <id> -n <ns> -a <api> -o json), then
python3 scripts/diff_pv.py custom.json oss.json.Always show the user the exact bazel commands and confirm before running — they execute in the
user's workspace.
assets/common/BUILD.bazel (opens in a new tab)assets/common/provider.bzl (opens in a new tab)assets/common/utils.bzl (opens in a new tab)assets/discovery/BUILD.bazel (opens in a new tab)assets/discovery/discover.bzl (opens in a new tab)assets/templates/BUILD.bazel (opens in a new tab)assets/templates/rule.bzl (opens in a new tab)assets/templates/rule_test.bzl (opens in a new tab)evals/evals.json (opens in a new tab)evals/trigger-eval.json (opens in a new tab)references/classification.md (opens in a new tab)references/endorctl-contract.md (opens in a new tab)scripts/collect_bom.py (opens in a new tab)scripts/diff_pv.py (opens in a new tab)scripts/inventory.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub endorlabs/bazel-helper --plugin aspect-generator