> ## Documentation Index
> Fetch the complete documentation index at: https://exosphere-auto-translate-docs-20260623-1106.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

title: דוגמאות
description: "כיצד להגדיר hooks עבור Claude Code ו-Agents SDK"
icon: book-open
---------------

דוגמאות מוכנות לשימוש עבור תרחישים נפוצים. כל אחת מהן מציגה כיצד להתקין ומה לצפות לו.

***

## הגדרת hooks עבור Claude Code

Failproof AI משתלבת עם Claude Code דרך [מערכת ה-hooks שלו](https://docs.anthropic.com/en/docs/claude-code/hooks). כאשר אתה מריץ `failproofai policies --install`, היא רושמת פקודות hook ב-`settings.json` של Claude Code שמופעלות בכל קריאת כלי.

<Steps>
  <Step title="התקן את failproofai">
    ```bash theme={null}
    npm install -g failproofai
    ```
  </Step>

  <Step title="הפעל את כל המדיניות המובנית">
    ```bash theme={null}
    failproofai policies --install
    ```
  </Step>

  <Step title="אמת שהוקמו hooks">
    ```bash theme={null}
    cat ~/.claude/settings.json | grep failproofai
    ```

    אתה אמור לראות ערכי hook עבור אירועים `PreToolUse`, `PostToolUse`, `Notification` ו-`Stop`.
  </Step>

  <Step title="הרץ את Claude Code">
    ```bash theme={null}
    claude
    ```

    המדיניויות פועלות כעת באופן אוטומטי בכל קריאת כלי. נסה לבקש מ-Claude להריץ `sudo rm -rf /` - זה יחסום.
  </Step>
</Steps>

***

## הגדרת hooks עבור Agents SDK

אם אתה בונה עם [Agents SDK](https://docs.anthropic.com/en/docs/agents-sdk), אתה יכול להשתמש באותה מערכת hook בצורה תכנותית.

<Steps>
  <Step title="התקן את failproofai בפרויקט שלך">
    ```bash theme={null}
    npm install failproofai
    ```
  </Step>

  <Step title="הגדר hooks בסוכן שלך">
    העבר פקודות hook כאשר אתה יוצר את תהליך הסוכן. ה-hooks מופעלים באותו אופן כמו ב-Claude Code - דרך stdin/stdout JSON:

    ```bash theme={null}
    failproofai --hook PreToolUse   # called before each tool
    failproofai --hook PostToolUse  # called after each tool
    ```
  </Step>

  <Step title="כתוב מדיניות מותאמת עבור הסוכן שלך">
    ```javascript theme={null}
    import { customPolicies, allow, deny } from "failproofai";

    customPolicies.add({
      name: "limit-to-project-dir",
      description: "Keep the agent inside the project directory",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        const path = String(ctx.toolInput?.file_path ?? "");
        if (path.startsWith("/") && !path.startsWith(ctx.session?.cwd ?? "")) {
          return deny("Agent is restricted to the project directory");
        }
        return allow();
      },
    });
    ```
  </Step>

  <Step title="התקן את המדיניות המותאמת">
    ```bash theme={null}
    failproofai policies --install --custom ./my-agent-policies.js
    ```
  </Step>
</Steps>

***

## חסום פקודות הורסות

ההגדרה הנפוצה ביותר - מנע מסוכנים לגרום נזק בלתי הפיך.

```bash theme={null}
failproofai policies --install block-sudo block-rm-rf block-force-push block-curl-pipe-sh
```

מה זה עושה:

* `block-sudo` - חוסם את כל פקודות ה-`sudo`
* `block-rm-rf` - חוסם מחיקת קבצים רקורסיבית
* `block-force-push` - חוסם `git push --force`
* `block-curl-pipe-sh` - חוסם העברת סקריפטים מרחוקים אל shell

***

## מנע דליפת סודות

עצור סוכנים מלראות או להדליף אישורים בפלט הכלי.

```bash theme={null}
failproofai policies --install sanitize-api-keys sanitize-jwt sanitize-connection-strings sanitize-bearer-tokens
```

אלה מופעלים על `PostToolUse` - לאחר שכלי רץ, הם מנקים את הפלט לפני שהסוכן רואה אותו.

***

## קבל התראות Slack כשסוכנים זקוקים לתשומת לב

השתמש ב-notification hook להעברת התראות צפי ל-Slack.

```javascript theme={null}
import { customPolicies, allow, instruct } from "failproofai";

customPolicies.add({
  name: "slack-on-idle",
  description: "Alert Slack when the agent is waiting for input",
  match: { events: ["Notification"] },
  fn: async (ctx) => {
    const webhookUrl = process.env.SLACK_WEBHOOK_URL;
    if (!webhookUrl) return allow();

    const message = String(ctx.payload?.message ?? "Agent is waiting");
    const project = ctx.session?.cwd ?? "unknown";

    try {
      await fetch(webhookUrl, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          text: `*${message}*\nProject: \`${project}\``,
        }),
        signal: AbortSignal.timeout(5000),
      });
    } catch {
      // never block the agent if Slack is unreachable
    }

    return allow();
  },
});
```

התקן זאת:

```bash theme={null}
SLACK_WEBHOOK_URL=https://hooks.slack.com/... failproofai policies --install --custom ./slack-alerts.js
```

***

## שמור סוכנים על ענף

מנע מסוכנים להחליף ענפים או לדחוף לענפים מוגנים.

```javascript theme={null}
import { customPolicies, allow, deny } from "failproofai";

