Better Bots via Hooks

Better Bots via Hooks 图片 1
Better Bots via Hooks 图片 2
Better Bots via Hooks 图片 3

markdownlint-disable MD003 MD033 MD046

It can be tedious trying to get your bot to do exactly what you want to do, but it’s not always necessary. If there are hard conventions that you need to enforce (like tidying, not committing certain kinds of changes), try enforcing these at the git pre-commit hook level. The advantage of this is that you don’t need to go through contortions to put certain kinds of requirements in AGENT.md files, skill instructions etc. If you let your agent commit your code, the pre-commit hook can prevent them from committing until they play by the rules.

markdownlint-disable-line

" Captain Hook Topiary at Epcot Flower & Garden Festival 2014 " by Austin Kirk is licensed under CC BY 2.0.# Caveat Emptor

It’s always possible that your agent decides to commit with --no-verify or even deletes your hooks, so consider this part of a belt and suspenders approach to getting the results you want.# Show Me the Hooks

Here’s an example of a pre-commit hook that I’m using formymindisracing.com. It

prevents commits to main

prevents updates to a scaffolding file that I keep under version control but don’t want changed

enforces tidying and linting:

#!/bin/sh

Pre-commit hook to run precious lint on staged files

Check if we're on main branch

branch = $( git symbolic-ref --short HEAD 2>/dev/null ) if [ " $branch " = "main" ]; then echo "ERROR: Direct commits to 'main' branch are not allowed." echo "Please create a feature branch instead:" echo " git checkout -b feature/your-feature-name" exit 1 fi

Block commits that include.serena/project.yml (tool artifact, never commit)

if git diff --cached --name-only | grep -q '^.serena/project.yml ; then echo "ERROR:.serena/project.yml is staged for commit." echo "This file is a local tool artifact and should not be committed." echo " git reset HEAD.serena/project.yml" exit 1 fi

Run precious lint on staged files

precious lint -q --staged

Capture the exit code

RESULT = $?

If preciou…

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论