Skip to content

Commit f6b24e9

Browse files
terisukeclaude
andcommitted
feat(guardrails): Wave 8 — review fixes + 9 hooks + multi-model delegation
Review fixes (PR #128 feedback): - Fix active_task_count race: counter → Map-based callID tracking - Fix verify-agent-output: parse <task_result> payload instead of raw length - Fix enforce-soak-time: add user-visible advisory via out.output - Fix enforce-domain-naming: add user-visible advisory via out.output - Fix issue_verification_done: conditional on reviewed && factchecked - Add per-provider cost tracking to session state New plugin hooks (5): - verify-state-file-integrity: JSON parse check + auto-repair - audit-docker-build-args: detect secrets in --build-arg - enforce-review-reading: stale review detection (review_at < push_at) - pr-guard: preflight check (tests + typecheck) before gh pr create - stop-test-gate: block push/merge without test execution New CI workflow hooks (4): - enforce-seed-data-verification (seed-verify.yml) - workflow-sync-guard (workflow-sync.yml) - inject-claude-review-on-checks (pr-management.yml) - post-pr-create-review-trigger (pr-management.yml) Multi-model delegation enhancement (OpenCode competitive advantage): - Provider-aware routing: recommend optimal providers per agent tier - Per-provider LLM call tracking: llm_calls_by_provider map - Cost waste detection: low-tier agent on high-tier model - Tier mismatch advisory: surface in compacting context - Session provider tracking: list of all providers used guardrail.ts: 987 → 1184 lines (+197) Closes #124, #125, #126 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent ab477ad commit f6b24e9

4 files changed

Lines changed: 544 additions & 41 deletions

File tree

‎.github/workflows/pr-management.yml‎

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ name: pr-management
22

33
on:
44
pull_request_target:
5-
types: [opened]
5+
types: [opened, reopened]
6+
check_suite:
7+
types: [completed]
68

79
jobs:
810
check-duplicates:
11+
if: github.event_name == 'pull_request_target' && github.event.action == 'opened'
912
runs-on: ubuntu-latest
1013
permissions:
1114
contents: read
@@ -72,6 +75,7 @@ jobs:
7275
fi
7376
7477
add-contributor-label:
78+
if: github.event_name == 'pull_request_target' && github.event.action == 'opened'
7579
runs-on: ubuntu-latest
7680
permissions:
7781
pull-requests: write
@@ -93,3 +97,94 @@ jobs:
9397
labels: ['contributor']
9498
});
9599
}
100+
101+
inject-review-on-failure:
102+
if: >-
103+
github.event_name == 'check_suite' &&
104+
github.event.check_suite.conclusion == 'failure' &&
105+
github.event.check_suite.pull_requests[0]
106+
runs-on: ubuntu-latest
107+
permissions:
108+
pull-requests: write
109+
steps:
110+
- name: Comment review suggestion on failed CI
111+
uses: actions/github-script@v8
112+
with:
113+
script: |
114+
const prs = context.payload.check_suite.pull_requests;
115+
if (!prs || prs.length === 0) return;
116+
117+
const prNumber = prs[0].number;
118+
const marker = '<!-- inject-review-on-failure -->';
119+
120+
// Check for existing comment to avoid duplicates
121+
const { data: comments } = await github.rest.issues.listComments({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: prNumber
125+
});
126+
127+
const existing = comments.find(c => c.body.includes(marker));
128+
if (existing) {
129+
core.info(`Review suggestion already posted on PR #${prNumber}`);
130+
return;
131+
}
132+
133+
const suite = context.payload.check_suite;
134+
const body = `${marker}
135+
**CI failed** on commit \`${suite.head_sha.substring(0, 7)}\`
136+
137+
Consider running \`/review\` to investigate the failure before pushing another attempt.`;
138+
139+
await github.rest.issues.createComment({
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
issue_number: prNumber,
143+
body
144+
});
145+
146+
core.info(`Posted review suggestion on PR #${prNumber}`);
147+
148+
post-pr-create-review-trigger:
149+
if: >-
150+
github.event_name == 'pull_request_target' &&
151+
(github.event.action == 'opened' || github.event.action == 'reopened')
152+
runs-on: ubuntu-latest
153+
permissions:
154+
pull-requests: write
155+
steps:
156+
- name: Comment automated review notice
157+
uses: actions/github-script@v8
158+
with:
159+
script: |
160+
const pr = context.payload.pull_request;
161+
const marker = '<!-- post-pr-review-trigger -->';
162+
163+
// Check for existing comment to avoid duplicates on reopen
164+
const { data: comments } = await github.rest.issues.listComments({
165+
owner: context.repo.owner,
166+
repo: context.repo.repo,
167+
issue_number: pr.number
168+
});
169+
170+
const existing = comments.find(c => c.body.includes(marker));
171+
if (existing) {
172+
core.info(`Review notice already posted on PR #${pr.number}`);
173+
return;
174+
}
175+
176+
const action = context.payload.action === 'reopened' ? 'reopened' : 'opened';
177+
const body = `${marker}
178+
**New PR ${action}** -- automated review will run on the next push.
179+
180+
To trigger a manual review, comment \`/review\` on this PR.`;
181+
182+
await github.rest.issues.createComment({
183+
owner: context.repo.owner,
184+
repo: context.repo.repo,
185+
issue_number: pr.number,
186+
body
187+
});
188+
189+
core.info(`Posted review trigger notice on PR #${pr.number} (${action})`);
190+

