Repository navigation
chore(agents): enforce OSS isolation with a mechanical pre-push guard - #369
Conversation
|
Warning Amazon Q Developer for GitHub: end of support On January 30, 2027, AWS will discontinue support for the Amazon Q Developer for GitHub App. New app installations will no longer be available starting November 18, 2026. For capabilities similar to the Amazon Q Developer for GitHub App, explore Kiro and the Kiro GitHub App. For more information about the end of support, see Amazon Q Developer end-of-support announcement on the AWS DevOps Blog. |
Reviewer's GuideImplementationRead the guard’s scanning and pre-push logic, which implements the mechanical checks for public GitHub contributions.
ConfigurationRead the agent instructions, ignore-file change, and OSS isolation rule together to understand how the guard is intended to be used and enforced.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
This comment has been minimized.
This comment has been minimized.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 51 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
✅ Deploy Preview for adt-cli canceled.
|
There was a problem hiding this comment.
Review Summary
This PR adds a mechanical OSS isolation gate (pre-push hook + agent rule + .gitignore entry). The overall approach is sound and the structure is clean. Two logic defects in scripts/oss-github-guard.sh need fixing before merge:
-
New-branch range is unbounded (line 66–68): When
remote_shais all-zeros (first push of a branch),range="$local_sha"causesgit logto walk the entire ancestry of the commit rather than only the new commits being pushed. This makes the scan both incorrect in scope and prohibitively slow on repos with long history. -
ghfailure silently produces a false "clean" result (lines 45–46): Pipinggh pr view ... 2>/dev/null | scan ...swallowsgh's exit code. Anygherror (unauthenticated, wrong repo, network issue) causes empty stdout to flow intoscan, which then exits 0 — the guard reports "clean" when it has actually scanned nothing. A suggested fix is provided on those lines.
No other blocking issues found in the remaining files (.gitignore, AGENTS.md, .agents/rules/git/oss-isolation.md).
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 1 medium |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Hey - I've found 16 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="AGENTS.md" line_range="46-47" />
<code_context>
+`.agents/rules/git/oss-isolation.md`).
+
+Before any `git push` to a public remote or `gh pr create/edit/comment`:
+run `scripts/oss-github-guard.sh` (the pre-push hook enforces this; a
+non-zero exit is a hard stop). Full rule:
+`.agents/rules/git/oss-isolation.md`.
</code_context>
<issue_to_address>
**Pushes bypass the guard**
When a contributor pushes using the repository’s configured Git hooks, no configured `.husky/pre-push` hook invokes `scripts/oss-github-guard.sh`, so ordinary public pushes proceed without the advertised mechanical check and forbidden context reaches GitHub.
Add and configure a pre-push hook that runs `scripts/oss-github-guard.sh`.
Also at `scripts/oss-github-guard.sh:10`.
</issue_to_address>
### Comment 2
<location path="scripts/oss-github-guard.sh" line_range="71" />
<code_context>
+ else
+ range="$remote_sha..$local_sha"
+ fi
+ git log --format='%H%n%B%n%an <%ae>%n%cn <%ce>' "$range" 2>/dev/null | scan "commits $range -> $remote_name (github.com)" || exit 1
+ done
+ echo "OSS-GUARD: push to $remote_name (github.com) clean."
</code_context>
<issue_to_address>
**Pushed file contents go unchecked**
When an outgoing commit contains forbidden context in a changed file, `git log --format` supplies only commit hashes, messages, and author/committer metadata to `scan`, not changed file contents, so forbidden context in source, comments, fixtures, or documentation passes the push check and reaches GitHub.
Scan the outgoing changes’ file contents as well as their commit metadata.
Also at `.agents/rules/git/oss-isolation.md:22`.
</issue_to_address>
### Comment 3
<location path="scripts/oss-github-guard.sh" line_range="45-46" />
<code_context>
+case "${1:-}" in
+ --pr)
+ [ -n "${2:-}" ] || { echo "usage: $0 --pr <N>" >&2; exit 2; }
+ gh pr view "$2" --json title,body --jq '.title, .body' 2>/dev/null | scan "PR $2 title/body" || exit 1
+ gh pr view "$2" --json comments --jq '.comments[] | .body' 2>/dev/null | scan "PR $2 comments" || exit 1
+ echo "OSS-GUARD: PR $2 clean."
+ ;;
</code_context>
<issue_to_address>
**Failed scans report clean**
When `gh`, `git log`, or a file read fails while the guard is running, the pipelines return `scan`’s status, and `scan` accepts empty input as clean; failed `--file` reads also fall through. The guard reports success without inspecting the input, allowing the caller to proceed unchecked.
Make producer and file-read failures stop the guard instead of treating missing input as a clean scan.
Also at `scripts/oss-github-guard.sh:37-38`, `scripts/oss-github-guard.sh:51`, `scripts/oss-github-guard.sh:71`, `scripts/oss-github-guard.sh:79-80`.
</issue_to_address>
### Comment 4
<location path="scripts/oss-github-guard.sh" line_range="46" />
<code_context>
+ --pr)
+ [ -n "${2:-}" ] || { echo "usage: $0 --pr <N>" >&2; exit 2; }
+ gh pr view "$2" --json title,body --jq '.title, .body' 2>/dev/null | scan "PR $2 title/body" || exit 1
+ gh pr view "$2" --json comments --jq '.comments[] | .body' 2>/dev/null | scan "PR $2 comments" || exit 1
+ echo "OSS-GUARD: PR $2 clean."
+ ;;
</code_context>
<issue_to_address>
**Review replies go unchecked**
When forbidden context appears in a PR review comment or reply, the `--pr` query reads general PR comments but not review threads or inline review replies, so `scan` reports the PR clean while that public text remains unchecked.
Include review-thread comments and replies in the `--pr` scan.
Also at `.agents/rules/git/oss-isolation.md:17`.
</issue_to_address>
### Comment 5
<location path="scripts/oss-github-guard.sh" line_range="42-46" />
<code_context>
+ fi
+}
+
+case "${1:-}" in
+ --pr)
+ [ -n "${2:-}" ] || { echo "usage: $0 --pr <N>" >&2; exit 2; }
+ gh pr view "$2" --json title,body --jq '.title, .body' 2>/dev/null | scan "PR $2 title/body" || exit 1
+ gh pr view "$2" --json comments --jq '.comments[] | .body' 2>/dev/null | scan "PR $2 comments" || exit 1
+ echo "OSS-GUARD: PR $2 clean."
+ ;;
</code_context>
<issue_to_address>
**Issue text goes unchecked**
When a contributor creates or edits an issue containing forbidden context, the guard has no issue mode and `--pr` only queries pull requests, so issue titles, bodies, and comments are not checked by the advertised live-content scan.
Add a guard mode that scans the relevant issue text before it is published.
Also at `.agents/rules/git/oss-isolation.md:48`.
</issue_to_address>
### Comment 6
<location path="scripts/oss-github-guard.sh" line_range="45-46" />
<code_context>
+case "${1:-}" in
+ --pr)
+ [ -n "${2:-}" ] || { echo "usage: $0 --pr <N>" >&2; exit 2; }
+ gh pr view "$2" --json title,body --jq '.title, .body' 2>/dev/null | scan "PR $2 title/body" || exit 1
+ gh pr view "$2" --json comments --jq '.comments[] | .body' 2>/dev/null | scan "PR $2 comments" || exit 1
+ echo "OSS-GUARD: PR $2 clean."
+ ;;
</code_context>
<issue_to_address>
**New GitHub text goes unchecked**
When a contributor submits a new PR or issue title, body, or comment, the documented preflight scans branch names and commit metadata, while `--pr` reads an existing PR rather than the text about to be submitted; the new payload can therefore reach GitHub without being checked.
Scan the proposed GitHub text itself as part of the preflight.
Also at `.agents/rules/git/oss-isolation.md:48`.
</issue_to_address>
### Comment 7
<location path="scripts/oss-github-guard.sh" line_range="18-23" />
<code_context>
+# live in scripts/.oss-guard-local.patterns (local, untracked): one regex
+# fragment per line, OR-joined into the scan. Without that file only the
+# generic patterns apply.
+PATTERNS='@(corp|internal)\.example'
+LABEL='internal / non-public context'
+PATTERN_FILE="$(dirname "$0")/.oss-guard-local.patterns"
+if [ -f "$PATTERN_FILE" ]; then
+ LOCAL=$(grep -vE '^\s*(#|$)' "$PATTERN_FILE" | paste -sd '|' -)
+ [ -n "$LOCAL" ] && PATTERNS="$PATTERNS|$LOCAL"
+fi
+TMP=$(mktemp) || exit 2
</code_context>
<issue_to_address>
**Local patterns are silently omitted**
When the ignored local pattern file has not been provisioned, `scripts/oss-github-guard.sh` continues with only its generic pattern and reports a clean scan, so organization-specific links, codenames, and identifiers go undetected.
Require the local pattern file or otherwise ensure the required organization-specific patterns are available before scanning.
</issue_to_address>
### Comment 8
<location path="scripts/oss-github-guard.sh" line_range="59-61" />
<code_context>
+ # pre-push hook mode: args "<remote> <url>", stdin lines "<local_ref> <local_sha> <remote_ref> <remote_sha>"
+ remote_name="$1"; remote_url="$2"
+ case "$remote_url" in
+ *github.com*) : ;;
+ *) exit 0 ;; # internal remotes (GitLab) are out of scope for this guard
+ esac
+ while read -r local_ref local_sha remote_ref remote_sha; do
+ [ "$local_sha" = "0000000000000000000000000000000000000000" ] && continue
</code_context>
<issue_to_address>
**SSH aliases bypass scanning**
When a public GitHub remote uses an SSH host alias, the remote URL does not contain the literal `github.com`, so the `case` check exits as though the remote were internal and skips the push scan.
Recognize GitHub remotes configured through SSH host aliases.
</issue_to_address>
### Comment 9
<location path="scripts/oss-github-guard.sh" line_range="67" />
<code_context>
+ branch=${local_ref#refs/heads/}
+ printf '%s\n' "$branch" | scan "branch name ($branch)" || exit 1
+ if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then
+ range="$local_sha"
+ else
+ range="$remote_sha..$local_sha"
</code_context>
<issue_to_address>
**Old commits block new branches**
When a new branch descends from already-published commits containing a forbidden pattern, the zero-remote-SHA case sets `range` to the local tip, so `git log` scans its ancestors, including already-published commits; a matching old commit blocks an otherwise clean push.
For a new branch, limit the scan to commits not already reachable from the remote.
</issue_to_address>
### Comment 10
<location path="scripts/oss-github-guard.sh" line_range="79-80" />
<code_context>
+ # standalone mode: scan branch name + commits between upstream and HEAD.
+ branch=$(git rev-parse --abbrev-ref HEAD)
+ printf '%s\n' "$branch" | scan "branch name" || exit 1
+ base=$(git rev-parse --abbrev-ref --symbolic-full-name '@{push}' 2>/dev/null | sed 's|/[^/]*$||') || base=origin
+ git log --format='%H%n%B%n%an <%ae>%n%cn <%ce>' "${base}/HEAD..HEAD" 2>/dev/null | scan "commit metadata (${base}/HEAD..HEAD)" || exit 1
+ echo "OSS-GUARD: outgoing commits and branch name clean."
+ ;;
</code_context>
<issue_to_address>
**Wrong push base is scanned**
When the configured push target differs from the remote’s default branch, standalone mode compares `HEAD` with `remote/HEAD` instead of the configured push target, so it can miss commits the push will send or treat already-published commits as outgoing.
Derive the comparison base from the configured push target rather than the remote’s default branch.
</issue_to_address>
### Comment 11
<location path="scripts/oss-github-guard.sh" line_range="79-80" />
<code_context>
+ # standalone mode: scan branch name + commits between upstream and HEAD.
+ branch=$(git rev-parse --abbrev-ref HEAD)
+ printf '%s\n' "$branch" | scan "branch name" || exit 1
+ base=$(git rev-parse --abbrev-ref --symbolic-full-name '@{push}' 2>/dev/null | sed 's|/[^/]*$||') || base=origin
+ git log --format='%H%n%B%n%an <%ae>%n%cn <%ce>' "${base}/HEAD..HEAD" 2>/dev/null | scan "commit metadata (${base}/HEAD..HEAD)" || exit 1
+ echo "OSS-GUARD: outgoing commits and branch name clean."
+ ;;
</code_context>
<issue_to_address>
**Untracked branches skip commit scans**
When the standalone guard runs on a branch without a configured push upstream, such as before its first push, when `@{push}` is unset, `git rev-parse` fails but the succeeding `sed` makes the command substitution succeed with an empty `base`. The resulting `/HEAD..HEAD` range fails in `git log`, whose error is discarded, so the guard reports clean without scanning commits.
Detect a missing push upstream and either determine the correct outgoing range or exit nonzero instead of reporting clean.
</issue_to_address>
### Comment 12
<location path="scripts/oss-github-guard.sh" line_range="37" />
<code_context>
+
+scan() { # scan <label> — text arrives on stdin, kept in $TMP
+ cat >"$TMP"
+ if grep -Ein "$PATTERNS" "$TMP" >/dev/null 2>&1; then
+ die "$1"
+ fi
</code_context>
<issue_to_address>
**Invalid patterns pass clean**
When a local forbidden-pattern fragment makes the combined regex invalid, if the combined regex is invalid, `grep` returns an error rather than a match; `scan` treats that result as clean and allows the contribution through with the configured checks disabled.
Validate the configured regex before scanning and exit nonzero on grep errors.
</issue_to_address>
### Comment 13
<location path="scripts/oss-github-guard.sh" line_range="18" />
<code_context>
+# live in scripts/.oss-guard-local.patterns (local, untracked): one regex
+# fragment per line, OR-joined into the scan. Without that file only the
+# generic patterns apply.
+PATTERNS='@(corp|internal)\.example'
+LABEL='internal / non-public context'
+PATTERN_FILE="$(dirname "$0")/.oss-guard-local.patterns"
</code_context>
<issue_to_address>
**Corporate emails evade generic scan**
When the local pattern file is absent or does not separately match the email domain, `PATTERNS` is used with `grep -E`, where `@(...)` matches a literal `@` followed by parentheses rather than grouping alternatives. An author such as `name@corp.example` therefore passes the generic email check unless a local pattern independently catches it.
Use ERE grouping without the literal `@` parentheses, for example `@(corp|internal)\.example` should be written as `@(corp|internal)\.example` only if `@` is intended literally before the group; otherwise use `@(corp|internal)`’s equivalent ERE as `@(corp|internal)` is not valid grouping—construct the intended domain pattern with `@(... )` removed as a literal, e.g. `@(corp|internal)` replaced by `@(corp|internal)` is not sufficient.
</issue_to_address>
### Comment 14
<location path=".agents/rules/git/oss-isolation.md" line_range="6" />
<code_context>
+description: Zero internal context in any public GitHub contribution. Mandatory preflight before publishing to github.com.
+---
+
+# OSS Isolation Rule (public GitHub)
+
+## The rule
</code_context>
<issue_to_address>
**New rule is missing from the rules index**
When this new agent rule is added without updating the repository guide's rules index, the repository guide's rules index omits the new OSS isolation rule, so agents relying on that index cannot discover it there.
Add the OSS isolation rule to the rules index in `.agents/repo-guide.md`.
</issue_to_address>
### Comment 15
<location path="scripts/oss-github-guard.sh" line_range="71" />
<code_context>
+ else
+ range="$remote_sha..$local_sha"
+ fi
+ git log --format='%H%n%B%n%an <%ae>%n%cn <%ce>' "$range" 2>/dev/null | scan "commits $range -> $remote_name (github.com)" || exit 1
+ done
+ echo "OSS-GUARD: push to $remote_name (github.com) clean."
</code_context>
<issue_to_address>
**Annotated tag text goes unchecked**
When a pushed annotated tag contains forbidden text in its annotation or tagger metadata, `git log` dereferences the tag to its target commit, so the tag annotation and tagger metadata are not scanned and can be published unchecked.
Scan the pushed annotated tag object, including its annotation and tagger metadata.
</issue_to_address>
### Comment 16
<location path="scripts/oss-github-guard.sh" line_range="59-60" />
<code_context>
+ # pre-push hook mode: args "<remote> <url>", stdin lines "<local_ref> <local_sha> <remote_ref> <remote_sha>"
+ remote_name="$1"; remote_url="$2"
+ case "$remote_url" in
+ *github.com*) : ;;
+ *) exit 0 ;; # internal remotes (GitLab) are out of scope for this guard
+ esac
+ while read -r local_ref local_sha remote_ref remote_sha; do
</code_context>
<issue_to_address>
**Uppercase hostnames bypass scanning**
When a GitHub remote URL uses uppercase letters in its hostname, the case-sensitive `case` pattern does not match the GitHub URL, so the script exits as though the remote were internal and skips the push scan.
Normalize the hostname’s case or use a case-insensitive GitHub URL check.
</issue_to_address>Sourcery assessment
Approval pending. 16 findings to address first.
Blocking findings: AGENTS.md:47, scripts/oss-github-guard.sh:71, scripts/oss-github-guard.sh:46, scripts/oss-github-guard.sh:46, scripts/oss-github-guard.sh:46, and 11 more
Add an always-on agent rule (.agents/rules/git/oss-isolation.md) and scripts/oss-github-guard.sh: a mechanical gate that scans outgoing commit metadata, branch names and PR/issue text before anything reaches a public remote. Organization-specific forbidden patterns live in scripts/.oss-guard-local.patterns (local, untracked) so the published script ships only the mechanism; the pre-push hook OR-joins them into the scan. AGENTS.md gains a mandatory pointer section.
c197638 to
8837db3
Compare
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|



Enforces strict Open Source Software (OSS) isolation for all contributions targeting public GitHub repositories.
This change introduces a mandatory preflight guard (
scripts/oss-github-guard.sh) to prevent internal context (e.g., corporate hostnames, internal system codenames, internal MR numbers, corporate email domains) from appearing in public artifacts.Impact includes:
github.com.ghCLI.This rule is enforced globally via updates to
AGENTS.mdand documented in.agents/rules/git/oss-isolation.md. The guard uses organization-specific patterns found in the untracked filescripts/.oss-guard-local.patterns.Requirement: Any attempt to push or interact with a public GitHub remote will halt with a non-zero exit if forbidden patterns are found; users must sanitize content before proceeding.
Summary by Sourcery
Enforce removal of internal context from all contributions targeting public GitHub repositories.
New Features:
Enhancements:
Documentation:
Chores: