Fix all guardrail findings (make lint, make test, make sast) across one or more repositories. This is a complete, repeatable workflow: sync with main, run all guardrails, fix every finding, update documentation, commit following standards, push, and create PRs.
For guardrail tools, refer to the CI/CD rule and Security rule. For commit conventions, refer to the Git Flow rule. For changelog updates, refer to the Documentation rule.
Vendor Detection
Auto-detect the Git hosting vendor from git remote get-url origin to determine the correct PR creation CLI:
| Remote URL contains |
Vendor |
PR CLI |
github.com |
GitHub |
gh pr create |
dev.azure.com or ssh.dev.azure.com |
Azure DevOps |
az repos pr create |
gitlab.com or gitlab |
GitLab |
glab mr create |
| Other |
Unknown |
Skip PR, report branch for manual creation |
Step-by-step Workflow (repeat for every repository)
Step 1 -- Sync with the default branch
cd <REPO_PATH>
git checkout <default-branch>
git fetch --all
git pull --rebase
- Detect the default branch with
git symbolic-ref refs/remotes/origin/HEAD (strip refs/remotes/origin/). Fall back to main if unavailable.
- If
pull --rebase fails due to conflicts, report the failure and skip this repo.
Step 2 -- Run all three guardrails
Run them in this exact order. Each gate must be evaluated independently -- even if one passes, the others may fail.
Gate 1: Lint
make lint
- Timeout: 3 minutes.
- Parse the output. Record every finding with file path, line number, rule, and message.
- NEVER invoke linter binaries directly. Always use
make lint.
Gate 2: Test
make test
- Timeout: 5 minutes.
- Record any failing test names and error messages.
- NEVER invoke test runners directly. Always use
make test.
Gate 3: SAST
make sast
- Timeout: 10 minutes -- SAST is the slowest gate (it runs CodeQL, Semgrep, Trivy, Hadolint, and Gitleaks).
- Parse the output. Record every finding with tool name, rule ID, file path, line number, and description.
- NEVER invoke SAST tools directly. Always use
make sast.
Decision point
- If all three gates pass with 0 findings: print
<repo>: SKIP(clean) and move to the next repo.
- If any gate has findings: proceed to Step 3.
Step 3 -- Create the feature branch
git checkout -b fix/<scope>
Branch naming rules (from the Git Flow rule):
- Format:
type/scope
- Choose the scope based on what was found:
- Lint-only findings:
fix/lint-findings
- SAST-only findings:
fix/sast-findings
- Test-only findings:
fix/test-findings
- Mixed findings:
fix/guardrail-findings
- If a specific tool dominates:
fix/codeql-findings, fix/semgrep-findings, etc.
- The branch type is always
fix for guardrail remediation.
Step 4 -- Fix each finding
Read the affected files, understand the context, and apply a minimal, targeted fix for each finding. Never refactor surrounding code.
4a. Lint fix patterns
| Linter / Rule |
Root Cause |
Fix |
unused variable/import |
Dead code left after refactoring |
Remove the unused variable or import |
ineffectual assignment |
Variable assigned but never read |
Remove assignment or use the value |
errcheck / unchecked error |
Return value of error-returning function ignored |
Assign to err and handle it, or explicitly ignore with _ = |
staticcheck / deprecated API |
Using deprecated function |
Replace with the recommended alternative |
govet / struct field alignment |
Struct fields not optimally ordered |
Reorder fields by size (largest first) |
revive / exported without comment |
Exported symbol missing doc comment |
Add a doc comment starting with the symbol name |
4b. Test fix patterns
| Failure Type |
Root Cause |
Fix |
| Assertion mismatch |
Code behavior changed but test not updated |
Update the test expectation to match the new correct behavior, or fix the code if the test was correct |
| Compilation error in test |
Test references a removed/renamed symbol |
Update the test to use the new symbol |
| Timeout |
Test relies on external service or has infinite loop |
Fix the logic or add proper mocking |
| Race condition |
Shared state across parallel tests |
Add proper synchronization or use t.Parallel() correctly |
Important: Tests must follow BDD structure (// given, // when, // then). If you modify a test, preserve or add this structure.
4c. SAST fix patterns
CodeQL:
| Rule |
Root Cause |
Fix |
go/useless-assignment-to-field |
Value receiver stores a parameter in a struct field used only through method values on the same local copy |
Remove the struct field. Replace callback methods with inline closures capturing the parameter. |
go/disabled-certificate-check |
InsecureSkipVerify: true hardcoded in tls.Config |
Replace the hardcoded true with a configurable setting field. Add // #nosec G402 -- controlled via configuration on the same line. |
go/sql-injection |
String concatenation in SQL queries |
Use parameterized queries ($1, $2) or whitelist-validated identifiers |
go/path-injection |
Unsanitized user input in file paths |
Sanitize with filepath.Clean and validate against an allowed base path |
go/log-injection |
User-controlled input directly in log messages |
Use structured logging fields instead of string interpolation |
Semgrep:
| Pattern |
Root Cause |
Fix |
| Hardcoded secret / credential |
API key, password, or token in source code |
Move to environment variable or secret manager |
| OWASP rule violation |
Insecure coding pattern (e.g., weak crypto, missing input validation) |
Apply the recommendation from the Semgrep rule description |
| Anti-pattern |
Code smell flagged by Semgrep rules |
Refactor to the recommended pattern |
Trivy (IaC scanning):
| Finding |
Root Cause |
Fix |
| Dockerfile misconfiguration |
Running as root, unpinned base image, etc. |
Pin image tags, add USER nonroot, use multi-stage builds |
| Kubernetes misconfiguration |
Missing resource limits, privileged containers, etc. |
Add resource limits, set securityContext properly |
| Terraform misconfiguration |
Missing encryption, overly permissive IAM, etc. |
Enable encryption, restrict IAM policies |
Hadolint (Dockerfile):
| Rule |
Root Cause |
Fix |
DL3007 |
Using latest tag |
Pin to a specific version |
DL3008 |
Unpinned apt-get install |
Pin package versions |
DL3025 |
Using CMD instead of ENTRYPOINT |
Use ENTRYPOINT for the main command |
SC2086 |
Unquoted variable in RUN |
Quote the variable |
Gitleaks (secrets):
| Finding |
Root Cause |
Fix |
| Secret detected in source |
Hardcoded secret, API key, or password |
Remove from source, add to .gitignore, rotate the exposed credential immediately |
| Secret in git history |
Previously committed secret |
Remove with git filter-branch or BFG, then rotate credentials |
For any rule not listed above: analyze the code, apply a minimal fix, and document the new pattern in the commit message body.
Step 5 -- Verify build
Run the appropriate build verification for the detected language:
| Language |
Build command |
| Go |
go build ./... |
| JavaScript/TypeScript |
npm run build or yarn build |
| Python |
python -m py_compile <main-module> |
| Java |
./gradlew build or mvn compile |
If compilation fails, diagnose and fix before proceeding.
Step 6 -- Re-run the failing guardrails
After applying fixes, re-run only the guardrails that originally failed:
make lint # if lint had findings
make test # if tests were failing
make sast # if SAST had findings
If new findings appear, fix them. Repeat until all three gates pass. If you cannot resolve a finding after 2 attempts, document it and proceed -- the PR description should note unresolved items.
Step 7 -- Update CHANGELOG.md
Read the existing CHANGELOG.md. Under ## [Unreleased], add entries in the appropriate category. Follow the Documentation rule for changelog conventions:
- Use simple past tense: "fixed", "removed", "replaced"
- Start each entry with a lowercase verb
- Use Keep a Changelog categories
Step 8 -- Stage and commit
Stage only the files you changed. Follow the Git Flow rule for commit message format:
- Format:
fix(<scope>): <subject in simple past tense>
- Use bullet points for multi-file changes
Step 9 -- Push the branch
GIT_SSH_COMMAND="ssh -o BatchMode=yes -o ConnectTimeout=15" git push -u origin <branch> --force
--force is safe because this is a new branch we just created
Step 10 -- Restore the original branch
git checkout <default-branch>
Step 11 -- Create Pull Request
Use the detected vendor CLI (GitHub: gh pr create, Azure DevOps: az repos pr create, GitLab: glab mr create).
PR title rules:
- Format:
fix(<scope>): resolved <tool/gate> findings
- Under 70 characters
- Simple past tense, lowercase
Error Handling
| Situation |
Action |
git pull --rebase fails |
Print FAIL(rebase conflict), restore branch, skip repo |
make lint times out |
Print FAIL(lint timeout), skip repo |
make test times out |
Print FAIL(test timeout), skip repo |
make sast times out |
Print FAIL(sast timeout), skip repo |
| Build fails after fix |
Diagnose and fix; if unresolvable, print FAIL(build), restore branch, skip repo |
| Re-run still has findings after 2 fix attempts |
Document unresolved items in PR description, proceed with commit |
git push fails |
Print FAIL(push: <error>), restore branch, skip repo |
| PR creation fails |
Print FAIL(pr: <error>) but branch is already pushed -- report for manual PR creation |
| Unknown rule from any tool |
Read and analyze the code, apply minimal fix, document in commit message |
| Gitleaks finds a real secret |
Stop immediately, warn the user, do NOT commit the secret -- it must be rotated first |
1---
2name: fix-guardrails
3description: Fix all guardrail findings (make lint, make test, make sast) across repositories. Use when the user asks to fix linting errors, test failures, SAST findings, or run the full guardrail remediation workflow.
4metadata:
5 source: https://skillmd.com/skills/aibot88/fix-guardrails
6---
7
8Fix all guardrail findings (`make lint`, `make test`, `make sast`) across one or more repositories. This is a complete, repeatable workflow: sync with main, run all guardrails, fix every finding, update documentation, commit following standards, push, and create PRs.
9
10For guardrail tools, refer to the CI/CD rule and Security rule. For commit conventions, refer to the Git Flow rule. For changelog updates, refer to the Documentation rule.
11
12## Vendor Detection
13
14Auto-detect the Git hosting vendor from `git remote get-url origin` to determine the correct PR creation CLI:
15
16| Remote URL contains | Vendor | PR CLI |
17|----------------------------------------|--------------|--------------------------------------------|
18| `github.com` | GitHub | `gh pr create` |
19| `dev.azure.com` or `ssh.dev.azure.com` | Azure DevOps | `az repos pr create` |
20| `gitlab.com` or `gitlab` | GitLab | `glab mr create` |
21| Other | Unknown | Skip PR, report branch for manual creation |
22
23---
24
25## Step-by-step Workflow (repeat for every repository)
26
27### Step 1 -- Sync with the default branch
28
29```bash
30cd <REPO_PATH>
31git checkout <default-branch>
32git fetch --all
33git pull --rebase
34```
35
36- Detect the default branch with `git symbolic-ref refs/remotes/origin/HEAD` (strip `refs/remotes/origin/`). Fall back to `main` if unavailable.
37- If `pull --rebase` fails due to conflicts, report the failure and **skip this repo**.
38
39### Step 2 -- Run all three guardrails
40
41Run them **in this exact order**. Each gate must be evaluated independently -- even if one passes, the others may fail.
42
43#### Gate 1: Lint
44
45```bash
46make lint
47```
48
49- Timeout: **3 minutes**.
50- Parse the output. Record every finding with **file path**, **line number**, **rule**, and **message**.
51- NEVER invoke linter binaries directly. Always use `make lint`.
52
53#### Gate 2: Test
54
55```bash
56make test
57```
58
59- Timeout: **5 minutes**.
60- Record any failing test names and error messages.
61- NEVER invoke test runners directly. Always use `make test`.
62
63#### Gate 3: SAST
64
65```bash
66make sast
67```
68
69- Timeout: **10 minutes** -- SAST is the slowest gate (it runs CodeQL, Semgrep, Trivy, Hadolint, and Gitleaks).
70- Parse the output. Record every finding with **tool name**, **rule ID**, **file path**, **line number**, and **description**.
71- NEVER invoke SAST tools directly. Always use `make sast`.
72
73#### Decision point
74
75- If **all three gates pass** with 0 findings: print `<repo>: SKIP(clean)` and move to the next repo.
76- If **any gate has findings**: proceed to Step 3.
77
78### Step 3 -- Create the feature branch
79
80```bash
81git checkout -b fix/<scope>
82```
83
84**Branch naming rules** (from the Git Flow rule):
85
86- Format: `type/scope`
87- Choose the scope based on what was found:
88 - Lint-only findings: `fix/lint-findings`
89 - SAST-only findings: `fix/sast-findings`
90 - Test-only findings: `fix/test-findings`
91 - Mixed findings: `fix/guardrail-findings`
92 - If a specific tool dominates: `fix/codeql-findings`, `fix/semgrep-findings`, etc.
93- The branch type is always `fix` for guardrail remediation.
94
95### Step 4 -- Fix each finding
96
97Read the affected files, understand the context, and apply a **minimal, targeted fix** for each finding. Never refactor surrounding code.
98
99#### 4a. Lint fix patterns
100
101| Linter / Rule | Root Cause | Fix |
102|-------------------------------------|--------------------------------------------------|----------------------------------------------------------------|
103| `unused variable/import` | Dead code left after refactoring | Remove the unused variable or import |
104| `ineffectual assignment` | Variable assigned but never read | Remove assignment or use the value |
105| `errcheck` / unchecked error | Return value of error-returning function ignored | Assign to `err` and handle it, or explicitly ignore with `_ =` |
106| `staticcheck` / deprecated API | Using deprecated function | Replace with the recommended alternative |
107| `govet` / struct field alignment | Struct fields not optimally ordered | Reorder fields by size (largest first) |
108| `revive` / exported without comment | Exported symbol missing doc comment | Add a doc comment starting with the symbol name |
109
110#### 4b. Test fix patterns
111
112| Failure Type | Root Cause | Fix |
113|---------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
114| Assertion mismatch | Code behavior changed but test not updated | Update the test expectation to match the new correct behavior, or fix the code if the test was correct |
115| Compilation error in test | Test references a removed/renamed symbol | Update the test to use the new symbol |
116| Timeout | Test relies on external service or has infinite loop | Fix the logic or add proper mocking |
117| Race condition | Shared state across parallel tests | Add proper synchronization or use `t.Parallel()` correctly |
118
119**Important:** Tests must follow BDD structure (`// given`, `// when`, `// then`). If you modify a test, preserve or add this structure.
120
121#### 4c. SAST fix patterns
122
123**CodeQL:**
124
125| Rule | Root Cause | Fix |
126|----------------------------------|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
127| `go/useless-assignment-to-field` | Value receiver stores a parameter in a struct field used only through method values on the same local copy | Remove the struct field. Replace callback methods with **inline closures** capturing the parameter. |
128| `go/disabled-certificate-check` | `InsecureSkipVerify: true` hardcoded in `tls.Config` | Replace the hardcoded `true` with a configurable setting field. Add `// #nosec G402 -- controlled via configuration` on the same line. |
129| `go/sql-injection` | String concatenation in SQL queries | Use parameterized queries (`$1`, `$2`) or whitelist-validated identifiers |
130| `go/path-injection` | Unsanitized user input in file paths | Sanitize with `filepath.Clean` and validate against an allowed base path |
131| `go/log-injection` | User-controlled input directly in log messages | Use structured logging fields instead of string interpolation |
132
133**Semgrep:**
134
135| Pattern | Root Cause | Fix |
136|-------------------------------|-----------------------------------------------------------------------|------------------------------------------------------------|
137| Hardcoded secret / credential | API key, password, or token in source code | Move to environment variable or secret manager |
138| OWASP rule violation | Insecure coding pattern (e.g., weak crypto, missing input validation) | Apply the recommendation from the Semgrep rule description |
139| Anti-pattern | Code smell flagged by Semgrep rules | Refactor to the recommended pattern |
140
141**Trivy (IaC scanning):**
142
143| Finding | Root Cause | Fix |
144|-----------------------------|------------------------------------------------------|------------------------------------------------------------|
145| Dockerfile misconfiguration | Running as root, unpinned base image, etc. | Pin image tags, add `USER nonroot`, use multi-stage builds |
146| Kubernetes misconfiguration | Missing resource limits, privileged containers, etc. | Add resource limits, set `securityContext` properly |
147| Terraform misconfiguration | Missing encryption, overly permissive IAM, etc. | Enable encryption, restrict IAM policies |
148
149**Hadolint (Dockerfile):**
150
151| Rule | Root Cause | Fix |
152|----------|-------------------------------------|---------------------------------------|
153| `DL3007` | Using `latest` tag | Pin to a specific version |
154| `DL3008` | Unpinned `apt-get install` | Pin package versions |
155| `DL3025` | Using `CMD` instead of `ENTRYPOINT` | Use `ENTRYPOINT` for the main command |
156| `SC2086` | Unquoted variable in `RUN` | Quote the variable |
157
158**Gitleaks (secrets):**
159
160| Finding | Root Cause | Fix |
161|---------------------------|----------------------------------------|------------------------------------------------------------------------------------|
162| Secret detected in source | Hardcoded secret, API key, or password | Remove from source, add to `.gitignore`, rotate the exposed credential immediately |
163| Secret in git history | Previously committed secret | Remove with `git filter-branch` or BFG, then rotate credentials |
164
165For **any rule not listed above**: analyze the code, apply a minimal fix, and document the new pattern in the commit message body.
166
167### Step 5 -- Verify build
168
169Run the appropriate build verification for the detected language:
170
171| Language | Build command |
172|-----------------------|--------------------------------------|
173| Go | `go build ./...` |
174| JavaScript/TypeScript | `npm run build` or `yarn build` |
175| Python | `python -m py_compile <main-module>` |
176| Java | `./gradlew build` or `mvn compile` |
177
178If compilation fails, diagnose and fix before proceeding.
179
180### Step 6 -- Re-run the failing guardrails
181
182After applying fixes, re-run **only the guardrails that originally failed**:
183
184```bash
185make lint # if lint had findings
186make test # if tests were failing
187make sast # if SAST had findings
188```
189
190If new findings appear, fix them. Repeat until all three gates pass. If you cannot resolve a finding after 2 attempts, document it and proceed -- the PR description should note unresolved items.
191
192### Step 7 -- Update CHANGELOG.md
193
194Read the existing `CHANGELOG.md`. Under `## [Unreleased]`, add entries in the appropriate category. Follow the Documentation rule for changelog conventions:
195
196- Use **simple past tense**: "fixed", "removed", "replaced"
197- Start each entry with a **lowercase verb**
198- Use [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) categories
199
200### Step 8 -- Stage and commit
201
202Stage only the files you changed. Follow the Git Flow rule for commit message format:
203
204- Format: `fix(<scope>): <subject in simple past tense>`
205- Use bullet points for multi-file changes
206
207### Step 9 -- Push the branch
208
209```bash
210GIT_SSH_COMMAND="ssh -o BatchMode=yes -o ConnectTimeout=15" git push -u origin <branch> --force
211```
212
213- `--force` is safe because this is a **new branch we just created**
214
215### Step 10 -- Restore the original branch
216
217```bash
218git checkout <default-branch>
219```
220
221### Step 11 -- Create Pull Request
222
223Use the detected vendor CLI (GitHub: `gh pr create`, Azure DevOps: `az repos pr create`, GitLab: `glab mr create`).
224
225**PR title rules:**
226
227- Format: `fix(<scope>): resolved <tool/gate> findings`
228- Under 70 characters
229- Simple past tense, lowercase
230
231## Error Handling
232
233| Situation | Action |
234|------------------------------------------------|-------------------------------------------------------------------------------------------|
235| `git pull --rebase` fails | Print `FAIL(rebase conflict)`, restore branch, skip repo |
236| `make lint` times out | Print `FAIL(lint timeout)`, skip repo |
237| `make test` times out | Print `FAIL(test timeout)`, skip repo |
238| `make sast` times out | Print `FAIL(sast timeout)`, skip repo |
239| Build fails after fix | Diagnose and fix; if unresolvable, print `FAIL(build)`, restore branch, skip repo |
240| Re-run still has findings after 2 fix attempts | Document unresolved items in PR description, proceed with commit |
241| `git push` fails | Print `FAIL(push: <error>)`, restore branch, skip repo |
242| PR creation fails | Print `FAIL(pr: <error>)` but branch is already pushed -- report for manual PR creation |
243| Unknown rule from any tool | Read and analyze the code, apply minimal fix, document in commit message |
244| Gitleaks finds a real secret | **Stop immediately**, warn the user, do NOT commit the secret -- it must be rotated first |