-
Notifications
You must be signed in to change notification settings - Fork 0
feat(guardrails): add CI hard block, architecture advisory, and post-deploy verify hooks #119
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -510,6 +510,32 @@ export default async function guardrail(input: { | |||||||||||||
| throw new Error(text("merge blocked: run /review before merging")) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| // CI hard block: verify all checks are green before gh pr merge | ||||||||||||||
| if (/\bgh\s+pr\s+merge\b/i.test(cmd)) { | ||||||||||||||
| try { | ||||||||||||||
| const prMatch = cmd.match(/\bgh\s+pr\s+merge\s+(\d+)/i) | ||||||||||||||
| const prArg = prMatch ? prMatch[1] : "" | ||||||||||||||
| const proc = Bun.spawn(["gh", "pr", "checks", ...(prArg ? [prArg] : [])], { | ||||||||||||||
| cwd: input.worktree, | ||||||||||||||
| stdout: "pipe", | ||||||||||||||
| stderr: "pipe", | ||||||||||||||
| }) | ||||||||||||||
| const [ciOut] = await Promise.all([ | ||||||||||||||
| new Response(proc.stdout).text(), | ||||||||||||||
| new Response(proc.stderr).text(), | ||||||||||||||
| proc.exited, | ||||||||||||||
| ]) | ||||||||||||||
| if (proc.exitCode !== 0 || /fail|pending/i.test(ciOut)) { | ||||||||||||||
| await mark({ last_block: "bash", last_command: cmd, last_reason: "CI checks not all green" }) | ||||||||||||||
| throw new Error(text("merge blocked: CI checks not all green — run `gh pr checks` to verify")) | ||||||||||||||
| } | ||||||||||||||
| } catch (e) { | ||||||||||||||
| if (String(e).includes("blocked")) throw e | ||||||||||||||
| // gh unavailable or network failure — log so CI skip is observable | ||||||||||||||
| await mark({ last_block: "bash:ci-warn", last_command: cmd, last_reason: "CI check verification failed" }) | ||||||||||||||
| console.warn("[guardrail] CI check verification failed — gh may be unavailable: " + String(e)) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| // Direct push to protected branches | ||||||||||||||
| const protectedBranch = /^(main|master|develop|dev)$/ | ||||||||||||||
| if (/\bgit\s+push\b/i.test(cmd)) { | ||||||||||||||
|
|
@@ -614,11 +640,35 @@ export default async function guardrail(input: { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Architecture layer advisory | ||||||||||||||
| if ((item.tool === "edit" || item.tool === "write") && file && code(file)) { | ||||||||||||||
| const relFile = rel(input.worktree, file) | ||||||||||||||
| const content = typeof item.args?.content === "string" ? item.args.content : | ||||||||||||||
| typeof item.args?.newString === "string" ? item.args.newString : "" | ||||||||||||||
| if (content) { | ||||||||||||||
| const isUI = /^(src\/(ui|components|tui)\/)/i.test(relFile) | ||||||||||||||
| const isAPI = /^(src\/(api|routes)\/)/i.test(relFile) | ||||||||||||||
| const importsDB = /from\s+['"].*\/(db|database|model|sql)\//i.test(content) | ||||||||||||||
| const importsUI = /from\s+['"].*\/(ui|components|tui)\//i.test(content) | ||||||||||||||
| if (isUI && importsDB) { | ||||||||||||||
| out.output += "\n⚠️ Architecture: UI layer importing from DB layer directly. Consider using a service/repository layer." | ||||||||||||||
| } | ||||||||||||||
| if (isAPI && importsUI) { | ||||||||||||||
| out.output += "\n⚠️ Architecture: API layer importing from UI layer. This creates a circular dependency risk." | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // CI status advisory after push/PR create | ||||||||||||||
| if (item.tool === "bash" && /\b(git\s+push|gh\s+pr\s+create)\b/i.test(str(item.args?.command))) { | ||||||||||||||
| out.output = (out.output || "") + "\n⚠️ Remember to verify CI status: `gh pr checks`" | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Post-merge deployment verification advisory | ||||||||||||||
| if (item.tool === "bash" && /\bgh\s+pr\s+merge\b/i.test(str(item.args?.command))) { | ||||||||||||||
|
||||||||||||||
| if (item.tool === "bash" && /\bgh\s+pr\s+merge\b/i.test(str(item.args?.command))) { | |
| if ( | |
| item.tool === "bash" && | |
| /\bgh\s+pr\s+merge\b/i.test(str(item.args?.command)) && | |
| out.metadata?.exit === 0 | |
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the fallback path (when
gh pr checkscan’t be executed), the code only callsmark(...)but doesn’t emit any user-visible warning. That contradicts the inline comment (“warn so user knows CI was not verified”) and the PR description’s fallback-to-warning behavior. Consider appending a warning to thebashtool output forgh pr merge(e.g., viatool.execute.afterwhen the last state indicatesbash:ci-warn) so the user actually sees it.