Repository navigation
feat: detect platform deployment env declarations and code references - #22
Merged
Merged
Conversation
Extend brainpod detect --with-env with deployment manifests of other hosting platforms (app.json/scalingo.json, heroku.yml, render.yaml, fly.toml, DigitalOcean app specs, vercel.json/toml, netlify.toml, App Engine app.yaml, AWS Copilot manifests), optional required/secret/generated/hasDefault/scope fields, Dockerfile ARG declarations, and a catalog-driven literal search for platform-injected names and framework env prefixes in source files.
dmeijboom
approved these changes
Nov 10, 2026
dmeijboom
left a comment
Contributor
There was a problem hiding this comment.
Approved but as discussed with a new flag
There was a problem hiding this comment.
🟡 Changes recommended
Environment overrides omit sidecar declarations from detection, and reference scanning retains and clones every match before truncation, risking substantial memory amplification despite the output cap.
2 open issues
What changed in this PR
Extends the opt-in environment detection introduced in #21 with platform deployment manifests and catalog-driven source references, while preserving default scan behavior.
Changes:
- Adds platform adapters and optional semantic fields for declarations and resource references.
- Detects build-scoped Dockerfile
ARGdeclarations and cataloged environment names in source files. - Expands synthetic tests, pinned corpus checks, and documentation covering privacy and increased opt-in reads.
| File | Description |
|---|---|
| tests/detect-env.md | Documents platform coverage, reference matching, privacy, and validation results. |
| tests/detect-corpus.md | Describes the five-repository platform supplement. |
| tests/detect-corpus.json | Adds platform, build-argument, and code-reference assertions. |
| src/detect/rules.toml | Defines platform routing and documented code-reference patterns. |
| src/detect/mod.rs | Integrates source scanning, project ownership, and output fields. |
| src/detect/environment/references.rs | Matches cataloged identifiers and groups reference records. |
| src/detect/environment/platforms.rs | Parses platform declarations and resource references. |
| src/detect/environment.rs | Adds formats, semantic fields, and Dockerfile ARG parsing. |
| src/detect/environment_tests.rs | Updates existing tests for source reads and build arguments. |
| src/detect/environment_reference_tests.rs | Tests matching, gating, occurrence limits, and determinism. |
| src/detect/environment_platform_tests.rs | Tests platform semantics, routing, and redaction. |
| src/detect/catalog.rs | Compiles and extends the code-reference catalog. |
| README.md | Explains expanded opt-in coverage and source-read impact. |
Review effort: Balanced
- Traverse environments.<name>.sidecars in Copilot manifests. - Aggregate code-reference hits per directory as a unique-line count plus the smallest MAX_OCCURRENCES locations, and merge without per-hit clones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stacked on #21 (
feat/detect-env). Everything is opt-in:--with-envreads manifest/config/deployment files only; the source-file search needs--with-sourceas well (--with-sourcewithout--with-envis a clap error).Summary
brainpod detect --with-envnow also reports:app.json, Scalingoscalingo.json,heroku.yml, Renderrender.yaml, Fly.iofly.toml, DigitalOcean.do/app.yaml/.do/deploy.template.yaml, Vercelvercel.json/vercel.toml(legacyenv/build.env), Netlifynetlify.toml(build, context and template environments), Google App Engineapp.yaml(only whenruntimeis present), and AWS Copilotcopilot/*/manifest.yml. Railway and Koyeb are excluded: Railway's config files hold no variables and its replacement is executable code, and Koyeb has no repository file.required,secret,generated,hasDefaultandscope. Each is set only where the manifest states it. Database, service and secret wiring uses feat: detect environment declarations with --with-env #21'sreferenceshape: RenderfromDatabase/fromService/fromGroup, DigitalOcean${db.VAR}/${APP_URL}bindings, Vercel@secret, and Copilot SSM, Secrets Manager and CloudFormation references.ARG: reported likeENV, withscope: "build"and ahasDefaultboolean. This updates feat: detect environment declarations with --with-env #21's statement thatARGis not inferred.--with-env --with-sourceonly): a literal, catalog-driven search of source files for platform-injected names and framework env prefixes:NEXT_PUBLIC_,VITE_,REACT_APP_,NUXT_PUBLIC_/NUXT_,PUBLIC_(only in projects detected as SvelteKit or Astro),EXPO_PUBLIC_,GATSBY_,VUE_APP_and others.rules.tomlcatalog.code_references, each with its primary documentation link.(project, name)becomes oneformat: "code-reference"record withorigin,provider,scope, up to 20 file/lineoccurrencesandoccurrenceCount.URL,CONTEXT,PORT, …) are never cataloged. Moderately generic documented names are reported only when the platform's manifest exists in the repository.Platform adapters live in
src/detect/environment/platforms.rsand the code-reference matcher insrc/detect/environment/references.rs. There are no new dependencies: TOML uses the existingtomlcrate, and platform JSON usesserde_json. JSON keeps the last value of a duplicate key, as these platforms do; Chatwoot'sapp.jsonhas one.Read impact
Measured on the 56 pinned repositories. Times are the median of per-repository five-run warm medians on a loaded host, including CLI startup and serialization.
--with-envon #21--with-env--with-env --with-source--with-envreads no application source; the 66 extra files compared with #21 are the platform manifests. Only--with-sourcereads source files. Without flags, reads and output are unchanged.Privacy
Names and provenance only. No values are returned in JSON, text, diagnostics or retained facts, including defaults, generated values, secret values, DigitalOcean
EV[...]values and Netlify template labels. Nothing is evaluated, expanded, fetched or executed. Source files are only split into identifier tokens; no code text is kept. SSM paths, ARNs and other non-simple targets are dropped. Malformed input produces fixed, redacted diagnostics. Synthetic tests assert thatDO_NOT_DISCLOSEmarkers never appear in output.Validation
cargo test --locked: 231 passed, 3 ignored benchmarks not run. The offline cache lacksserde-saphyr, so this ran online. New tests check that--with-envalone reads no source files and emits nocode-referencerecords, and that clap rejects--with-sourcewithout--with-env.cargo fmt --all -- --check: passed.cargo clippy --all-targets -- -D warnings: with clippy 0.1.98 there are 4 errors in unchanged code (deno.rsquestion_mark, generated tunnel protobufresult_large_err); the base branch reports the same 4. With only those two lints allowed, clippy is clean.--with-source. Code-reference corpus checks are stored assourceChecksand run only in that mode; declaration checks run in both opt-in modes.app.json):--with-env: 348/348, including 48/48 declaration checks (22 new).--with-env --with-source: 353/353, adding 5/5sourceChecks.projectsarrays in both opt-in modes equal the no-flag ones.EXTRA_FEATURESabsent, encoded "ARG is not inferred". It now asserts that no non-build record exists, plus a positive build-scopedARGcheck.See
tests/detect-env.mdfor the platform research (included and excluded, with doc links), the field mapping per format, the code-reference rules and pattern table with sources, and full results.