failproofai 0.0.6-beta.0 → 0.0.6-beta.2
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/review-policies.mjs +113 -0
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +5 -5
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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/build-manifest.json +2 -2
- 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]__0a.nuas._.js → [root-of-the-server]__05akje6._.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]__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]__0.~fd7s._.js → [root-of-the-server]__0i5kvry._.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 +6 -6
- 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 +5 -5
- 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/{0teq8wdh3po1n.js → 00j0rr7rh8ef8.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0maq.q1t.ri85.js → 05j1px0r8yzh6.js} +2 -2
- package/.next/standalone/.next/static/chunks/0badv41uxa56..js +4 -0
- package/.next/standalone/.next/static/chunks/{0hplx-8c-4vpv.js → 0ijk_kek9_wyx.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0uc0um_uz51m_.js → 0npb~873.wvg3.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0hctoh28rg838.js → 0xpl.oscrakvx.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0.z51twd.0l5z.js → 1052sguyd-.ka.js} +1 -1
- package/.next/standalone/.next/static/chunks/{09e7drilkf1sn.js → 12simlrcfk3g2.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0ul6fk-z.6k-0.js → 14cl9poem30dq.js} +1 -1
- package/.next/standalone/.next/static/chunks/{turbopack-0r26pc8h0y_-e.js → turbopack-0o7k.hakttp4k.js} +1 -1
- package/.next/standalone/CHANGELOG.md +19 -0
- package/.next/standalone/README.md +2 -2
- package/.next/standalone/bun.lock +43 -85
- package/.next/standalone/dist/cli.mjs +91 -4
- package/.next/standalone/docs/ar/built-in-policies.mdx +124 -87
- package/.next/standalone/docs/ar/custom-policies.mdx +72 -72
- package/.next/standalone/docs/ar/examples.mdx +86 -33
- package/.next/standalone/docs/ar/getting-started.mdx +82 -29
- package/.next/standalone/docs/built-in-policies.mdx +38 -1
- package/.next/standalone/docs/custom-policies.mdx +1 -1
- package/.next/standalone/docs/de/built-in-policies.mdx +93 -56
- package/.next/standalone/docs/de/custom-policies.mdx +56 -56
- package/.next/standalone/docs/de/examples.mdx +72 -18
- package/.next/standalone/docs/de/getting-started.mdx +72 -20
- package/.next/standalone/docs/es/built-in-policies.mdx +115 -78
- package/.next/standalone/docs/es/custom-policies.mdx +55 -55
- package/.next/standalone/docs/es/examples.mdx +73 -19
- package/.next/standalone/docs/es/getting-started.mdx +72 -20
- package/.next/standalone/docs/examples.mdx +54 -0
- package/.next/standalone/docs/fr/built-in-policies.mdx +83 -46
- package/.next/standalone/docs/fr/custom-policies.mdx +51 -51
- package/.next/standalone/docs/fr/examples.mdx +78 -24
- package/.next/standalone/docs/fr/getting-started.mdx +65 -13
- package/.next/standalone/docs/getting-started.mdx +52 -0
- package/.next/standalone/docs/he/built-in-policies.mdx +156 -117
- package/.next/standalone/docs/he/custom-policies.mdx +75 -75
- package/.next/standalone/docs/he/examples.mdx +87 -33
- package/.next/standalone/docs/he/getting-started.mdx +84 -33
- package/.next/standalone/docs/hi/built-in-policies.mdx +101 -60
- package/.next/standalone/docs/hi/custom-policies.mdx +71 -70
- package/.next/standalone/docs/hi/examples.mdx +90 -36
- package/.next/standalone/docs/hi/getting-started.mdx +80 -27
- package/.next/standalone/docs/i18n/README.ar.md +69 -69
- package/.next/standalone/docs/i18n/README.de.md +46 -46
- package/.next/standalone/docs/i18n/README.es.md +42 -42
- package/.next/standalone/docs/i18n/README.fr.md +39 -39
- package/.next/standalone/docs/i18n/README.he.md +83 -83
- package/.next/standalone/docs/i18n/README.hi.md +69 -69
- package/.next/standalone/docs/i18n/README.it.md +72 -72
- package/.next/standalone/docs/i18n/README.ja.md +71 -71
- package/.next/standalone/docs/i18n/README.ko.md +52 -52
- package/.next/standalone/docs/i18n/README.pt-br.md +44 -44
- package/.next/standalone/docs/i18n/README.ru.md +66 -66
- package/.next/standalone/docs/i18n/README.tr.md +82 -83
- package/.next/standalone/docs/i18n/README.vi.md +70 -71
- package/.next/standalone/docs/i18n/README.zh.md +51 -51
- package/.next/standalone/docs/it/built-in-policies.mdx +118 -81
- package/.next/standalone/docs/it/custom-policies.mdx +69 -69
- package/.next/standalone/docs/it/examples.mdx +93 -39
- package/.next/standalone/docs/it/getting-started.mdx +73 -21
- package/.next/standalone/docs/ja/built-in-policies.mdx +98 -61
- package/.next/standalone/docs/ja/custom-policies.mdx +71 -71
- package/.next/standalone/docs/ja/examples.mdx +76 -22
- package/.next/standalone/docs/ja/getting-started.mdx +65 -13
- package/.next/standalone/docs/ko/built-in-policies.mdx +137 -100
- package/.next/standalone/docs/ko/custom-policies.mdx +67 -67
- package/.next/standalone/docs/ko/examples.mdx +87 -33
- package/.next/standalone/docs/ko/getting-started.mdx +61 -9
- package/.next/standalone/docs/pt-br/built-in-policies.mdx +94 -57
- package/.next/standalone/docs/pt-br/custom-policies.mdx +56 -56
- package/.next/standalone/docs/pt-br/examples.mdx +78 -24
- package/.next/standalone/docs/pt-br/getting-started.mdx +64 -12
- package/.next/standalone/docs/ru/built-in-policies.mdx +142 -105
- package/.next/standalone/docs/ru/custom-policies.mdx +82 -81
- package/.next/standalone/docs/ru/examples.mdx +77 -22
- package/.next/standalone/docs/ru/getting-started.mdx +74 -22
- package/.next/standalone/docs/tr/built-in-policies.mdx +104 -67
- package/.next/standalone/docs/tr/custom-policies.mdx +59 -60
- package/.next/standalone/docs/tr/examples.mdx +97 -42
- package/.next/standalone/docs/tr/getting-started.mdx +75 -23
- package/.next/standalone/docs/vi/built-in-policies.mdx +110 -72
- package/.next/standalone/docs/vi/custom-policies.mdx +68 -68
- package/.next/standalone/docs/vi/examples.mdx +93 -38
- package/.next/standalone/docs/vi/getting-started.mdx +74 -22
- package/.next/standalone/docs/zh/built-in-policies.mdx +132 -95
- package/.next/standalone/docs/zh/custom-policies.mdx +49 -49
- package/.next/standalone/docs/zh/examples.mdx +90 -36
- package/.next/standalone/docs/zh/getting-started.mdx +73 -21
- package/.next/standalone/node_modules/@next/env/package.json +1 -1
- package/.next/standalone/node_modules/next/dist/build/swc/index.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/pages-turbo.runtime.prod.js +7 -7
- package/.next/standalone/node_modules/next/dist/lib/patch-incorrect-lockfile.js +3 -3
- package/.next/standalone/node_modules/next/dist/server/config-schema.js +10 -2
- package/.next/standalone/node_modules/next/dist/server/config.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-turbopack.js +2 -2
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/app-info-log.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/start-server.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/render.js +27 -20
- package/.next/standalone/node_modules/next/dist/shared/lib/errors/canary-only-config-error.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/anonymous-meta.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/swc-load-failure.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/version.js +2 -2
- package/.next/standalone/node_modules/next/package.json +15 -15
- package/.next/standalone/package.json +2 -2
- package/.next/standalone/server.js +1 -1
- package/.next/standalone/src/hooks/builtin-policies.ts +106 -1
- package/README.md +2 -2
- package/dist/cli.mjs +91 -4
- package/package.json +2 -2
- package/src/hooks/builtin-policies.ts +106 -1
- package/.next/standalone/.next/static/chunks/0w9lwqy0-v1dk.js +0 -4
- /package/.next/standalone/.next/static/{8mygPGI5bzrtWK36ZYO59 → A9pNTZdoYJTVyPAYwQMx5}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{8mygPGI5bzrtWK36ZYO59 → A9pNTZdoYJTVyPAYwQMx5}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{8mygPGI5bzrtWK36ZYO59 → A9pNTZdoYJTVyPAYwQMx5}/_ssgManifest.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Chính sách tùy chỉnh
|
|
3
|
-
description: "Viết các quy tắc của riêng bạn bằng JavaScript - thực thi
|
|
3
|
+
description: "Viết các quy tắc của riêng bạn bằng JavaScript - thực thi quy ước, ngăn chặn sự trôi dạt, phát hiện lỗi, tích hợp với các hệ thống bên ngoài"
|
|
4
4
|
icon: code
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Chính sách tùy chỉnh cho phép bạn viết các quy tắc cho bất kỳ hành vi agent
|
|
7
|
+
Chính sách tùy chỉnh cho phép bạn viết các quy tắc cho bất kỳ hành vi nào của agent: thực thi quy ước dự án, ngăn chặn sự trôi dạt, kiểm soát các hoạt động tàn phá, phát hiện agent bị mắc kẹt, hoặc tích hợp với Slack, quy trình phê duyệt, và nhiều hơn nữa. Chúng sử dụng cùng một hệ thống hook event và các quyết định `allow`, `deny`, `instruct` như các chính sách tích hợp.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -39,12 +39,12 @@ failproofai policies --install --custom ./my-policies.js
|
|
|
39
39
|
|
|
40
40
|
## Hai cách để tải chính sách tùy chỉnh
|
|
41
41
|
|
|
42
|
-
### Tùy chọn 1: Dựa trên quy ước (được
|
|
42
|
+
### Tùy chọn 1: Dựa trên quy ước (được khuyến nghị)
|
|
43
43
|
|
|
44
|
-
Thả các tệp `*policies.{js,mjs,ts}` vào `.failproofai/policies/` và chúng sẽ được tải tự động — không cần cờ hoặc thay đổi cấu hình. Điều này hoạt động giống như git hooks: thả một tệp, nó
|
|
44
|
+
Thả các tệp `*policies.{js,mjs,ts}` vào `.failproofai/policies/` và chúng sẽ được tải tự động — không cần cờ hoặc thay đổi cấu hình. Điều này hoạt động giống như git hooks: thả một tệp, nó sẽ hoạt động.
|
|
45
45
|
|
|
46
46
|
```
|
|
47
|
-
# Cấp độ dự án — được
|
|
47
|
+
# Cấp độ dự án — được commit vào git, chia sẻ với nhóm
|
|
48
48
|
.failproofai/policies/security-policies.mjs
|
|
49
49
|
.failproofai/policies/workflow-policies.mjs
|
|
50
50
|
|
|
@@ -52,21 +52,21 @@ Thả các tệp `*policies.{js,mjs,ts}` vào `.failproofai/policies/` và chún
|
|
|
52
52
|
~/.failproofai/policies/my-policies.mjs
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
**Cách hoạt động:**
|
|
56
|
-
- Cả
|
|
57
|
-
- Các tệp được tải theo thứ tự bảng chữ cái trong mỗi thư mục.
|
|
55
|
+
**Cách nó hoạt động:**
|
|
56
|
+
- Cả thư mục dự án và thư mục người dùng đều được quét (kết hợp — không phải first-scope-wins)
|
|
57
|
+
- Các tệp được tải theo thứ tự bảng chữ cái trong mỗi thư mục. Sử dụng tiền tố `01-`, `02-` để kiểm soát thứ tự
|
|
58
58
|
- Chỉ các tệp khớp với `*policies.{js,mjs,ts}` được tải; các tệp khác bị bỏ qua
|
|
59
|
-
- Mỗi tệp được tải độc lập (fail-open
|
|
60
|
-
- Hoạt động cùng với các chính sách `--custom`
|
|
59
|
+
- Mỗi tệp được tải độc lập (fail-open cho mỗi tệp)
|
|
60
|
+
- Hoạt động cùng với các chính sách `--custom` rõ ràng và chính sách tích hợp
|
|
61
61
|
|
|
62
62
|
<Tip>
|
|
63
|
-
Chính sách quy ước là cách dễ nhất để
|
|
63
|
+
Chính sách quy ước là cách dễ nhất để xây dựng một tiêu chuẩn chất lượng cho tổ chức của bạn. Commit `.failproofai/policies/` vào git và mỗi thành viên nhóm sẽ tự động nhận được các quy tắc tương tự — không cần thiết lập trên mỗi nhà phát triển. Khi nhóm của bạn khám phá ra các chế độ lỗi mới, hãy thêm một chính sách và push. Theo thời gian, những quy tắc này trở thành một tiêu chuẩn chất lượng sống động liên tục cải thiện với mỗi đóng góp.
|
|
64
64
|
</Tip>
|
|
65
65
|
|
|
66
|
-
### Tùy chọn 2: Đường dẫn tệp
|
|
66
|
+
### Tùy chọn 2: Đường dẫn tệp rõ ràng
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
|
-
# Cài đặt với tệp chính sách tùy chỉnh
|
|
69
|
+
# Cài đặt với một tệp chính sách tùy chỉnh
|
|
70
70
|
failproofai policies --install --custom ./my-policies.js
|
|
71
71
|
|
|
72
72
|
# Thay thế đường dẫn tệp chính sách
|
|
@@ -76,13 +76,13 @@ failproofai policies --install --custom ./new-policies.js
|
|
|
76
76
|
failproofai policies --uninstall --custom
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Đường dẫn tuyệt đối đã
|
|
79
|
+
Đường dẫn tuyệt đối đã giải quyết được lưu trữ trong `policies-config.json` dưới dạng `customPoliciesPath`. Tệp được tải mới trên mỗi hook event - không có bộ nhớ đệm giữa các sự kiện.
|
|
80
80
|
|
|
81
81
|
### Sử dụng cả hai cùng nhau
|
|
82
82
|
|
|
83
|
-
Chính sách quy ước và tệp `--custom`
|
|
83
|
+
Chính sách quy ước và tệp `--custom` rõ ràng có thể coexist. Thứ tự tải:
|
|
84
84
|
|
|
85
|
-
1. Tệp `customPoliciesPath`
|
|
85
|
+
1. Tệp `customPoliciesPath` rõ ràng (nếu được cấu hình)
|
|
86
86
|
2. Tệp quy ước dự án (`{cwd}/.failproofai/policies/`, theo thứ tự bảng chữ cái)
|
|
87
87
|
3. Tệp quy ước người dùng (`~/.failproofai/policies/`, theo thứ tự bảng chữ cái)
|
|
88
88
|
|
|
@@ -90,7 +90,7 @@ Chính sách quy ước và tệp `--custom` tường minh có thể cùng tồn
|
|
|
90
90
|
|
|
91
91
|
## API
|
|
92
92
|
|
|
93
|
-
###
|
|
93
|
+
### Import
|
|
94
94
|
|
|
95
95
|
```js
|
|
96
96
|
import { customPolicies, allow, deny, instruct } from "failproofai";
|
|
@@ -98,7 +98,7 @@ import { customPolicies, allow, deny, instruct } from "failproofai";
|
|
|
98
98
|
|
|
99
99
|
### `customPolicies.add(hook)`
|
|
100
100
|
|
|
101
|
-
Đăng ký một chính sách. Gọi
|
|
101
|
+
Đăng ký một chính sách. Gọi hàm này bao nhiêu lần tùy ý cho nhiều chính sách trong cùng một tệp.
|
|
102
102
|
|
|
103
103
|
```ts
|
|
104
104
|
customPolicies.add({
|
|
@@ -109,34 +109,34 @@ customPolicies.add({
|
|
|
109
109
|
});
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
###
|
|
112
|
+
### Các trợ giúp quyết định
|
|
113
113
|
|
|
114
|
-
| Hàm |
|
|
114
|
+
| Hàm | Tác dụng | Sử dụng khi |
|
|
115
115
|
|----------|--------|----------|
|
|
116
|
-
| `allow()` | Cho phép hoạt động im lặng | Hành động an toàn, không cần tin nhắn |
|
|
116
|
+
| `allow()` | Cho phép hoạt động im lặng | Hành động là an toàn, không cần tin nhắn |
|
|
117
117
|
| `deny(message)` | Chặn hoạt động | Agent không nên thực hiện hành động này |
|
|
118
|
-
| `instruct(message)` | Thêm ngữ cảnh mà không chặn | Cung cấp ngữ cảnh bổ sung để
|
|
118
|
+
| `instruct(message)` | Thêm ngữ cảnh mà không chặn | Cung cấp cho agent ngữ cảnh bổ sung để giữ đúng hướng |
|
|
119
119
|
|
|
120
|
-
`deny(message)` - tin nhắn xuất hiện
|
|
120
|
+
`deny(message)` - tin nhắn xuất hiện cho Claude với tiền tố `"Blocked by failproofai:"`. Một `deny` duy nhất sẽ ngắn mạch tất cả đánh giá tiếp theo.
|
|
121
121
|
|
|
122
|
-
`instruct(message)` - tin nhắn được thêm vào ngữ cảnh của Claude cho
|
|
122
|
+
`instruct(message)` - tin nhắn được thêm vào ngữ cảnh của Claude cho lệnh gọi công cụ hiện tại. Tất cả các tin nhắn `instruct` được tích lũy và cung cấp cùng nhau.
|
|
123
123
|
|
|
124
124
|
<Tip>
|
|
125
|
-
Bạn có thể thêm hướng dẫn bổ sung vào bất kỳ tin nhắn `deny` hoặc `instruct` nào bằng cách thêm trường `hint` trong `policyParams` — không cần thay đổi mã. Điều này hoạt động
|
|
125
|
+
Bạn có thể thêm hướng dẫn bổ sung vào bất kỳ tin nhắn `deny` hoặc `instruct` nào bằng cách thêm trường `hint` trong `policyParams` — không cần thay đổi mã. Điều này hoạt động với chính sách tùy chỉnh (`custom/`), quy ước dự án (`.failproofai-project/`), và quy ước người dùng (`.failproofai-user/`) cũng vậy. Xem [Configuration → hint](/vi/configuration#hint-cross-cutting) để biết thêm chi tiết.
|
|
126
126
|
</Tip>
|
|
127
127
|
|
|
128
|
-
### Tin nhắn
|
|
128
|
+
### Tin nhắn cho phép thông tin
|
|
129
129
|
|
|
130
|
-
`allow(message)` cho phép hoạt động **và** gửi
|
|
130
|
+
`allow(message)` cho phép hoạt động **và** gửi một tin nhắn thông tin trở lại Claude. Tin nhắn được cung cấp dưới dạng `additionalContext` trong phản hồi stdout của trình xử lý hook — cơ chế tương tự được sử dụng bởi `instruct`, nhưng về mặt ngữ nghĩa khác: nó là một cập nhật trạng thái, không phải một cảnh báo.
|
|
131
131
|
|
|
132
|
-
| Hàm |
|
|
132
|
+
| Hàm | Tác dụng | Sử dụng khi |
|
|
133
133
|
|----------|--------|----------|
|
|
134
|
-
| `allow(message)` | Cho phép và gửi ngữ cảnh cho Claude | Xác nhận kiểm tra đã vượt qua, hoặc giải thích tại sao kiểm tra bị bỏ qua |
|
|
134
|
+
| `allow(message)` | Cho phép và gửi ngữ cảnh cho Claude | Xác nhận một kiểm tra đã vượt qua, hoặc giải thích tại sao một kiểm tra bị bỏ qua |
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
- **Xác nhận trạng thái:** `allow("All CI checks passed.")` — cho Claude biết
|
|
138
|
-
- **Giải thích fail-open:** `allow("GitHub CLI not installed, skipping CI check.")` — cho Claude biết tại sao kiểm tra bị bỏ qua để nó có bối cảnh đầy đủ
|
|
139
|
-
- **Nhiều tin nhắn tích lũy:** nếu nhiều chính sách trả về `allow(message)`, tất cả các tin nhắn được
|
|
136
|
+
Các trường hợp sử dụng:
|
|
137
|
+
- **Xác nhận trạng thái:** `allow("All CI checks passed.")` — cho Claude biết mọi thứ đều ổn
|
|
138
|
+
- **Giải thích fail-open:** `allow("GitHub CLI not installed, skipping CI check.")` — cho Claude biết tại sao một kiểm tra bị bỏ qua để nó có bối cảnh đầy đủ
|
|
139
|
+
- **Nhiều tin nhắn tích lũy:** nếu nhiều chính sách mỗi cái trả về `allow(message)`, tất cả các tin nhắn được kết hợp với ngắt dòng và cung cấp cùng nhau
|
|
140
140
|
|
|
141
141
|
```js
|
|
142
142
|
customPolicies.add({
|
|
@@ -157,30 +157,30 @@ customPolicies.add({
|
|
|
157
157
|
|
|
158
158
|
### Các trường `PolicyContext`
|
|
159
159
|
|
|
160
|
-
| Trường |
|
|
160
|
+
| Trường | Loại | Mô tả |
|
|
161
161
|
|-------|------|-------------|
|
|
162
162
|
| `eventType` | `string` | `"PreToolUse"`, `"PostToolUse"`, `"Notification"`, `"Stop"` |
|
|
163
|
-
| `toolName` | `string \| undefined` | Công cụ đang được gọi (ví
|
|
163
|
+
| `toolName` | `string \| undefined` | Công cụ đang được gọi (ví dụ `"Bash"`, `"Write"`, `"Read"`) |
|
|
164
164
|
| `toolInput` | `Record<string, unknown> \| undefined` | Các tham số đầu vào của công cụ |
|
|
165
165
|
| `payload` | `Record<string, unknown>` | Tải trọng sự kiện thô đầy đủ từ Claude Code |
|
|
166
|
-
| `session` | `SessionMetadata \| undefined` | Ngữ cảnh phiên (xem bên dưới) |
|
|
166
|
+
| `session` | `SessionMetadata \| undefined` | Ngữ cảnh phiên làm việc (xem bên dưới) |
|
|
167
167
|
|
|
168
168
|
### Các trường `SessionMetadata`
|
|
169
169
|
|
|
170
|
-
| Trường |
|
|
170
|
+
| Trường | Loại | Mô tả |
|
|
171
171
|
|-------|------|-------------|
|
|
172
|
-
| `sessionId` | `string` | Định danh phiên Claude Code |
|
|
172
|
+
| `sessionId` | `string` | Định danh phiên làm việc Claude Code |
|
|
173
173
|
| `cwd` | `string` | Thư mục làm việc của phiên Claude Code |
|
|
174
|
-
| `transcriptPath` | `string` | Đường dẫn đến tệp
|
|
174
|
+
| `transcriptPath` | `string` | Đường dẫn đến tệp bảng điểm JSONL của phiên |
|
|
175
175
|
|
|
176
176
|
### Các loại sự kiện
|
|
177
177
|
|
|
178
|
-
| Sự kiện | Khi nó
|
|
178
|
+
| Sự kiện | Khi nó kích hoạt | Nội dung `toolInput` |
|
|
179
179
|
|-------|--------------|----------------------|
|
|
180
|
-
| `PreToolUse` | Trước khi Claude chạy
|
|
181
|
-
| `PostToolUse` | Sau khi
|
|
182
|
-
| `Notification` | Khi Claude gửi thông báo | `{ message: "...", notification_type: "idle" \| "permission_prompt" \| ... }` -
|
|
183
|
-
| `Stop` | Khi phiên Claude kết thúc |
|
|
180
|
+
| `PreToolUse` | Trước khi Claude chạy công cụ | Đầu vào của công cụ (ví dụ `{ command: "..." }` cho Bash) |
|
|
181
|
+
| `PostToolUse` | Sau khi công cụ hoàn thành | Đầu vào của công cụ + `tool_result` (kết quả) |
|
|
182
|
+
| `Notification` | Khi Claude gửi thông báo | `{ message: "...", notification_type: "idle" \| "permission_prompt" \| ... }` - hooks phải luôn trả về `allow()`, chúng không thể chặn thông báo |
|
|
183
|
+
| `Stop` | Khi phiên Claude kết thúc | Rỗng |
|
|
184
184
|
|
|
185
185
|
---
|
|
186
186
|
|
|
@@ -188,20 +188,20 @@ customPolicies.add({
|
|
|
188
188
|
|
|
189
189
|
Chính sách được đánh giá theo thứ tự này:
|
|
190
190
|
|
|
191
|
-
1. Chính sách tích hợp
|
|
192
|
-
2. Chính sách tùy chỉnh
|
|
191
|
+
1. Chính sách tích hợp (theo thứ tự định nghĩa)
|
|
192
|
+
2. Chính sách tùy chỉnh rõ ràng từ `customPoliciesPath` (theo thứ tự `.add()`)
|
|
193
193
|
3. Chính sách quy ước từ dự án `.failproofai/policies/` (tệp theo thứ tự bảng chữ cái, thứ tự `.add()` bên trong)
|
|
194
194
|
4. Chính sách quy ước từ người dùng `~/.failproofai/policies/` (tệp theo thứ tự bảng chữ cái, thứ tự `.add()` bên trong)
|
|
195
195
|
|
|
196
196
|
<Note>
|
|
197
|
-
`deny` đầu tiên
|
|
197
|
+
`deny` đầu tiên sẽ ngắn mạch tất cả các chính sách tiếp theo. Tất cả các tin nhắn `instruct` được tích lũy và cung cấp cùng nhau.
|
|
198
198
|
</Note>
|
|
199
199
|
|
|
200
200
|
---
|
|
201
201
|
|
|
202
|
-
##
|
|
202
|
+
## Imports truyền bá
|
|
203
203
|
|
|
204
|
-
Các tệp chính sách tùy chỉnh có thể
|
|
204
|
+
Các tệp chính sách tùy chỉnh có thể import các mô-đun cục bộ sử dụng đường dẫn tương đối:
|
|
205
205
|
|
|
206
206
|
```js
|
|
207
207
|
// my-policies.js
|
|
@@ -218,13 +218,13 @@ customPolicies.add({
|
|
|
218
218
|
});
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
Tất cả các nhập
|
|
221
|
+
Tất cả các nhập tương đối có thể đạt được từ tệp mục nhập đều được giải quyết. Điều này được thực hiện bằng cách viết lại các nhập `from "failproofai"` thành đường dẫn dist thực tế và tạo các tệp `.mjs` tạm thời để đảm bảo khả năng tương thích ESM.
|
|
222
222
|
|
|
223
223
|
---
|
|
224
224
|
|
|
225
|
-
## Lọc loại sự kiện
|
|
225
|
+
## Lọc theo loại sự kiện
|
|
226
226
|
|
|
227
|
-
Sử dụng `match.events` để hạn
|
|
227
|
+
Sử dụng `match.events` để giới hạn khi nào một chính sách kích hoạt:
|
|
228
228
|
|
|
229
229
|
```js
|
|
230
230
|
customPolicies.add({
|
|
@@ -238,26 +238,26 @@ customPolicies.add({
|
|
|
238
238
|
});
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
-
Bỏ qua `match` hoàn toàn để kích hoạt
|
|
241
|
+
Bỏ qua `match` hoàn toàn để kích hoạt trên mọi loại sự kiện.
|
|
242
242
|
|
|
243
243
|
---
|
|
244
244
|
|
|
245
|
-
## Xử lý lỗi và chế độ
|
|
245
|
+
## Xử lý lỗi và chế độ hỏng
|
|
246
246
|
|
|
247
|
-
Chính sách tùy chỉnh
|
|
247
|
+
Chính sách tùy chỉnh **fail-open**: lỗi không bao giờ chặn chính sách tích hợp hoặc làm hỏng trình xử lý hook.
|
|
248
248
|
|
|
249
249
|
| Lỗi | Hành vi |
|
|
250
250
|
|---------|----------|
|
|
251
|
-
| `customPoliciesPath` không được đặt | Không có chính sách tùy chỉnh
|
|
252
|
-
| Tệp không tìm thấy | Cảnh báo được ghi vào `~/.failproofai/hook.log`; tích hợp
|
|
253
|
-
| Lỗi
|
|
254
|
-
| Lỗi
|
|
255
|
-
| `fn` ném
|
|
256
|
-
| `fn` mất
|
|
251
|
+
| `customPoliciesPath` không được đặt | Không có chính sách tùy chỉnh rõ ràng chạy; chính sách quy ước và tích hợp tiếp tục bình thường |
|
|
252
|
+
| Tệp không tìm thấy | Cảnh báo được ghi vào `~/.failproofai/hook.log`; tích hợp tiếp tục |
|
|
253
|
+
| Lỗi Syntax/import (rõ ràng) | Lỗi được ghi vào `~/.failproofai/hook.log`; chính sách tùy chỉnh rõ ràng bị bỏ qua |
|
|
254
|
+
| Lỗi Syntax/import (quy ước) | Lỗi được ghi; tệp đó bị bỏ qua, các tệp quy ước khác vẫn tải |
|
|
255
|
+
| `fn` ném khi chạy | Lỗi được ghi; hook đó được coi là `allow`; các hook khác tiếp tục |
|
|
256
|
+
| `fn` mất quá lâu hơn 10 giây | Timeout được ghi; được coi là `allow` |
|
|
257
257
|
| Thư mục quy ước bị thiếu | Không có chính sách quy ước chạy; không có lỗi |
|
|
258
258
|
|
|
259
259
|
<Tip>
|
|
260
|
-
Để gỡ lỗi
|
|
260
|
+
Để gỡ lỗi lỗi chính sách tùy chỉnh, hãy theo dõi tệp nhật ký:
|
|
261
261
|
|
|
262
262
|
```bash
|
|
263
263
|
tail -f ~/.failproofai/hook.log
|
|
@@ -328,17 +328,17 @@ Thư mục `examples/` chứa các tệp chính sách sẵn sàng chạy:
|
|
|
328
328
|
| Tệp | Nội dung |
|
|
329
329
|
|------|----------|
|
|
330
330
|
| `examples/policies-basic.js` | Năm chính sách khởi động bao gồm các chế độ lỗi agent phổ biến |
|
|
331
|
-
| `examples/policies-advanced/index.js` | Các mẫu nâng cao: nhập
|
|
332
|
-
| `examples/convention-policies/security-policies.mjs` | Chính sách bảo mật dựa trên quy ước (chặn ghi .env, ngăn
|
|
333
|
-
| `examples/convention-policies/workflow-policies.mjs` | Chính sách quy trình
|
|
331
|
+
| `examples/policies-advanced/index.js` | Các mẫu nâng cao: nhập truyền bá, lệnh gọi async, scrubbing đầu ra, và hook kết thúc phiên |
|
|
332
|
+
| `examples/convention-policies/security-policies.mjs` | Chính sách bảo mật dựa trên quy ước (chặn ghi .env, ngăn viết lại lịch sử git) |
|
|
333
|
+
| `examples/convention-policies/workflow-policies.mjs` | Chính sách quy trình công việc dựa trên quy ước (nhắc nhở kiểm tra, tệp ghi kiểm toán) |
|
|
334
334
|
|
|
335
|
-
### Sử dụng ví dụ tệp
|
|
335
|
+
### Sử dụng các ví dụ tệp rõ ràng
|
|
336
336
|
|
|
337
337
|
```bash
|
|
338
338
|
failproofai policies --install --custom ./examples/policies-basic.js
|
|
339
339
|
```
|
|
340
340
|
|
|
341
|
-
### Sử dụng ví dụ dựa trên quy ước
|
|
341
|
+
### Sử dụng các ví dụ dựa trên quy ước
|
|
342
342
|
|
|
343
343
|
```bash
|
|
344
344
|
# Copy to project level
|
|
@@ -350,4 +350,4 @@ mkdir -p ~/.failproofai/policies
|
|
|
350
350
|
cp examples/convention-policies/*.mjs ~/.failproofai/policies/
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
-
Không cần lệnh cài đặt — các tệp được
|
|
353
|
+
Không cần lệnh cài đặt — các tệp được nhận diện tự động trên hook event tiếp theo.
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
---
|
|
2
|
+
---
|
|
2
3
|
title: Ví dụ
|
|
3
4
|
description: "Cách thiết lập hooks cho Claude Code và Agents SDK"
|
|
4
5
|
icon: book-open
|
|
5
6
|
---
|
|
6
7
|
|
|
7
|
-
Các ví dụ sẵn sàng sử dụng cho các tình huống phổ biến. Mỗi ví dụ cho thấy cách cài đặt và những gì
|
|
8
|
+
Các ví dụ sẵn sàng sử dụng cho các tình huống phổ biến. Mỗi ví dụ cho thấy cách cài đặt và những gì mong đợi.
|
|
8
9
|
|
|
9
10
|
---
|
|
10
11
|
|
|
11
12
|
## Thiết lập hooks cho Claude Code
|
|
12
13
|
|
|
13
|
-
Failproof AI tích hợp với Claude Code thông qua [hệ thống hooks](https://docs.anthropic.com/en/docs/claude-code/hooks)
|
|
14
|
+
Failproof AI tích hợp với Claude Code thông qua [hệ thống hooks](https://docs.anthropic.com/en/docs/claude-code/hooks). Khi bạn chạy `failproofai policies --install`, nó sẽ đăng ký các lệnh hook trong `settings.json` của Claude Code, được kích hoạt trên mỗi lệnh gọi công cụ.
|
|
14
15
|
|
|
15
16
|
<Steps>
|
|
16
17
|
<Step title="Cài đặt failproofai">
|
|
@@ -23,7 +24,7 @@ Failproof AI tích hợp với Claude Code thông qua [hệ thống hooks](https
|
|
|
23
24
|
failproofai policies --install
|
|
24
25
|
```
|
|
25
26
|
</Step>
|
|
26
|
-
<Step title="Xác minh
|
|
27
|
+
<Step title="Xác minh hooks đã được đăng ký">
|
|
27
28
|
```bash
|
|
28
29
|
cat ~/.claude/settings.json | grep failproofai
|
|
29
30
|
```
|
|
@@ -35,7 +36,7 @@ Failproof AI tích hợp với Claude Code thông qua [hệ thống hooks](https
|
|
|
35
36
|
claude
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
Các chính sách
|
|
39
|
+
Các chính sách hiện chạy tự động trên mỗi lệnh gọi công cụ. Hãy thử yêu cầu Claude chạy `sudo rm -rf /` - nó sẽ bị chặn.
|
|
39
40
|
</Step>
|
|
40
41
|
</Steps>
|
|
41
42
|
|
|
@@ -43,7 +44,7 @@ Failproof AI tích hợp với Claude Code thông qua [hệ thống hooks](https
|
|
|
43
44
|
|
|
44
45
|
## Thiết lập hooks cho Agents SDK
|
|
45
46
|
|
|
46
|
-
Nếu bạn đang xây dựng
|
|
47
|
+
Nếu bạn đang xây dựng với [Agents SDK](https://docs.anthropic.com/en/docs/agents-sdk), bạn có thể sử dụng cùng một hệ thống hook theo cách lập trình.
|
|
47
48
|
|
|
48
49
|
<Steps>
|
|
49
50
|
<Step title="Cài đặt failproofai trong dự án của bạn">
|
|
@@ -52,25 +53,25 @@ Nếu bạn đang xây dựng bằng [Agents SDK](https://docs.anthropic.com/en/
|
|
|
52
53
|
```
|
|
53
54
|
</Step>
|
|
54
55
|
<Step title="Cấu hình hooks trong agent của bạn">
|
|
55
|
-
Truyền các lệnh hook khi tạo quy trình agent của bạn. Các hooks kích hoạt
|
|
56
|
+
Truyền các lệnh hook khi tạo quy trình agent của bạn. Các hooks được kích hoạt theo cách tương tự như trong Claude Code - thông qua stdin/stdout JSON:
|
|
56
57
|
|
|
57
58
|
```bash
|
|
58
|
-
failproofai --hook PreToolUse #
|
|
59
|
-
failproofai --hook PostToolUse #
|
|
59
|
+
failproofai --hook PreToolUse # called before each tool
|
|
60
|
+
failproofai --hook PostToolUse # called after each tool
|
|
60
61
|
```
|
|
61
62
|
</Step>
|
|
62
|
-
<Step title="Viết
|
|
63
|
+
<Step title="Viết chính sách tùy chỉnh cho agent của bạn">
|
|
63
64
|
```javascript
|
|
64
65
|
import { customPolicies, allow, deny } from "failproofai";
|
|
65
66
|
|
|
66
67
|
customPolicies.add({
|
|
67
68
|
name: "limit-to-project-dir",
|
|
68
|
-
description: "
|
|
69
|
+
description: "Keep the agent inside the project directory",
|
|
69
70
|
match: { events: ["PreToolUse"] },
|
|
70
71
|
fn: async (ctx) => {
|
|
71
72
|
const path = String(ctx.toolInput?.file_path ?? "");
|
|
72
73
|
if (path.startsWith("/") && !path.startsWith(ctx.session?.cwd ?? "")) {
|
|
73
|
-
return deny("Agent
|
|
74
|
+
return deny("Agent is restricted to the project directory");
|
|
74
75
|
}
|
|
75
76
|
return allow();
|
|
76
77
|
},
|
|
@@ -86,51 +87,51 @@ Nếu bạn đang xây dựng bằng [Agents SDK](https://docs.anthropic.com/en/
|
|
|
86
87
|
|
|
87
88
|
---
|
|
88
89
|
|
|
89
|
-
## Chặn các lệnh
|
|
90
|
+
## Chặn các lệnh phá hủy
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
Thiết lập phổ biến nhất - ngăn chặn các agent thực hiện các hành động không thể hoàn tác.
|
|
92
93
|
|
|
93
94
|
```bash
|
|
94
95
|
failproofai policies --install block-sudo block-rm-rf block-force-push block-curl-pipe-sh
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
Điều này
|
|
98
|
+
Điều này thực hiện:
|
|
98
99
|
- `block-sudo` - chặn tất cả các lệnh `sudo`
|
|
99
100
|
- `block-rm-rf` - chặn xóa tệp đệ quy
|
|
100
101
|
- `block-force-push` - chặn `git push --force`
|
|
101
|
-
- `block-curl-pipe-sh` - chặn
|
|
102
|
+
- `block-curl-pipe-sh` - chặn piping các kịch bản từ xa vào shell
|
|
102
103
|
|
|
103
104
|
---
|
|
104
105
|
|
|
105
106
|
## Ngăn chặn rò rỉ bí mật
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
Ngăn các agent nhìn thấy hoặc rò rỉ thông tin xác thực trong kết quả công cụ.
|
|
108
109
|
|
|
109
110
|
```bash
|
|
110
111
|
failproofai policies --install sanitize-api-keys sanitize-jwt sanitize-connection-strings sanitize-bearer-tokens
|
|
111
112
|
```
|
|
112
113
|
|
|
113
|
-
Những
|
|
114
|
+
Những chính sách này được kích hoạt trên `PostToolUse` - sau khi công cụ chạy, chúng sẽ làm sạch kết quả trước khi agent nhìn thấy.
|
|
114
115
|
|
|
115
116
|
---
|
|
116
117
|
|
|
117
|
-
## Nhận cảnh báo Slack khi
|
|
118
|
+
## Nhận cảnh báo Slack khi các agent cần chú ý
|
|
118
119
|
|
|
119
|
-
Sử dụng hook thông báo để chuyển tiếp cảnh báo
|
|
120
|
+
Sử dụng hook thông báo để chuyển tiếp các cảnh báo chờ đợi đến Slack.
|
|
120
121
|
|
|
121
122
|
```javascript
|
|
122
123
|
import { customPolicies, allow, instruct } from "failproofai";
|
|
123
124
|
|
|
124
125
|
customPolicies.add({
|
|
125
126
|
name: "slack-on-idle",
|
|
126
|
-
description: "
|
|
127
|
+
description: "Alert Slack when the agent is waiting for input",
|
|
127
128
|
match: { events: ["Notification"] },
|
|
128
129
|
fn: async (ctx) => {
|
|
129
130
|
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
|
|
130
131
|
if (!webhookUrl) return allow();
|
|
131
132
|
|
|
132
|
-
const message = String(ctx.payload?.message ?? "Agent
|
|
133
|
-
const project = ctx.session?.cwd ?? "
|
|
133
|
+
const message = String(ctx.payload?.message ?? "Agent is waiting");
|
|
134
|
+
const project = ctx.session?.cwd ?? "unknown";
|
|
134
135
|
|
|
135
136
|
try {
|
|
136
137
|
await fetch(webhookUrl, {
|
|
@@ -142,7 +143,7 @@ customPolicies.add({
|
|
|
142
143
|
signal: AbortSignal.timeout(5000),
|
|
143
144
|
});
|
|
144
145
|
} catch {
|
|
145
|
-
//
|
|
146
|
+
// never block the agent if Slack is unreachable
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
return allow();
|
|
@@ -158,22 +159,22 @@ SLACK_WEBHOOK_URL=https://hooks.slack.com/... failproofai policies --install --c
|
|
|
158
159
|
|
|
159
160
|
---
|
|
160
161
|
|
|
161
|
-
## Giữ
|
|
162
|
+
## Giữ các agent trên một nhánh
|
|
162
163
|
|
|
163
|
-
Ngăn
|
|
164
|
+
Ngăn các agent chuyển đổi nhánh hoặc đẩy đến các nhánh được bảo vệ.
|
|
164
165
|
|
|
165
166
|
```javascript
|
|
166
167
|
import { customPolicies, allow, deny } from "failproofai";
|
|
167
168
|
|
|
168
169
|
customPolicies.add({
|
|
169
170
|
name: "stay-on-branch",
|
|
170
|
-
description: "
|
|
171
|
+
description: "Prevent the agent from checking out other branches",
|
|
171
172
|
match: { events: ["PreToolUse"] },
|
|
172
173
|
fn: async (ctx) => {
|
|
173
174
|
if (ctx.toolName !== "Bash") return allow();
|
|
174
175
|
const cmd = String(ctx.toolInput?.command ?? "");
|
|
175
176
|
if (/git\s+checkout\s+(?!-b)/.test(cmd)) {
|
|
176
|
-
return deny("
|
|
177
|
+
return deny("Stay on the current branch. Create a new branch with -b if needed.");
|
|
177
178
|
}
|
|
178
179
|
return allow();
|
|
179
180
|
},
|
|
@@ -184,20 +185,20 @@ customPolicies.add({
|
|
|
184
185
|
|
|
185
186
|
## Yêu cầu kiểm tra trước khi commit
|
|
186
187
|
|
|
187
|
-
Nhắc nhở
|
|
188
|
+
Nhắc nhở các agent chạy các bài kiểm tra trước khi commit.
|
|
188
189
|
|
|
189
190
|
```javascript
|
|
190
191
|
import { customPolicies, allow, instruct } from "failproofai";
|
|
191
192
|
|
|
192
193
|
customPolicies.add({
|
|
193
194
|
name: "test-before-commit",
|
|
194
|
-
description: "
|
|
195
|
+
description: "Remind the agent to run tests before committing",
|
|
195
196
|
match: { events: ["PreToolUse"] },
|
|
196
197
|
fn: async (ctx) => {
|
|
197
198
|
if (ctx.toolName !== "Bash") return allow();
|
|
198
199
|
const cmd = String(ctx.toolInput?.command ?? "");
|
|
199
200
|
if (/git\s+commit/.test(cmd)) {
|
|
200
|
-
return instruct("
|
|
201
|
+
return instruct("Run tests before committing. Use `npm test` or `bun test` first.");
|
|
201
202
|
}
|
|
202
203
|
return allow();
|
|
203
204
|
},
|
|
@@ -206,9 +207,9 @@ customPolicies.add({
|
|
|
206
207
|
|
|
207
208
|
---
|
|
208
209
|
|
|
209
|
-
## Khóa kho lưu trữ
|
|
210
|
+
## Khóa chặt kho lưu trữ production
|
|
210
211
|
|
|
211
|
-
Commit một cấu hình
|
|
212
|
+
Commit một cấu hình cấp dự án để mỗi nhà phát triển trong nhóm của bạn nhận được cùng các chính sách.
|
|
212
213
|
|
|
213
214
|
Tạo `.failproofai/policies-config.json` trong kho lưu trữ của bạn:
|
|
214
215
|
|
|
@@ -238,16 +239,70 @@ git add .failproofai/policies-config.json
|
|
|
238
239
|
git commit -m "Add failproofai team policies"
|
|
239
240
|
```
|
|
240
241
|
|
|
241
|
-
Mỗi thành viên
|
|
242
|
+
Mỗi thành viên nhóm đã cài đặt failproofai sẽ tự động áp dụng các quy tắc này.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Xây dựng tiêu chuẩn chất lượng trên toàn tổ chức với các chính sách quy ước
|
|
247
|
+
|
|
248
|
+
Thiết lập có ảnh hưởng nhất: commit `.failproofai/policies/` vào kho lưu trữ của bạn với các chính sách được điều chỉnh cho dự án của bạn. Mỗi thành viên nhóm sẽ nhận được chúng tự động — không cần các lệnh cài đặt, không cần thay đổi cấu hình.
|
|
249
|
+
|
|
250
|
+
<Steps>
|
|
251
|
+
<Step title="Tạo thư mục và thêm các chính sách">
|
|
252
|
+
```bash
|
|
253
|
+
mkdir -p .failproofai/policies
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```js
|
|
257
|
+
// .failproofai/policies/team-policies.mjs
|
|
258
|
+
import { customPolicies, allow, deny, instruct } from "failproofai";
|
|
259
|
+
|
|
260
|
+
// Enforce your team's preferred package manager
|
|
261
|
+
// (or enable the built-in prefer-package-manager policy instead)
|
|
262
|
+
customPolicies.add({
|
|
263
|
+
name: "enforce-bun",
|
|
264
|
+
match: { events: ["PreToolUse"] },
|
|
265
|
+
fn: async (ctx) => {
|
|
266
|
+
if (ctx.toolName !== "Bash") return allow();
|
|
267
|
+
const cmd = String(ctx.toolInput?.command ?? "");
|
|
268
|
+
if (/\bnpm\b/.test(cmd)) return deny("Use bun instead of npm.");
|
|
269
|
+
return allow();
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// Remind the agent to run tests before committing
|
|
274
|
+
customPolicies.add({
|
|
275
|
+
name: "test-before-commit",
|
|
276
|
+
match: { events: ["PreToolUse"] },
|
|
277
|
+
fn: async (ctx) => {
|
|
278
|
+
if (ctx.toolName !== "Bash") return allow();
|
|
279
|
+
if (/git\s+commit/.test(ctx.toolInput?.command ?? "")) {
|
|
280
|
+
return instruct("Run tests before committing.");
|
|
281
|
+
}
|
|
282
|
+
return allow();
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
</Step>
|
|
287
|
+
<Step title="Commit vào git">
|
|
288
|
+
```bash
|
|
289
|
+
git add .failproofai/policies/
|
|
290
|
+
git commit -m "Add team quality policies"
|
|
291
|
+
```
|
|
292
|
+
</Step>
|
|
293
|
+
<Step title="Tiếp tục cải thiện">
|
|
294
|
+
Khi nhóm của bạn gặp phải các chế độ lỗi mới, thêm các chính sách và đẩy. Mọi người sẽ nhận được bản cập nhật trên `git pull` tiếp theo của họ. Những chính sách này trở thành một tiêu chuẩn chất lượng sống động phát triển cùng với nhóm của bạn.
|
|
295
|
+
</Step>
|
|
296
|
+
</Steps>
|
|
242
297
|
|
|
243
298
|
---
|
|
244
299
|
|
|
245
|
-
##
|
|
300
|
+
## Các ví dụ khác
|
|
246
301
|
|
|
247
302
|
Thư mục [`examples/`](https://github.com/exospherehost/failproofai/tree/main/examples) trong kho lưu trữ chứa:
|
|
248
303
|
|
|
249
|
-
| Tệp |
|
|
304
|
+
| Tệp | Nó cho thấy điều gì |
|
|
250
305
|
|------|---------------|
|
|
251
|
-
| `policies-basic.js` | Các chính sách khởi động - chặn ghi
|
|
252
|
-
| `policies-notification.js` | Cảnh báo Slack cho thông báo
|
|
253
|
-
| `policies-advanced/index.js` |
|
|
306
|
+
| `policies-basic.js` | Các chính sách khởi động - chặn ghi production, force-push, kịch bản được piping |
|
|
307
|
+
| `policies-notification.js` | Cảnh báo Slack cho các thông báo chờ đợi và kết thúc phiên |
|
|
308
|
+
| `policies-advanced/index.js` | Các lần nhập chuyển tiếp, hooks không đồng bộ, làm sạch kết quả PostToolUse, xử lý sự kiện Stop |
|