‎.github/workflows/seed-verify.yml‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: seed-verify
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
pull_request_target:
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
check-seed-data:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
20+
fetch-depth: 0
21+
22+
- name: Detect seed file changes
23+
id: detect
24+
run: |
25+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
26+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
27+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
28+
else
29+
BASE_SHA="${{ github.event.before }}"
30+
HEAD_SHA="${{ github.sha }}"
31+
fi
32+
33+
SEED_PATTERNS="prisma/seed.* scripts/seed.* **/seed.sql"
34+
CHANGED_SEEDS=""
35+
36+
for pattern in $SEED_PATTERNS; do
37+
MATCHES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- "$pattern" 2>/dev/null || true)
38+
if [ -n "$MATCHES" ]; then
39+
CHANGED_SEEDS="$CHANGED_SEEDS $MATCHES"
40+
fi
41+
done
42+
43+
CHANGED_SEEDS=$(echo "$CHANGED_SEEDS" | xargs)
44+
45+
if [ -z "$CHANGED_SEEDS" ]; then
46+
echo "No seed files modified"
47+
echo "changed=false" >> "$GITHUB_OUTPUT"
48+
else
49+
echo "Seed files modified: $CHANGED_SEEDS"
50+
echo "changed=true" >> "$GITHUB_OUTPUT"
51+
echo "files=$CHANGED_SEEDS" >> "$GITHUB_OUTPUT"
52+
fi
53+
54+
- name: Verify seed checksums
55+
if: steps.detect.outputs.changed == 'true'
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
FILES="${{ steps.detect.outputs.files }}"
60+
CHECKSUM_FILE=".seed-checksums"
61+
REPORT=""
62+
HAS_MISMATCH="false"
63+
64+
echo "=== Seed Data Verification ==="
65+
echo "Modified seed files: $FILES"
66+
echo ""
67+
68+
for f in $FILES; do
69+
if [ -f "$f" ]; then
70+
CURRENT_HASH=$(sha256sum "$f" | awk '{print $1}')
71+
echo "File: $f"
72+
echo " SHA-256: $CURRENT_HASH"
73+
74+
if [ -f "$CHECKSUM_FILE" ]; then
75+
EXPECTED_HASH=$(grep "$f" "$CHECKSUM_FILE" | awk '{print $1}' || true)
76+
if [ -n "$EXPECTED_HASH" ] && [ "$CURRENT_HASH" != "$EXPECTED_HASH" ]; then
77+
echo " Status: CHANGED (was $EXPECTED_HASH)"
78+
HAS_MISMATCH="true"
79+
REPORT="$REPORT\n- \`$f\`: checksum changed"
80+
else
81+
echo " Status: OK (new or matching)"
82+
REPORT="$REPORT\n- \`$f\`: new or matching checksum"
83+
fi
84+
else
85+
echo " Status: No baseline checksum file found"
86+
REPORT="$REPORT\n- \`$f\`: no baseline (.seed-checksums missing)"
87+
fi
88+
echo ""
89+
fi
90+
done
91+
92+
# Post summary comment on PRs
93+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
94+
PR_NUMBER="${{ github.event.pull_request.number }}"
95+
MARKER="<!-- seed-verify -->"
96+
97+
if [ "$HAS_MISMATCH" = "true" ]; then
98+
BODY="$MARKER
99+
**Seed Data Verification**
100+
101+
Seed files were modified in this PR. Checksum mismatches detected:
102+
$(echo -e "$REPORT")
103+
104+
Please verify these seed data changes are intentional and update \`.seed-checksums\` if needed."
105+
else
106+
BODY="$MARKER
107+
**Seed Data Verification**
108+
109+
Seed files were modified in this PR:
110+
$(echo -e "$REPORT")
111+
112+
No checksum mismatches found."
113+
fi
114+
115+
# Upsert comment (avoid duplicates)
116+
EXISTING=$(gh api "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \
117+
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
118+
119+
if [ -n "$EXISTING" ]; then
120+
gh api "repos/${{ github.repository }}/issues/comments/$EXISTING" \
121+
-X PATCH -f body="$BODY"
122+
else
123+
gh pr comment "$PR_NUMBER" --body "$BODY"
124+
fi
125+
fi
126+
127+
echo "=== Verification complete ==="
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: workflow-sync-guard
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
pull_request_target:
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
check-workflow-changes:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
20+
fetch-depth: 0
21+
22+
- name: Detect workflow file changes
23+
id: detect
24+
run: |
25+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
26+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
27+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
28+
else
29+
BASE_SHA="${{ github.event.before }}"
30+
HEAD_SHA="${{ github.sha }}"
31+
fi
32+
33+
CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '.github/workflows/' 2>/dev/null || true)
34+
35+
if [ -z "$CHANGED" ]; then
36+
echo "No workflow files modified"
37+
echo "changed=false" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "Workflow files modified:"
40+
echo "$CHANGED"
41+
echo "changed=true" >> "$GITHUB_OUTPUT"
42+
# Store as single-line comma-separated for output
43+
FILES_LIST=$(echo "$CHANGED" | tr '\n' ',' | sed 's/,$//')
44+
echo "files=$FILES_LIST" >> "$GITHUB_OUTPUT"
45+
fi
46+
47+
- name: Post upstream compatibility warning
48+
if: steps.detect.outputs.changed == 'true' && github.event_name == 'pull_request_target'
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
PR_NUMBER="${{ github.event.pull_request.number }}"
53+
FILES="${{ steps.detect.outputs.files }}"
54+
MARKER="<!-- workflow-sync-guard -->"
55+
56+
# Format file list as markdown
57+
FILE_LIST=""
58+
IFS=',' read -ra FILE_ARRAY <<< "$FILES"
59+
for f in "${FILE_ARRAY[@]}"; do
60+
FILE_LIST="$FILE_LIST\n- \`$f\`"
61+
done
62+
63+
BODY="$MARKER
64+
**Workflow files modified -- verify upstream compatibility**
65+
66+
The following workflow files were changed in this PR:
67+
$(echo -e "$FILE_LIST")
68+
69+
Before merging, please verify:
70+
- [ ] Changes do not break upstream sync (\`upstream-sync.yml\` restores our workflows on merge)
71+
- [ ] New workflows use \`pull_request_target\` (not \`pull_request\`) for fork compatibility
72+
- [ ] Runner is set to \`ubuntu-latest\` (not blacksmith or other custom runners)
73+
- [ ] No secrets are exposed in workflow logs"
74+
75+
# Upsert comment (avoid duplicates)
76+
EXISTING=$(gh api "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \
77+
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
78+
79+
if [ -n "$EXISTING" ]; then
80+
gh api "repos/${{ github.repository }}/issues/comments/$EXISTING" \
81+
-X PATCH -f body="$BODY"
82+
else
83+
gh pr comment "$PR_NUMBER" --body "$BODY"
84+
fi

0 commit comments

Comments
 (0)