customPolicies.add({
  name: "stay-on-branch",
  description: "Prevent the agent from checking out other branches",
  match: { events: ["PreToolUse"] },
  fn: async (ctx) => {
    if (ctx.toolName !== "Bash") return allow();
    const cmd = String(ctx.toolInput?.command ?? "");
    if (/git\s+checkout\s+(?!-b)/.test(cmd)) {
      return deny("Stay on the current branch. Create a new branch with -b if needed.");
    }
    return allow();
  },
});
```

***

## דרוש בדיקות לפני commits

תזכור לסוכנים להריץ בדיקות לפני ביצוע commit.

```javascript theme={null}
import { customPolicies, allow, instruct } from "failproofai";

customPolicies.add({
  name: "test-before-commit",
  description: "Remind the agent to run tests before committing",
  match: { events: ["PreToolUse"] },
  fn: async (ctx) => {
    if (ctx.toolName !== "Bash") return allow();
    const cmd = String(ctx.toolInput?.command ?? "");
    if (/git\s+commit/.test(cmd)) {
      return instruct("Run tests before committing. Use `npm test` or `bun test` first.");
    }
    return allow();
  },
});
```

***

## נעל מחסן production

בצע commit של קובץ הגדרות ברמת הפרויקט כדי שכל מפתח בצוות שלך יקבל אותן מדיניויות.

צור `.failproofai/policies-config.json` בריפו שלך:

```json theme={null}
{
  "enabledPolicies": [
    "block-sudo",
    "block-rm-rf",
    "block-force-push",
    "block-push-master",
    "block-env-files",
    "sanitize-api-keys",
    "sanitize-jwt"
  ],
  "policyParams": {
    "block-push-master": {
      "protectedBranches": ["main", "release", "production"]
    }
  }
}
```

ואז בצע commit:

```bash theme={null}
git add .failproofai/policies-config.json
git commit -m "Add failproofai team policies"
```

כל חבר בצוות שיש לו failproofai מותקן יקטום את הכללים האלה באופן אוטומטי.

***

## בנה תקן איכות בקנה מידה של ארגון עם מדיניות convention

ההגדרה בעלת ההשפעה הגדולה ביותר: בצע commit של `.failproofai/policies/` לריפו שלך עם מדיניויות המותאמות לפרויקט שלך. כל חבר בצוות מקבל אותן באופן אוטומטי - ללא פקודות התקנה, ללא שינויי הגדרה.

<Steps>
  <Step title="צור את התיקייה והוסף מדיניויות">
    ```bash theme={null}
    mkdir -p .failproofai/policies
    ```

    ```js theme={null}
    // .failproofai/policies/team-policies.mjs
    import { customPolicies, allow, deny, instruct } from "failproofai";

    // Enforce your team's preferred package manager
    // (or enable the built-in prefer-package-manager policy instead)
    customPolicies.add({
      name: "enforce-bun",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        if (ctx.toolName !== "Bash") return allow();
        const cmd = String(ctx.toolInput?.command ?? "");
        if (/\bnpm\b/.test(cmd)) return deny("Use bun instead of npm.");
        return allow();
      },
    });

    // Remind the agent to run tests before committing
    customPolicies.add({
      name: "test-before-commit",
      match: { events: ["PreToolUse"] },
      fn: async (ctx) => {
        if (ctx.toolName !== "Bash") return allow();
        if (/git\s+commit/.test(ctx.toolInput?.command ?? "")) {
          return instruct("Run tests before committing.");
        }
        return allow();
      },
    });
    ```
  </Step>

  <Step title="בצע commit ל-git">
    ```bash theme={null}
    git add .failproofai/policies/
    git commit -m "Add team quality policies"
    ```
  </Step>

  <Step title="המשך בשיפור">
    כאשר הצוות שלך נתקל בהצורות כשל חדשות, הוסף מדיניויות והדחף. כולם מקבלים את העדכון ב-`git pull` הבא שלהם. המדיניויות הללו הופכות לתקן איכות חי שגדל עם הצוות שלך.
  </Step>
</Steps>

***

## דוגמאות נוספות

תיקייה [`examples/`](https://github.com/failproofai/failproofai/tree/main/examples) בריפו מכילה:

| קובץ                         | מה הוא מציג                                                                  |
| ---------------------------- | ---------------------------------------------------------------------------- |
| `policies-basic.js`          | מדיניויות התחלות - חסום כתיבה production, force-push, סקריפטים מובילים       |
| `policies-notification.js`   | התראות Slack עבור הודעות צפי וסיום הפעלה                                     |
| `policies-advanced/index.js` | יבואות טרנזיטיביות, hook אסינכרוני, ניקוי פלט PostToolUse, טיפול באירוע Stop |
