Repository hooks
hooks · версия 0.1.2
Агенты и автоматизации3 нормы1 проверка
Connects Git and Claude Code to the repository dispatcher and runs package hooks on their events.
О пакете
Этот текст ещё не переведён. Ниже английский оригинал.
A package can enforce a norm at a Git or Claude Code event. The norm lists the hook under enforcers and declares enforcerKind: hook.
How it works
- On install and update,
syncfinds the repository from the project's nearest ancestor with a.gitfile or directory. It installspre-commitandcommit-msgin Git's configured hooks folder. Each callsshtuk hookwith the event and any commit message path supplied by Git. syncalso adds four entries to the repository's.claude/settings.json. They callshtuk hook agent:<Event>onSessionStart,PreToolUse(Bash, Write, Edit, MultiEdit),PostToolUse(Write, Edit, MultiEdit), andStop.- In each project selected by the dispatcher, the runner reads the
hookslists of all installed packages. A declaration has{name, event, tools, run, norm, timeout}. Claude Code hooks receive the original JSON on stdin. Git hooks receive event arguments on the command line. - When the dispatcher supplies
SHTUK_FILES, the runner usesSHTUK_OWNERSto remove files whose owner appears in the norm'sexceptlist. It skips a hook when that list excludes every supplied file. - Hook exit code 0 lets the event pass. Code 2 blocks it and reports the finding on stderr. Other exit codes report a broken hook and let the event pass.
Other people's hooks, repeats and updates
- For an existing shell hook,
syncappends one marked block. Git runs the block when the shell reaches it. Keep the dispatcher block reachable when editing the preceding script. - In the repository's Claude Code settings,
syncreplaces its own entries across events, including entries for the older direct runner. It keeps other entries and settings. Invalid JSON stopssyncand leaves the settings file untouched. shtuk run hooks removeremoves the repository dispatcher entries.shtuk run hooks installedchecks for missing, duplicate, or stale entries.
Norms
- HK-R01: the hook runner is installed once per event. The enforcer is the check
installed. - HK-R02: a database record that breaks a check does not reach the disk silently. The enforcers are the hooks
record-pre(does not let through a record with no header, no title, or an empty required field) andrecord-post(after a write runs the schema checks s01 to s03 on that record and tells the agent at once what is broken). - HK-R03: one commit touches one project. The
one-projecthook reports staged files owned by multiple projects. Setmode: enforcein the project's copy of the rule to block such commits.
Git and Claude Code need shtuk and bun on their PATH.
Нормы 3
| ID | Норма | Уровень | Режим | Enforcer |
|---|---|---|---|---|
| HK-R01 | В .claude/settings.json проекта раннер хуков пакетов стоит по одному разу на события SessionStart, PreToolUse, PostToolUse и Stop |
MUST | не пускает | проверка |
| HK-R02 | Когда агент пишет запись коллекции, которая ломает проверку схемы, хук не пускает запись или сразу после неё говорит агенту, что сломано |
MUST | не пускает | хук |
| HK-R03 | The staged files with an owner belong to at most one project |
MUST | наблюдает | хук |
«Не пускает» — enforcer останавливает нарушение; «наблюдает» — только отмечает его. Уровень MUST — обязательно, SHOULD — по умолчанию да.
Действия 3
| Имя | Что делает | Файл | Когда |
|---|---|---|---|
| sync | Install the repository dispatcher entries for Git and Claude Code | sync.ts | после установки после обновления |
| remove | Remove the repository dispatcher entries for Git and Claude Code | remove.ts | shtuk run |
| installed | The repository dispatcher is installed once per event норма HK-R01 | installed.ts | проверка |
Проверки запускает shtuk check, любое действие — shtuk run hooks <имя>. Действия «после установки» запускаются сами, только если пакет из доверенного источника.
Хуки агента 3
Страницы 3
Ложатся в проект по этим путям.
- /norms/rules/hooks/
- Раннер хуков стоит в настройках Claude Code проекта HK-R01
- Запись базы, ломающая проверку, не попадает на диск молча HK-R02
- One commit touches one project HK-R03
Файлы пакета 13
Ложатся в .shtukbase/packages/hooks/; отсюда запускаются действия.
hooks/one-project.ts 631 Б
hooks/record-post.ts 1.5 КБ
hooks/record-pre.ts 2.6 КБ
icon.svg 377 Б
install.ts 4.3 КБ
installed.ts 141 Б
lib/git-hooks.ts 3.0 КБ
lib/hooklib.ts 7.0 КБ
lib/write.ts 927 Б
remove.ts 99 Б
run.ts 2.8 КБ
sync.ts 95 Б
test/hooks.test.ts 10.1 КБ