failproofai 0.0.5-beta.0 → 0.0.6-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.failproofai/policies/workflow-policies.mjs +2 -1
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +3 -3
- package/.next/standalone/.next/prerender-manifest.json +3 -3
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +2 -2
- package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +10 -10
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +10 -10
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +8 -8
- package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0g72weg._.js +1 -1
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_0z7w.hh._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0r6vvp5._.js → [root-of-the-server]__0.~fd7s._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__092s1ta._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__09icjsf._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0z5dd-f._.js → [root-of-the-server]__0a.nuas._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0g.lg8b._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0h..k-e._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0okos0k._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0w6l33k._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11pa2ra._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__12t-wym._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_10lm7or._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_0xerkr6._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_0q-m0y-._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/pages/404.html +2 -2
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +9 -9
- package/.next/standalone/.next/static/chunks/{0j_ivegn3i5wt.js → 0.z51twd.0l5z.js} +1 -1
- package/.next/standalone/.next/static/chunks/{04fpsjft~cje..js → 0hctoh28rg838.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0.io32u7gjgsb.js → 0hplx-8c-4vpv.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0yf_mmdukq6up.js → 0maq.q1t.ri85.js} +2 -2
- package/.next/standalone/.next/static/chunks/{0x8vagatq36_7.js → 0teq8wdh3po1n.js} +1 -1
- package/.next/standalone/.next/static/chunks/{04mtv9jnqknn3.js → 0uc0um_uz51m_.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0h4qcn40dunn7.js → 0ul6fk-z.6k-0.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0kvldut6ndzyz.js → 0w9lwqy0-v1dk.js} +1 -1
- package/.next/standalone/CHANGELOG.md +9 -1
- package/.next/standalone/README.md +2 -2
- package/.next/standalone/dist/cli.mjs +19 -2
- package/.next/standalone/docs/ar/architecture.mdx +66 -65
- package/.next/standalone/docs/ar/configuration.mdx +42 -42
- package/.next/standalone/docs/ar/custom-policies.mdx +63 -68
- package/.next/standalone/docs/architecture.mdx +2 -2
- package/.next/standalone/docs/configuration.mdx +1 -1
- package/.next/standalone/docs/custom-policies.mdx +2 -6
- package/.next/standalone/docs/de/architecture.mdx +92 -92
- package/.next/standalone/docs/de/configuration.mdx +35 -35
- package/.next/standalone/docs/de/custom-policies.mdx +50 -54
- package/.next/standalone/docs/es/architecture.mdx +73 -73
- package/.next/standalone/docs/es/configuration.mdx +25 -25
- package/.next/standalone/docs/es/custom-policies.mdx +49 -53
- package/.next/standalone/docs/fr/architecture.mdx +55 -55
- package/.next/standalone/docs/fr/configuration.mdx +26 -26
- package/.next/standalone/docs/fr/custom-policies.mdx +42 -46
- package/.next/standalone/docs/he/architecture.mdx +67 -67
- package/.next/standalone/docs/he/configuration.mdx +53 -52
- package/.next/standalone/docs/he/custom-policies.mdx +73 -77
- package/.next/standalone/docs/hi/architecture.mdx +107 -107
- package/.next/standalone/docs/hi/configuration.mdx +39 -39
- package/.next/standalone/docs/hi/custom-policies.mdx +77 -81
- package/.next/standalone/docs/i18n/README.ar.md +66 -66
- package/.next/standalone/docs/i18n/README.de.md +40 -40
- package/.next/standalone/docs/i18n/README.es.md +40 -40
- package/.next/standalone/docs/i18n/README.fr.md +44 -44
- package/.next/standalone/docs/i18n/README.he.md +67 -67
- package/.next/standalone/docs/i18n/README.hi.md +71 -71
- package/.next/standalone/docs/i18n/README.it.md +63 -63
- package/.next/standalone/docs/i18n/README.ja.md +55 -55
- package/.next/standalone/docs/i18n/README.ko.md +59 -59
- package/.next/standalone/docs/i18n/README.pt-br.md +45 -45
- package/.next/standalone/docs/i18n/README.ru.md +71 -71
- package/.next/standalone/docs/i18n/README.tr.md +76 -76
- package/.next/standalone/docs/i18n/README.vi.md +71 -71
- package/.next/standalone/docs/i18n/README.zh.md +53 -53
- package/.next/standalone/docs/it/architecture.mdx +55 -54
- package/.next/standalone/docs/it/configuration.mdx +45 -46
- package/.next/standalone/docs/it/custom-policies.mdx +77 -82
- package/.next/standalone/docs/ja/architecture.mdx +93 -93
- package/.next/standalone/docs/ja/configuration.mdx +48 -48
- package/.next/standalone/docs/ja/custom-policies.mdx +63 -67
- package/.next/standalone/docs/ko/architecture.mdx +66 -66
- package/.next/standalone/docs/ko/configuration.mdx +36 -36
- package/.next/standalone/docs/ko/custom-policies.mdx +73 -77
- package/.next/standalone/docs/pt-br/architecture.mdx +55 -55
- package/.next/standalone/docs/pt-br/configuration.mdx +36 -36
- package/.next/standalone/docs/pt-br/custom-policies.mdx +62 -66
- package/.next/standalone/docs/ru/architecture.mdx +59 -60
- package/.next/standalone/docs/ru/configuration.mdx +52 -53
- package/.next/standalone/docs/ru/custom-policies.mdx +70 -74
- package/.next/standalone/docs/tr/architecture.mdx +124 -124
- package/.next/standalone/docs/tr/configuration.mdx +46 -47
- package/.next/standalone/docs/tr/custom-policies.mdx +75 -78
- package/.next/standalone/docs/vi/architecture.mdx +65 -64
- package/.next/standalone/docs/vi/configuration.mdx +42 -42
- package/.next/standalone/docs/vi/custom-policies.mdx +68 -72
- package/.next/standalone/docs/zh/architecture.mdx +67 -67
- package/.next/standalone/docs/zh/configuration.mdx +35 -35
- package/.next/standalone/docs/zh/custom-policies.mdx +54 -58
- package/.next/standalone/package.json +1 -1
- package/.next/standalone/server.js +1 -1
- package/.next/standalone/src/hooks/builtin-policies.ts +30 -0
- package/README.md +2 -2
- package/dist/cli.mjs +19 -2
- package/package.json +1 -1
- package/src/hooks/builtin-policies.ts +30 -0
- /package/.next/standalone/.next/static/{ICeMHZ-8ZR7HY5GLm7oSJ → 8mygPGI5bzrtWK36ZYO59}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{ICeMHZ-8ZR7HY5GLm7oSJ → 8mygPGI5bzrtWK36ZYO59}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{ICeMHZ-8ZR7HY5GLm7oSJ → 8mygPGI5bzrtWK36ZYO59}/_ssgManifest.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: カスタムポリシー
|
|
3
|
-
description: "JavaScriptで独自のポリシーを記述する —
|
|
3
|
+
description: "JavaScriptで独自のポリシーを記述する — 規約の適用、ドリフトの防止、障害の検出、外部システムとの連携"
|
|
4
4
|
icon: code
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
カスタムポリシーを使用すると、あらゆるエージェントの動作に対してルールを記述できます。プロジェクトの規約を適用する、ドリフトを防止する、破壊的な操作をゲートする、スタックしたエージェントを検出する、あるいはSlackや承認ワークフローと連携するといったことが可能です。組み込みポリシーと同じフックイベントシステムおよび`allow`、`deny`、`instruct`の判定を使用します。
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -37,14 +37,14 @@ failproofai policies --install --custom ./my-policies.js
|
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
40
|
-
##
|
|
40
|
+
## カスタムポリシーの読み込み方法
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### オプション1: 規約ベース(推奨)
|
|
43
43
|
|
|
44
|
-
`*policies.{js,mjs,ts}` ファイルを `.failproofai/policies/`
|
|
44
|
+
`*policies.{js,mjs,ts}` ファイルを `.failproofai/policies/` に配置するだけで、フラグや設定変更なしに自動的に読み込まれます。Gitフックと同じ仕組みです。ファイルを置けば、そのまま動作します。
|
|
45
45
|
|
|
46
46
|
```
|
|
47
|
-
# プロジェクトレベル — git
|
|
47
|
+
# プロジェクトレベル — gitにコミットされ、チームで共有
|
|
48
48
|
.failproofai/policies/security-policies.mjs
|
|
49
49
|
.failproofai/policies/workflow-policies.mjs
|
|
50
50
|
|
|
@@ -52,31 +52,31 @@ failproofai policies --install --custom ./my-policies.js
|
|
|
52
52
|
~/.failproofai/policies/my-policies.mjs
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
- `*policies.{js,mjs,ts}`
|
|
55
|
+
**仕組み:**
|
|
56
|
+
- プロジェクトディレクトリとユーザーディレクトリの両方がスキャンされます(ユニオン — 先着スコープ優先ではありません)
|
|
57
|
+
- ファイルは各ディレクトリ内でアルファベット順に読み込まれます。順序を制御するには `01-`、`02-` などのプレフィックスを付けてください
|
|
58
|
+
- `*policies.{js,mjs,ts}` にマッチするファイルのみ読み込まれ、それ以外は無視されます
|
|
59
59
|
- 各ファイルは独立して読み込まれます(ファイル単位でフェイルオープン)
|
|
60
|
-
- 明示的な `--custom`
|
|
60
|
+
- 明示的な `--custom` および組み込みポリシーと共存できます
|
|
61
61
|
|
|
62
62
|
<Tip>
|
|
63
|
-
|
|
63
|
+
規約ポリシーは、チーム全体でポリシーを共有する最も簡単な方法です。`.failproofai/policies/` をgitにコミットすれば、チームメンバー全員が自動的に取得できます。
|
|
64
64
|
</Tip>
|
|
65
65
|
|
|
66
|
-
###
|
|
66
|
+
### オプション2: 明示的なファイルパス
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
69
|
# カスタムポリシーファイルを指定してインストール
|
|
70
70
|
failproofai policies --install --custom ./my-policies.js
|
|
71
71
|
|
|
72
|
-
#
|
|
72
|
+
# ポリシーファイルパスを置き換える
|
|
73
73
|
failproofai policies --install --custom ./new-policies.js
|
|
74
74
|
|
|
75
|
-
#
|
|
75
|
+
# カスタムポリシーのパスを設定から削除
|
|
76
76
|
failproofai policies --uninstall --custom
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
解決された絶対パスは `policies-config.json` の `customPoliciesPath`
|
|
79
|
+
解決された絶対パスは `policies-config.json` の `customPoliciesPath` に保存されます。ファイルはフックイベントのたびに新たに読み込まれます — イベント間でキャッシュは行われません。
|
|
80
80
|
|
|
81
81
|
### 両方を併用する
|
|
82
82
|
|
|
@@ -98,13 +98,13 @@ import { customPolicies, allow, deny, instruct } from "failproofai";
|
|
|
98
98
|
|
|
99
99
|
### `customPolicies.add(hook)`
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
ポリシーを登録します。同じファイル内に複数のポリシーを定義する場合は、必要な回数だけ呼び出してください。
|
|
102
102
|
|
|
103
103
|
```ts
|
|
104
104
|
customPolicies.add({
|
|
105
105
|
name: string; // 必須 - 一意の識別子
|
|
106
106
|
description?: string; // `failproofai policies` の出力に表示される
|
|
107
|
-
match?: { events?: HookEventType[] }; //
|
|
107
|
+
match?: { events?: HookEventType[] }; // イベントタイプでフィルタリング。省略すると全てにマッチ
|
|
108
108
|
fn: (ctx: PolicyContext) => PolicyResult | Promise<PolicyResult>;
|
|
109
109
|
});
|
|
110
110
|
```
|
|
@@ -113,34 +113,30 @@ customPolicies.add({
|
|
|
113
113
|
|
|
114
114
|
| 関数 | 効果 | 使用場面 |
|
|
115
115
|
|----------|--------|----------|
|
|
116
|
-
| `allow()` | 操作を静かに許可する |
|
|
116
|
+
| `allow()` | 操作を静かに許可する | アクションが安全で、メッセージが不要な場合 |
|
|
117
117
|
| `deny(message)` | 操作をブロックする | エージェントがこのアクションを取るべきでない場合 |
|
|
118
|
-
| `instruct(message)` | ブロックせずにコンテキストを追加する |
|
|
118
|
+
| `instruct(message)` | ブロックせずにコンテキストを追加する | エージェントが正しい方向を維持するための追加コンテキストを提供する場合 |
|
|
119
119
|
|
|
120
|
-
`deny(message)` — メッセージは `"Blocked by failproofai:"`
|
|
120
|
+
`deny(message)` — メッセージは `"Blocked by failproofai:"` というプレフィックスを付けてClaudeに表示されます。単一の `deny` が発生すると、以降の全ての評価がショートサーキットされます。
|
|
121
121
|
|
|
122
|
-
`instruct(message)` —
|
|
122
|
+
`instruct(message)` — メッセージは現在のツールコールのClaudeのコンテキストに追加されます。全ての `instruct` メッセージは蓄積され、まとめて配信されます。
|
|
123
123
|
|
|
124
124
|
<Tip>
|
|
125
|
-
`
|
|
125
|
+
`deny` または `instruct` メッセージに追加のガイダンスを付け加えるには、`policyParams` の `hint` フィールドを使用します — コードの変更は不要です。これはカスタム(`custom/`)、プロジェクト規約(`.failproofai-project/`)、ユーザー規約(`.failproofai-user/`)ポリシーでも機能します。詳細は[設定 → hint](/ja/configuration#hint-cross-cutting)を参照してください。
|
|
126
126
|
</Tip>
|
|
127
127
|
|
|
128
|
-
### 情報提供用のallow
|
|
128
|
+
### 情報提供用のallowメッセージ
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
`allow(message)` はv0.0.2-beta.3から利用できるベータ機能です。APIは将来のリリースで変更される可能性があります。それ以前のバージョンでは引数なしの `allow()` のみサポートされています。
|
|
132
|
-
</Note>
|
|
133
|
-
|
|
134
|
-
`allow(message)` は操作を許可し**つつ**、情報提供のメッセージをClaudeに送信します。メッセージはフックハンドラーのstdoutレスポンスの `additionalContext` として配信されます。これは `instruct` と同じ仕組みですが、意味的に異なります。警告ではなくステータスの更新として扱われます。
|
|
130
|
+
`allow(message)` は操作を許可し**つつ**、情報提供メッセージをClaudeに返します。メッセージはフックハンドラーのstdoutレスポンスの `additionalContext` として配信されます — `instruct` と同じ仕組みですが、意味的には異なります: これは警告ではなく、状態の更新です。
|
|
135
131
|
|
|
136
132
|
| 関数 | 効果 | 使用場面 |
|
|
137
133
|
|----------|--------|----------|
|
|
138
|
-
| `allow(message)` | 許可してClaudeにコンテキストを送信する |
|
|
134
|
+
| `allow(message)` | 許可してClaudeにコンテキストを送信する | チェックが通過したことを確認する、またはチェックがスキップされた理由を説明する |
|
|
139
135
|
|
|
140
136
|
ユースケース:
|
|
141
|
-
-
|
|
137
|
+
- **状態確認:** `allow("All CI checks passed.")` — Claudeに全てが正常であることを伝える
|
|
142
138
|
- **フェイルオープンの説明:** `allow("GitHub CLI not installed, skipping CI check.")` — チェックがスキップされた理由をClaudeに伝え、完全なコンテキストを提供する
|
|
143
|
-
-
|
|
139
|
+
- **複数のメッセージの蓄積:** 複数のポリシーがそれぞれ `allow(message)` を返した場合、全てのメッセージが改行で結合されてまとめて配信される
|
|
144
140
|
|
|
145
141
|
```js
|
|
146
142
|
customPolicies.add({
|
|
@@ -150,7 +146,7 @@ customPolicies.add({
|
|
|
150
146
|
const cwd = ctx.session?.cwd;
|
|
151
147
|
if (!cwd) return allow("No working directory, skipping branch check.");
|
|
152
148
|
|
|
153
|
-
// ...
|
|
149
|
+
// ... ブランチの状態を確認 ...
|
|
154
150
|
if (allPushed) {
|
|
155
151
|
return allow("Branch is up to date with remote.");
|
|
156
152
|
}
|
|
@@ -166,15 +162,15 @@ customPolicies.add({
|
|
|
166
162
|
| `eventType` | `string` | `"PreToolUse"`、`"PostToolUse"`、`"Notification"`、`"Stop"` |
|
|
167
163
|
| `toolName` | `string \| undefined` | 呼び出されるツール(例: `"Bash"`、`"Write"`、`"Read"`) |
|
|
168
164
|
| `toolInput` | `Record<string, unknown> \| undefined` | ツールの入力パラメータ |
|
|
169
|
-
| `payload` | `Record<string, unknown>` | Claude Code
|
|
170
|
-
| `session` | `SessionMetadata \| undefined` |
|
|
165
|
+
| `payload` | `Record<string, unknown>` | Claude Codeからの完全な生イベントペイロード |
|
|
166
|
+
| `session` | `SessionMetadata \| undefined` | セッションコンテキスト(下記参照) |
|
|
171
167
|
|
|
172
168
|
### `SessionMetadata` フィールド
|
|
173
169
|
|
|
174
170
|
| フィールド | 型 | 説明 |
|
|
175
171
|
|-------|------|-------------|
|
|
176
|
-
| `sessionId` | `string` | Claude Code
|
|
177
|
-
| `cwd` | `string` | Claude Code
|
|
172
|
+
| `sessionId` | `string` | Claude Codeセッションの識別子 |
|
|
173
|
+
| `cwd` | `string` | Claude Codeセッションの作業ディレクトリ |
|
|
178
174
|
| `transcriptPath` | `string` | セッションのJSONLトランスクリプトファイルへのパス |
|
|
179
175
|
|
|
180
176
|
### イベントタイプ
|
|
@@ -182,8 +178,8 @@ customPolicies.add({
|
|
|
182
178
|
| イベント | 発火タイミング | `toolInput` の内容 |
|
|
183
179
|
|-------|--------------|----------------------|
|
|
184
180
|
| `PreToolUse` | Claudeがツールを実行する前 | ツールの入力(例: Bashの場合 `{ command: "..." }`) |
|
|
185
|
-
| `PostToolUse` |
|
|
186
|
-
| `Notification` | Claudeが通知を送信するとき | `{ message: "...", notification_type: "idle" \| "permission_prompt" \| ... }` - フックは常に `allow()`
|
|
181
|
+
| `PostToolUse` | ツールが完了した後 | ツールの入力 + `tool_result`(出力) |
|
|
182
|
+
| `Notification` | Claudeが通知を送信するとき | `{ message: "...", notification_type: "idle" \| "permission_prompt" \| ... }` - フックは常に `allow()` を返す必要があり、通知をブロックすることはできません |
|
|
187
183
|
| `Stop` | Claudeセッションが終了するとき | 空 |
|
|
188
184
|
|
|
189
185
|
---
|
|
@@ -193,19 +189,19 @@ customPolicies.add({
|
|
|
193
189
|
ポリシーは以下の順序で評価されます:
|
|
194
190
|
|
|
195
191
|
1. 組み込みポリシー(定義順)
|
|
196
|
-
2. `customPoliciesPath`
|
|
197
|
-
3. プロジェクトの `.failproofai/policies/` からの規約ポリシー(ファイルはアルファベット順、ファイル内は `.add()`
|
|
198
|
-
4. ユーザーの `~/.failproofai/policies/` からの規約ポリシー(ファイルはアルファベット順、ファイル内は `.add()`
|
|
192
|
+
2. `customPoliciesPath` からの明示的なカスタムポリシー(`.add()` の順序)
|
|
193
|
+
3. プロジェクトの `.failproofai/policies/` からの規約ポリシー(ファイルはアルファベット順、ファイル内は `.add()` の順序)
|
|
194
|
+
4. ユーザーの `~/.failproofai/policies/` からの規約ポリシー(ファイルはアルファベット順、ファイル内は `.add()` の順序)
|
|
199
195
|
|
|
200
196
|
<Note>
|
|
201
|
-
最初の `deny`
|
|
197
|
+
最初の `deny` が全ての後続ポリシーをショートサーキットします。全ての `instruct` メッセージは蓄積され、まとめて配信されます。
|
|
202
198
|
</Note>
|
|
203
199
|
|
|
204
200
|
---
|
|
205
201
|
|
|
206
202
|
## 推移的インポート
|
|
207
203
|
|
|
208
|
-
|
|
204
|
+
カスタムポリシーファイルは相対パスを使用してローカルモジュールをインポートできます:
|
|
209
205
|
|
|
210
206
|
```js
|
|
211
207
|
// my-policies.js
|
|
@@ -222,42 +218,42 @@ customPolicies.add({
|
|
|
222
218
|
});
|
|
223
219
|
```
|
|
224
220
|
|
|
225
|
-
|
|
221
|
+
エントリファイルから到達可能な全ての相対インポートが解決されます。これは `from "failproofai"` インポートを実際のdistパスに書き換え、ESMの互換性を確保するために一時的な `.mjs` ファイルを作成することで実装されています。
|
|
226
222
|
|
|
227
223
|
---
|
|
228
224
|
|
|
229
225
|
## イベントタイプのフィルタリング
|
|
230
226
|
|
|
231
|
-
`match.events`
|
|
227
|
+
`match.events` を使用して、ポリシーが発火するタイミングを制限します:
|
|
232
228
|
|
|
233
229
|
```js
|
|
234
230
|
customPolicies.add({
|
|
235
231
|
name: "require-summary-on-stop",
|
|
236
232
|
match: { events: ["Stop"] },
|
|
237
233
|
fn: async (ctx) => {
|
|
238
|
-
//
|
|
234
|
+
// セッション終了時のみ発火
|
|
239
235
|
// ctx.session.transcriptPath にセッションの完全なログが含まれる
|
|
240
236
|
return allow();
|
|
241
237
|
},
|
|
242
238
|
});
|
|
243
239
|
```
|
|
244
240
|
|
|
245
|
-
`match`
|
|
241
|
+
`match` を完全に省略すると、全てのイベントタイプで発火します。
|
|
246
242
|
|
|
247
243
|
---
|
|
248
244
|
|
|
249
|
-
##
|
|
245
|
+
## エラー処理と障害モード
|
|
250
246
|
|
|
251
|
-
|
|
247
|
+
カスタムポリシーは**フェイルオープン**です: エラーが発生しても組み込みポリシーをブロックしたり、フックハンドラーをクラッシュさせたりすることはありません。
|
|
252
248
|
|
|
253
|
-
|
|
|
249
|
+
| 障害 | 動作 |
|
|
254
250
|
|---------|----------|
|
|
255
|
-
| `customPoliciesPath` が未設定 |
|
|
256
|
-
| ファイルが見つからない | `~/.failproofai/hook.log`
|
|
257
|
-
| 構文/インポートエラー(明示的) | `~/.failproofai/hook.log`
|
|
258
|
-
| 構文/インポートエラー(規約) |
|
|
259
|
-
| `fn` が実行時に例外をスロー |
|
|
260
|
-
| `fn` が10秒以上かかる |
|
|
251
|
+
| `customPoliciesPath` が未設定 | 明示的なカスタムポリシーは実行されない。規約ポリシーと組み込みポリシーは正常に継続 |
|
|
252
|
+
| ファイルが見つからない | `~/.failproofai/hook.log` に警告をログ記録。組み込みポリシーは継続 |
|
|
253
|
+
| 構文/インポートエラー(明示的) | `~/.failproofai/hook.log` にエラーをログ記録。明示的なカスタムポリシーはスキップ |
|
|
254
|
+
| 構文/インポートエラー(規約) | エラーをログ記録。該当ファイルはスキップ。他の規約ファイルは引き続き読み込まれる |
|
|
255
|
+
| `fn` が実行時に例外をスロー | エラーをログ記録。該当フックは `allow` として扱われる。他のフックは継続 |
|
|
256
|
+
| `fn` が10秒以上かかる | タイムアウトをログ記録。`allow` として扱われる |
|
|
261
257
|
| 規約ディレクトリが存在しない | 規約ポリシーは実行されない。エラーなし |
|
|
262
258
|
|
|
263
259
|
<Tip>
|
|
@@ -270,13 +266,13 @@ tail -f ~/.failproofai/hook.log
|
|
|
270
266
|
|
|
271
267
|
---
|
|
272
268
|
|
|
273
|
-
## 完全な例:
|
|
269
|
+
## 完全な例: 複数のポリシー
|
|
274
270
|
|
|
275
271
|
```js
|
|
276
272
|
// my-policies.js
|
|
277
273
|
import { customPolicies, allow, deny, instruct } from "failproofai";
|
|
278
274
|
|
|
279
|
-
// エージェントがsecrets
|
|
275
|
+
// エージェントがsecretsディレクトリに書き込むことを防止
|
|
280
276
|
customPolicies.add({
|
|
281
277
|
name: "block-secrets-dir",
|
|
282
278
|
description: "Prevent agent from writing to secrets/ directory",
|
|
@@ -289,7 +285,7 @@ customPolicies.add({
|
|
|
289
285
|
},
|
|
290
286
|
});
|
|
291
287
|
|
|
292
|
-
//
|
|
288
|
+
// エージェントを正しい方向に維持: コミット前にテストを確認
|
|
293
289
|
customPolicies.add({
|
|
294
290
|
name: "remind-test-before-commit",
|
|
295
291
|
description: "Keep the agent on track: verify tests pass before committing",
|
|
@@ -304,7 +300,7 @@ customPolicies.add({
|
|
|
304
300
|
},
|
|
305
301
|
});
|
|
306
302
|
|
|
307
|
-
//
|
|
303
|
+
// フリーズ期間中の予定外の依存関係変更を防止
|
|
308
304
|
customPolicies.add({
|
|
309
305
|
name: "dependency-freeze",
|
|
310
306
|
description: "Prevent unplanned dependency changes during freeze period",
|
|
@@ -327,22 +323,22 @@ export { customPolicies };
|
|
|
327
323
|
|
|
328
324
|
## サンプル
|
|
329
325
|
|
|
330
|
-
`examples/`
|
|
326
|
+
`examples/` ディレクトリには、すぐに実行できるポリシーファイルが含まれています:
|
|
331
327
|
|
|
332
328
|
| ファイル | 内容 |
|
|
333
329
|
|------|----------|
|
|
334
|
-
| `examples/policies-basic.js` |
|
|
330
|
+
| `examples/policies-basic.js` | 一般的なエージェントの障害モードをカバーする5つのスターターポリシー |
|
|
335
331
|
| `examples/policies-advanced/index.js` | 高度なパターン: 推移的インポート、非同期呼び出し、出力のスクラビング、セッション終了フック |
|
|
336
|
-
| `examples/convention-policies/security-policies.mjs` | 規約ベースのセキュリティポリシー(.env
|
|
332
|
+
| `examples/convention-policies/security-policies.mjs` | 規約ベースのセキュリティポリシー(.envファイルへの書き込みのブロック、gitの履歴書き換えの防止) |
|
|
337
333
|
| `examples/convention-policies/workflow-policies.mjs` | 規約ベースのワークフローポリシー(テストのリマインダー、ファイル書き込みの監査) |
|
|
338
334
|
|
|
339
|
-
###
|
|
335
|
+
### 明示的なファイルサンプルの使用
|
|
340
336
|
|
|
341
337
|
```bash
|
|
342
338
|
failproofai policies --install --custom ./examples/policies-basic.js
|
|
343
339
|
```
|
|
344
340
|
|
|
345
|
-
###
|
|
341
|
+
### 規約ベースのサンプルの使用
|
|
346
342
|
|
|
347
343
|
```bash
|
|
348
344
|
# プロジェクトレベルにコピー
|
|
@@ -354,4 +350,4 @@ mkdir -p ~/.failproofai/policies
|
|
|
354
350
|
cp examples/convention-policies/*.mjs ~/.failproofai/policies/
|
|
355
351
|
```
|
|
356
352
|
|
|
357
|
-
|
|
353
|
+
インストールコマンドは不要です — 次のフックイベント時に自動的にファイルが読み込まれます。
|