0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kiroのagent hooksを活用してCI失敗率を下げる

Posted at

kiroの作ったコードを実際Pushしてみると、CIに失敗することがあります。それ自体は問題ないのですが、毎回失敗していると修正が手間になってきます。
特にLinterとかは「自分でやってくれ」と思うこともしばしば。

そこでagent hooksを活用して自動でLintをやってくるよようにしました。

🚨手順

画像のようにKiroのアイコン -> Agent Hooksをクリックし、Describe a hook using natural languageとかかれた下の入力欄にやって欲しいことを書くだけ。
そうすると左のSessionが新しく立ち上がりhooksを作ります。

スクリーンショット 2025-12-13 20.54.31.png

📂vibeモードではできないの?

作れはしますが、json形式のファイルをつくってしまいkiroが認識しないケースもありました。

🪝中身はどういう感じ?

シンプルに .kiro/hooks/*.kiro.hook 形式のものをとってきて、中身はJsonで書かれています。ただし*.json形式ではAgentHooksとして認識しないので*.kiro.hook を拡張子への変更を忘れずに。

{
  "enabled": true,
  "name": "Auth Service Auto Format & Lint",
  "description": "auth-serviceのGoファイル保存時に自動フォーマットとlintを実行",
  "version": "1",
  "when": {
    "type": "fileEdited",
    "patterns": [
      "auth-service/**/*.go"
    ]
  },
  "then": {
    "type": "runCommand",
    "command": "cd auth-service && make format && make lint"
  }
}

公式ドキュメントは下記なのですが、thenやwhenの詳しい説明は自分がさがす限り見当たりませんでした...

そのため、kiroが実際に実装したものベースで紹介します

⏱️when(UI上ではEvent)

type name 追加のproperty name きっかけ
File Saved File path(s)to watch File保存時
File Created File path(s)to watch File作成時
File Deleted File path(s)to watch File削除時
Manual Trigger 手動でのトリガー

▶️then 

type name 追加のproperty name 効果
runCommand command コマンドを実行する
sendMessage message messageをKiroに送る
askAgent message messageをKiroに送る

askAgentとsendMessageはどのような違いがあるかまではわかりませんでしたが自分がUIベースで調査した限りではこのようなプロパティがありました。

✅最後に

CIに失敗してから直すのではなく、「保存した瞬間に怒られる」体験に変えることで、AI生成コードとの付き合い方がかなり楽になります。そこを楽にしてくれるagent hooksぜひ使って活用方法を教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?