Overview
ל-failproofai יש שתי תת-מערכות עצמאיות:- Hook handler - CLI subprocess מהיר שClaude Code קורא לו בכל קריאת Tool של Agent. מעריך Policies ומחזיר החלטה.
- Agent Monitor (Dashboard) - אפליקציית Next.js לעקיבה אחרי סשנים של Agent וניהול Policies.
~/.failproofai/ ובתיקייה .failproofai/ של הפרויקט, אך הן רצות כתהליכים נפרדים ותקשרו רק דרך מערכת הקבצים.
Hook handler
Integration עם Claude Code
כאשר אתה מריץfailproofai policies --install, הוא כותב entries כמו זה ל-~/.claude/settings.json:
failproofai --hook PreToolUse כ-subprocess לפני כל קריאת Tool, ומעביר JSON payload על stdin.
פורמט Payload
PostToolUse, ה-payload גם כולל tool_result עם Output של ה-Tool.
ה-Handler אוכף מגבלת stdin של 1 MB. Payloads החוצים זאת מושלכים וכל Policies באופן implicit מאפשרים.
Response format
Deny (PreToolUse):- Exit code:
2 - Reason כתוב ל-stderr (לא stdout)
- Exit code:
0 - stdout ריק
allow(message) מאפשר לPolicy לשלוח Context informational חזרה ל-Claude גם כאשר הפעולה מותרת. ה-Hook Handler כותב את ה-JSON הבא ל-stdout (לא קובץ Config — זה ה-Response של ה-Handler ל-Claude Code, בדיוק כמו Deny ו-Instruct responses למעלה):
- Exit code:
0(הפעולה מותרת) - כאשר multiple Policies מחזירות
allowעם Message, ה-Messages שלהם מצורפות עם newlines לתוך stringadditionalContextיחיד - אם אף Policy לא מספק Message, stdout ריק (כמו קודם)
Processing pipeline
src/hooks/handler.ts מיישם את כל ה-Pipeline:
Configuration loading
src/hooks/hooks-config.ts מיישם שלוש-scope Config loading.
enabledPolicies- deduplicated union על כל שלושת הקבציםpolicyParams- per-policy key, הקובץ הראשון שמגדיר אותו מנצח לחלוטיןcustomPoliciesPath- הקובץ הראשון שמגדיר אותו מנצחllm- הקובץ הראשון שמגדיר אותו מנצח
readHooksConfig() (global only) לקריאה וכתיבה, מכיוון שהוא לא קרוא עם Project cwd.
Policy evaluation
src/hooks/policy-evaluator.ts מריץ Policies בסדר.
עבור כל Policy:
- חפש את ה-
paramsschema של ה-Policy (אם יש לו). - קרא
policyParams[policy.name]מה-Merged Config. - Merge user-provided values על schema defaults לייצור
ctx.params. - קרא
policy.fn(ctx)עם ה-Resolved Context. - אם ה-Result הוא
deny, עצור מיד וחזור בהחלטה זו. - אם ה-Result הוא
instruct, צבור את ה-Message והמשך. - אם ה-Result הוא
allow, המשך ל-Policy הבא.
- אם כל
denyחזר, emit את ה-Deny Response. - אם כל
instructreturns נאספו, emit Responseinstructיחיד עם כל Messages מצורפות. - אחרת, emit Allow Response (stdout ריק, exit 0).
Builtin policies
src/hooks/builtin-policies.ts מגדיר את כל 39 ה-Builtin Policies כ-BuiltinPolicyDefinition objects:
params מכריזות PolicyParamsSchema עם Types וDefaults עבור כל Parameter. ה-Policy Evaluator משדר Resolved Values ל-ctx.params לפני קריאה ל-fn. Policy Functions קוראות ctx.params בלי Null-Guarding כי Defaults תמיד מיושמות ראשון.
Pattern Matching בתוך Policies משתמש בParsed Command Tokens (argv), לא Raw String Matching. זה מונע Bypass דרך Shell Operator Injection (למשל Pattern עבור sudo systemctl status * לא יכול להיות bypassed על ידי Appending ; rm -rf / לפקודה).
Custom policies
src/hooks/custom-hooks-registry.ts מיישם globalThis-backed Registry:
src/hooks/custom-hooks-loader.ts טוען את Policy File של ה-User:
- קרא
customPoliciesPathמ-Config; דלג אם חסר. - Resolve ל-Absolute Path; בדוק אם הקובץ קיים.
- כתוב מחדש את כל
from "failproofai"Imports ל-Actual Dist Path כדי שה-customPoliciesיתמוקד ל-globalThisRegistry אותו. - כתוב מחדש באופן Recursive Transitive Local Imports כדי להבטיח ESM Compatibility.
- כתוב Temporary
.mjsFiles ו-import()את Entry File. - קרא
getCustomHooks()כדי לאחזר Registered Hooks. - נקה את כל Temp Files בבלוק
finally.
~/.failproofai/hook.log ו-Loader מחזיר Array ריק. Builtin Policies לא מושפעות.
Custom Policies מוערכות לאחר כל Builtin Policies. Custom Policy deny עדיין Short-Circuits Further Custom Policies (אבל כל ה-Builtins כבר רצו בנקודה זו).
Activity logging
לאחר כל Hook Event, ה-Handler Appends JSONL Line ל-~/.failproofai/hook-activity.jsonl:
Dashboard architecture
ה-Dashboard היא אפליקציית Next.js 16 באמצעות App Router עם React Server Components ו-Server Actions.- Page Components קוראים ל-
lib/projects.tsו-lib/log-entries.tsכדי לקרוא Project/Session Data ישירות מ-Filesystem (אין API Layer עבור Reads). - ה-Policies Page משתמשת ב-Server Actions עבור כל Mutations (Toggle, Params Update, Install/Remove).
- ה-Session Viewer מנתח Claude’s JSONL Transcript Format ומרנדר Timeline של Messages וTool Calls.
- No Database - כל Persistent State נמצא בקבצים רגילים (
~/.failproofai/,~/.claude/projects/). - Server Actions לMutations - אין צורך ב-REST API עבור CRUD Operations.
- React Server Components לRead Pages - Fast Initial Load, לא Client Bundle עבור Data Fetching.
- Client Components רק כאשר Interactivity נדרשת (Policy Toggles, Activity Search, Log Viewer).

