Repository navigation
chore(agents): enforce OSS isolation with a mechanical pre-push guard #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| trigger: always_on | ||
| description: Zero internal context in any public GitHub contribution. Mandatory preflight before publishing to github.com. | ||
| --- | ||
|
|
||
| # OSS Isolation Rule (public GitHub) | ||
|
|
||
| ## The rule | ||
|
|
||
| **Public GitHub remotes (`origin`, `github.com`) and internal development | ||
| remotes are two separate worlds.** No internal context may ever appear in any | ||
| public GitHub artifact — not even as "evidence" or "provenance". | ||
|
|
||
| This applies to **every** contribution channel, for **every** agent runtime | ||
| (Cursor, Claude Code, Codex, and any CLI agent): | ||
|
|
||
| - PR titles, bodies, comments, and code-review replies | ||
| - Issues and issue comments | ||
| - Branch names and commit messages | ||
| - Author / committer emails (use the personal public identity, never a | ||
| corporate address) | ||
| - Code comments, test fixtures, documentation, changelogs | ||
|
|
||
| ## Forbidden patterns | ||
|
|
||
| Never write or paste into anything destined for GitHub: | ||
|
|
||
| | Pattern class | Example of the leak | | ||
| | --------------------------------------------------------- | -------------------------------------- | | ||
| | Corporate host names and internal group paths | shadow-MR / pipeline / work-item links | | ||
| | Corporate email domains in author metadata | commit author `@corp.example` | | ||
| | Internal system codenames | release train / environment names | | ||
| | Internal MR/pipeline/job numbers tied to internal systems | "!105", "builder 3029698363" | | ||
|
|
||
| The concrete patterns for this organization live in | ||
| `scripts/.oss-guard-local.patterns` (local, untracked — never commit it). The | ||
| mechanical guard reads that file and adds its patterns to the generic scan. | ||
|
|
||
| Generic engineering words (`canary`, `draft`, `shadow review`) are fine. | ||
| Internal _system names_ and _links_ are not. When unsure, drop the sentence — | ||
| the public PR must stand on its own without internal evidence. | ||
|
|
||
| ## Mandatory preflight (mechanical gate) | ||
|
|
||
| Before **any** of these actions targeting a public remote: | ||
|
|
||
| - `git push` to a `github.com` remote | ||
| - `gh pr create` / `gh pr edit` / `gh pr comment` / `gh issue create` | ||
|
ThePlenkov marked this conversation as resolved.
Resolved
|
||
|
|
||
| run: | ||
|
|
||
| ```sh | ||
| scripts/oss-github-guard.sh # scans outgoing commits + branch name | ||
| scripts/oss-github-guard.sh --pr <N> # scans live PR text via gh | ||
| ``` | ||
|
|
||
| The guard exits non-zero on any forbidden pattern. **A non-zero exit is a hard | ||
| stop** — fix the text, do not bypass, do not `--no-verify`. | ||
|
|
||
| ## Summarizing internal work for a public PR | ||
|
|
||
| Rewrite from scratch in public terms: what the bug was, what changed, which | ||
| local tests pass. Internal MR numbers, pipelines, jobs, and system names are | ||
| never part of that story. If a commit message or prior PR body already | ||
| contains internal references, do not copy it — sanitize first. | ||
|
|
||
| ## Why this exists | ||
|
|
||
| Prose alone failed: public contributions kept picking up internal links, | ||
| system codenames and corporate emails. The guard script plus this always-on | ||
| rule are the enforced baseline. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,3 +190,4 @@ gascity/AGENTS.md | |
| .beads-credential-key | ||
| .beads/proxieddb/ | ||
| *.gate.lock* | ||
| scripts/.oss-guard-local.patterns | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env sh | ||
| # oss-github-guard.sh — block non-public internal context from reaching public GitHub. | ||
| # | ||
| # Usage: | ||
| # scripts/oss-github-guard.sh # scan outgoing commits + branch name (pre-push mode or HEAD) | ||
| # scripts/oss-github-guard.sh --pr <N> # scan a live PR's title/body/comments via gh | ||
| # scripts/oss-github-guard.sh --file <f> # scan an arbitrary text file (e.g. a draft PR body) | ||
| # | ||
| # Exit 0 = clean, exit 1 = forbidden context found, exit 2 = usage/infra error. | ||
| # Installed as a pre-push hook it only fires for github.com remotes. | ||
|
|
||
| set -u | ||
|
|
||
| # Generic fallback patterns safe to publish. Organization-specific patterns | ||
| # 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' | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| 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" | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
ThePlenkov marked this conversation as resolved.
Resolved
|
||
| TMP=$(mktemp) || exit 2 | ||
| trap 'rm -f "$TMP"' EXIT | ||
|
|
||
| die() { | ||
| echo "OSS-GUARD: forbidden $LABEL detected in [$1]:" >&2 | ||
| grep -Ein "$PATTERNS" "$TMP" | sed 's/^/ /' >&2 | ||
| echo "OSS-GUARD: sanitize the text before publishing to github.com (see .agents/rules/git/oss-isolation.md)." >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| scan() { # scan <label> — text arrives on stdin, kept in $TMP | ||
| cat >"$TMP" | ||
| if grep -Ein "$PATTERNS" "$TMP" >/dev/null 2>&1; then | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| die "$1" | ||
|
Check warning on line 38 in scripts/oss-github-guard.sh
|
||
| 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 | ||
|
ThePlenkov marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
ThePlenkov marked this conversation as resolved.
Resolved
|
||
| echo "OSS-GUARD: PR $2 clean." | ||
| ;; | ||
| --file) | ||
| [ -n "${2:-}" ] || { echo "usage: $0 --file <path>" >&2; exit 2; } | ||
| scan "file $2" <"$2" | ||
| echo "OSS-GUARD: $2 clean." | ||
| ;; | ||
| *) | ||
| if [ $# -ge 2 ]; then | ||
| # 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 | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| esac | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| while read -r local_ref local_sha remote_ref remote_sha; do | ||
| [ "$local_sha" = "0000000000000000000000000000000000000000" ] && continue | ||
| branch=${local_ref#refs/heads/} | ||
| printf '%s\n' "$branch" | scan "branch name ($branch)" || exit 1 | ||
| if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then | ||
| range="$local_sha" | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| else | ||
|
ThePlenkov marked this conversation as resolved.
Resolved
|
||
| 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 | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
|
||
| done | ||
| echo "OSS-GUARD: push to $remote_name (github.com) clean." | ||
| exit 0 | ||
| fi | ||
| # 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 | ||
|
sourcery-ai[bot] marked this conversation as resolved.
Resolved
sourcery-ai[bot] marked this conversation as resolved.
Resolved
ThePlenkov marked this conversation as resolved.
Resolved
|
||
| echo "OSS-GUARD: outgoing commits and branch name clean." | ||
| ;; | ||
| esac | ||
| exit 0 | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.