
قواعد أمان محمولة لحدود إجراء وكلاء الذكاء الاصطناعي
مواصفة محمولة ومفتوحة لقواعد أمان وكلاء الذكاء الاصطناعي
المواصفة · الوثائق · مجموعات القواعد · مخطط JSON
HushSpec هو تنسيق سياسة مفتوح لقواعد أمان وكلاء الذكاء الاصطناعي. يحدد ما قد يفعله الوكيل في وقت التشغيل، بما في ذلك الوصول إلى نظام الملفات، الخروج الشبكي، استخدام الأدوات، كشف الأسرار، والمزيد، دون فرض كيف يجب تطبيق هذه الضوابط. هذا الفصل يجعل السياسات محمولة عبر بيئات التشغيل، الأطر، واللغات.
v0.1.1-alpha — المواصفة الأساسية، جميع حزم SDK الأربع (Rust، TypeScript، Python، Go)، وواجهة سطر الأوامر h2h منشورة وتعمل. قم بالتحليل، التحقق، التقييم، الدمج، الحل، الكشف، التوقيع، والتدقيق عبر 10 أنواع قواعد و3 وحدات امتداد. سطح API يستقر ولكنه لم يتجمد بعد — توقع تحسينات قبل v1.0.
hushspec: "0.1.0"
name: production-agent
rules:
forbidden_paths:
patterns:
- "**/.ssh/**"
- "**/.aws/**"
- "/etc/shadow"
egress:
allow:
- "api.openai.com"
- "*.anthropic.com"
- "api.github.com"
default: block
tool_access:
block: [shell_exec, run_command]
require_confirmation: [file_write, git_push]
default: allow
secret_patterns:
patterns:
- name: aws_key
pattern: "AKIA[0-9A-Z]{16}"
severity: critical
skip_paths: ["**/test/**"]
shell_commands:
forbidden_patterns:
- "rm\\s+-rf\\s+/"
- "curl.*\\|.*bash"
جميع حزم SDK الأربع تنفذ خط أنابيب HushSpec الكامل، من التحليل والتحقق عبر الحل والتقييم.
تصبح Homebrew، npm، والثنائيات المُجمّعة مسبقاً متاحة بدءاً من أول علامة
v0.xالتي بنتها خطوة الإصدار، بمجرد أن تنشر خطوة الإصدار القطع الفنية، صيغة الـ tap، وحزم npm. حتى ذلك الحين، قم بالتثبيت عبر Cargo.
جميع الطرق تثبت الأمر h2h. انظر أداة CLI أدناه.
[dependencies]
hushspec = "0.1"
npm install @hushspec/core
pip install hushspec
go get github.com/backbay-labs/hush/packages/go@main
use hushspec::HushSpec;
let yaml_str = "hushspec: \"0.1.0\"\nname: example\n";
let spec = HushSpec::parse(yaml_str)?;
let result = hushspec::validate(&spec);
assert!(result.is_valid());
import { parseOrThrow, validate } from '@hushspec/core';
const yamlString = 'hushspec: "0.1.0"\nname: example\n';
const spec = parseOrThrow(yamlString);
const result = validate(spec);
console.log(result.valid); // true
from hushspec import parse_or_raise, validate
yaml_string = 'hushspec: "0.1.0"\nname: example\n'
spec = parse_or_raise(yaml_string)
result = validate(spec)
assert result.is_valid
import (
"fmt"
"github.com/backbay-labs/hush/packages/go/hushspec"
)
yamlString := "hushspec: \"0.1.0\"\nname: example\n"
spec, err := hushspec.Parse(yamlString)
if err != nil {
panic(err)
}
result := hushspec.Validate(spec)
fmt.Println(result.IsValid())
كل SDK يعرض دالة evaluate() تأخذ مواصفة محللة وإجراءً، ثم تعيد قراراً (allow، warn، أو deny) بالإضافة إلى تفاصيل القاعدة المطابقة.
import { parseOrThrow, evaluate } from '@hushspec/core';
const spec = parseOrThrow(policyYaml);
const result = evaluate(spec, { type: 'egress', target: 'api.openai.com' });
// result.decision === 'allow' | 'warn' | 'deny'
// result.matched_rule === 'egress'
from hushspec import parse_or_raise, evaluate
spec = parse_or_raise(policy_yaml)
result = evaluate(spec, {"type": "egress", "target": "api.openai.com"})
assert result.decision in ("allow", "warn", "deny")
HushGuard يُغلف تحميل السياسة والتقييم خلف واجهة بسيطة evaluate، check، وenforce لكود التطبيق.
import { HushGuard } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
guard.enforce({ type: 'tool_call', target: 'bash' }); // throws HushSpecDenied if denied
from hushspec import HushGuard
guard = HushGuard.from_file("./policy.yaml")
guard.enforce({"type": "tool_call", "target": "bash"}) # raises HushSpecDenied if denied
واجهة سطر الأوامر h2h تغطي سير عمل السياسة الشائع: التحقق، الاختبار، التقييم وشرح الإجراءات الفردية، التدقيق، المقارنة، التنسيق، التهيئة، التوقيع، التحقق، وتشغيل وضع الطوارئ.
# التحقق من سياسة مقابل مخطط HushSpec
h2h validate policy.yaml
# تشغيل مجموعات اختبار التقييم
h2h test --fixtures ./tests/
# تقييم إجراء واحد وشرح القرار
h2h eval policy.yaml --type egress --target api.example.com
h2h explain policy.yaml --type egress --target api.example.com
# التحليل الثابت والتدقيق
h2h lint policy.yaml
# التدقيق والإصلاح التلقائي للمشكلات المحايدة للقرار
h2h lint policy.yaml --fix
# مقارنة سياستين وعرض تغييرات القرار الفعالة
h2h diff old.yaml new.yaml
# تنسيق ملفات السياسة بشكل نظامي
h2h fmt policy.yaml
# إنشاء هيكل مشروع سياسة جديد
h2h init --preset default
# توقيع سياسة باستخدام Ed25519
h2h sign policy.yaml --key h2h.key
# التحقق من توقيع السياسة
h2h verify policy.yaml --key h2h.pub
# توليد زوج مفاتيح Ed25519 جديد
h2h keygen
# تجاوز طارئ (مفتاح قتل يرفض الكل)
h2h panic activate --sentinel /tmp/hushspec.panic
h2h panic deactivate --sentinel /tmp/hushspec.panic
انظر التثبيت أعلاه لخيارات التثبيت — Homebrew، npm، Cargo، أو الثنائيات المُجمّعة مسبقاً.
تولد الدالة evaluate_audited() إيصالات قرار منظمة مع آثار القواعد، ملخصات السياسة، وتحرير محتوى اختياري. تتوافق الإيصالات مع hushspec-receipt.v0.schema.json وهي مصممة لدعم بيئات التدقيق الثقيلة مثل SOC 2، HIPAA، PCI-DSS، وFedRAMP.
import { parseOrThrow, evaluateAudited } from '@hushspec/core';
const spec = parseOrThrow(policyYaml);
const receipt = evaluateAudited(spec, action, {
enabled: true,
include_rule_trace: true,
redact_content: false,
});
// receipt.decision, receipt.rule_evaluations, receipt.policy_summary
مصارف الإيصالات (FileReceiptSink، ConsoleReceiptSink، FilteredSink، MultiSink، CallbackSink) متاحة في جميع حزم SDK الأربع لتوجيه الإيصالات إلى التخزين، التسجيل، أو نقاط نهاية OTLP.
خط أنابيب الكشف يدمج فحوص حقن التعليمات، كسر القيود، والتصدير في تدفق التقييم. كاشفات مرجعية مبنية على التعبيرات النمطية تُشحن مع جميع حزم SDK، ويمكن تسجيل كاشفات مخصصة عبر DetectorRegistry.
import { parseOrThrow, evaluateWithDetection, DetectorRegistry } from '@hushspec/core';
const registry = DetectorRegistry.withDefaults();
const result = evaluateWithDetection(spec, action, registry, {
enabled: true,
prompt_injection_threshold: 0.5,
});
// result.detection_results contains matched patterns and confidence scores
محولات مبنية مسبقاً تُترجم استدعاءات الأدوات الخاصة بالأطر إلى إجراءات تقييم HushSpec.
واجهة EvaluationObserver وغلاف ObservableEvaluator يصدران أحداثاً منظمة لكل تقييم، تحميل سياسة، وإعادة تحميل سياسة. المراقبون المضمنون يشملون JsonLineObserver، ConsoleObserver، وMetricsCollector.
import { ObservableEvaluator, JsonLineObserver, MetricsCollector } from '@hushspec/core';
const evaluator = new ObservableEvaluator();
evaluator.addObserver(new JsonLineObserver(process.stderr));
evaluator.addObserver(new MetricsCollector());
const result = evaluator.evaluate(spec, action);
يمكن توقيع السياسات بمفاتيح Ed25519 والتحقق منها عند التحميل. توفر CLI أوامر sign، verify، وkeygen. تنسيق التوقيع يتوافق مع hushspec-signature.v0.schema.json.
# توليد زوج مفاتيح
h2h keygen --output-dir mykeys
# توقيع سياسة (ينشئ policy.yaml.sig)
h2h sign policy.yaml --key mykeys/h2h.key
# التحقق من التوقيع
h2h verify policy.yaml --key mykeys/h2h.pub
وضع الطوارئ هو مفتاح قتل يرفض الكل يمكن تفعيله فوراً دون إعادة نشر السياسات. يمكنك تشغيله بملف حارس، واجهة CLI، أو استدعاء API. بينما وضع الطوارئ نشط، كل تقييم يرجع deny.
# تفعيل وضع الطوارئ
h2h panic activate --sentinel /tmp/hushspec.panic
# إلغاء التفعيل
h2h panic deactivate --sentinel /tmp/hushspec.panic
import { activatePanic, deactivatePanic, isPanicActive } from '@hushspec/core';
activatePanic();
// All evaluate() calls now return deny
deactivatePanic();
يمكن تحميل السياسات من ملفات محلية، عناوين URL HTTPS (مع تخزين ETag وحماية SSRF)، أو مجموعات قواعد مدمجة. PolicyWatcher وPolicyPoller يدعمان إعادة التحميل السريع دون إعادة تشغيل العملية.
import { PolicyWatcher, HushGuard } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
const watcher = new PolicyWatcher('./policy.yaml', {
onChange: (newSpec) => guard.swapPolicy(newSpec),
});
watcher.start();
يدعم HushSpec وحدات امتداد اختيارية لسلوك سياسة أكثر تقدماً:
| الامتداد | الغرض |
|---|---|
| Posture | آلة حالة تصريحية للقدرات والميزانيات |
| Origins | إسقاط سياسة واعي بالأصل (Slack، GitHub، البريد الإلكتروني، إلخ) |
| Detection | تكوين عتبة لحقن التعليمات، كسر القيود، استخبارات التهديدات |
extensions:
posture:
initial: standard
states:
standard: { capabilities: [file_access, egress] }
restricted: { capabilities: [file_access] }
transitions:
- { from: "*", to: restricted, on: critical_violation }
detection:
prompt_injection:
block_at_or_above: high
سياسات جاهزة للاستخدام موجودة في rulesets/:
مستندات HushSpec تُحمّل أصلاً في Clawdstrike:
// Auto-detects HushSpec vs Clawdstrike-native format
let policy = clawdstrike::Policy::from_yaml_auto(yaml)?;
# التحويل بين التنسيقات
hush policy migrate policy.yaml --to hushspec
spec/ المواصفة المعيارية، بما في ذلك وثائق الأساس والامتداد
schemas/ تعريفات مخطط JSON
crates/ حزم Rust
hushspec/ المكتبة الأساسية: تحليل، تحقق، دمج، حل، تقييم، كشف، توقيع
hushspec-cli/ أداة CLI
hushspec-testkit/ مشغل اختبارات المطابقة
packages/ حزم SDK للغات TypeScript وPython وGo
rulesets/ مجموعات قواعد الأمان المدمجة
fixtures/ تركيبات المطابقة والتقييم
docs/ موقع توثيق mdBook
generated/ قطع أثرية لعقد SDK المشترك المولدة
scripts/ أدوات توليد الكود و CI
المواصفة المعيارية موجودة في spec/. تعريفات مخطط JSON للتحقق البرمجي موجودة في [schemas/](./schemas/]. التوثيق الكامل موجود في docs/.
Apache-2.0. انظر LICENSE.
| القدرة | Rust | TypeScript | Python | Go |
|---|
| تحليل + تحقق (Level 1) | نعم | نعم | نعم | نعم |
| دمج (Level 2) | نعم | نعم | نعم | نعم |
| حل (Level 2+) | نعم | نعم | نعم | نعم |
| تقييم (Level 3) | نعم | نعم | نعم | نعم |
| مسار التدقيق (Level 4) | نعم | نعم | نعم | نعم |
| كشف | نعم | نعم | نعم | نعم |
| مراقبة | نعم | نعم | نعم | نعم |
| مصارف الإيصالات | نعم | نعم | نعم | نعم |
| الطريقة | الأمر |
|---|
| Homebrew (macOS/Linux) | brew install backbay-labs/tap/h2h |
| npm | npm install -g @hushspec/cli (أو npx @hushspec/cli validate policy.yaml) |
| Cargo (من المصدر) | cargo install hushspec-cli |
| ثنائيات مُجمّعة مسبقاً | GitHub Releases — h2h-<tag>-<target>.tar.gz + SHA256SUMS، موثقة المصدر |
| الإطار | المحول | SDK |
|---|
| Claude / Anthropic | mapClaudeToolToAction, createSecureToolHandler | TypeScript |
| OpenAI | mapOpenAIToolCall, createOpenAIGuard | TypeScript |
| MCP (بروتوكول سياق النموذج) | mapMCPToolCall, createMCPGuard | TypeScript |
import { HushGuard, mapClaudeToolToAction } from '@hushspec/core';
const guard = HushGuard.fromFile('./policy.yaml');
const action = mapClaudeToolToAction(toolUseBlock);
guard.enforce(action);
| القاعدة | الغرض |
|---|
forbidden_paths | منع الوصول إلى مسارات نظام الملفات الحساسة |
path_allowlist | وصول قراءة/كتابة/تعديل قائم على القائمة البيضاء |
egress | التحكم بالخروج الشبكي حسب النطاق |
secret_patterns | كشف الأسرار في محتوى الملفات |
patch_integrity | التحقق من سلامة التعديل (حدود الحجم، أنماط محظورة) |
shell_commands | حظر أوامر شل خطيرة |
tool_access | التحكم في استدعاءات الأدوات/MCP |
computer_use | التحكم في إجراءات CUA |
remote_desktop_channels | التحكم في القنوات الجانبية لسطح المكتب البعيد |
input_injection | التحكم في قدرات حقن الإدخال |
| مجموعة القواعد | الوصف |
|---|
default | أمان متوازن لتنفيذ وكيل الذكاء الاصطناعي |
strict | أقصى أمان، أقل الصلاحيات |
permissive | صديقة للتطوير، حدود مرنة |
ai-agent | محسنة لمساعدي البرمجة بالذكاء الاصطناعي |
cicd | أمان خط أنابيب CI/CD |
remote-desktop | جلسات وكيل استخدام الكمبيوتر |
panic | تجاوز طارئ يرفض الكل |