{"_id":"@ai-operations/ops-policy","name":"@ai-operations/ops-policy","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@ai-operations/ops-policy","version":"0.1.0","description":"Policy engine for AI Operations OS — rule evaluation, autonomy levels, budget enforcement, escalation logic","private":false,"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest","clean":"rm -rf dist"},"dependencies":{"@ai-operations/shared-types":"*"},"devDependencies":{"typescript":"^5.7.0"},"repository":{"type":"git","url":"git+https://github.com/zanderone1980/ai-operations-os.git","directory":"packages/ops-policy"},"bugs":{"url":"https://github.com/zanderone1980/ai-operations-os/issues"},"author":{"name":"Alex Pinkevich","email":"alex@zanderpinkdesign.com"},"license":"MIT","publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"keywords":["ai-ops","ai-agents","workflow","automation","safety"],"_id":"@ai-operations/ops-policy@0.1.0","gitHead":"5479e60c372e0d4d5269e3fd1f87915563e9a87d","homepage":"https://github.com/zanderone1980/ai-operations-os#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-LKiCWMBURfPfg0zbKxehTW7CSDzTgmT5KIqDMDfqaOC4ksd9v/HQ1/KuhiizKj5lAPTGc143V7aPHnssGZV2Xw==","shasum":"016c787a6cb439f0faff38ccccc022e6db814f3c","tarball":"https://registry.npmjs.org/@ai-operations/ops-policy/-/ops-policy-0.1.0.tgz","fileCount":38,"unpackedSize":125389,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEbamvDy6lGZGSd8H4wVXVJHDaN1d13muuyvUWWZdCt6AiEAw+VVI+SWy8MAtAYPhttDxDUTtcY3jBVh+VFhZu705ro="}]},"_npmUser":{"name":"alexpinkone","email":"pinkevich1980@gmail.com"},"directories":{},"maintainers":[{"name":"alexpinkone","email":"pinkevich1980@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ops-policy_0.1.0_1773153569609_0.5535240330405469"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-10T14:39:29.504Z","0.1.0":"2026-03-10T14:39:29.749Z","modified":"2026-03-10T14:39:30.000Z"},"maintainers":[{"name":"alexpinkone","email":"pinkevich1980@gmail.com"}],"description":"Policy engine for AI Operations OS — rule evaluation, autonomy levels, budget enforcement, escalation logic","homepage":"https://github.com/zanderone1980/ai-operations-os#readme","keywords":["ai-ops","ai-agents","workflow","automation","safety"],"repository":{"type":"git","url":"git+https://github.com/zanderone1980/ai-operations-os.git","directory":"packages/ops-policy"},"author":{"name":"Alex Pinkevich","email":"alex@zanderpinkdesign.com"},"bugs":{"url":"https://github.com/zanderone1980/ai-operations-os/issues"},"license":"MIT","readme":"# @ai-operations/ops-policy\n\n> Business rules, autonomy levels, escalation paths, and budget tracking for AI Operations OS.\n\nPart of [AI Operations OS](https://github.com/zanderone1980/ai-operations-os) — autonomous business workflow orchestration with safety enforcement.\n\n## Install\n\n```\nnpm install @ai-operations/ops-policy\n```\n\n## Quick Start\n\n```ts\nimport { AutonomyManager, BudgetTracker } from '@ai-operations/ops-policy';\nimport { DEFAULT_POLICY } from '@ai-operations/shared-types';\n\nconst manager = new AutonomyManager(DEFAULT_POLICY);\nconst decision = manager.canExecute('gmail', 'send', { source: 'email' });\n\nif (decision.allowed && !decision.requiresApproval) {\n  // Safe to execute autonomously\n  manager.recordAction();\n}\n```\n\n## API\n\n### `RuleEngine`\n\nEvaluates policy rules against connector operations. Rules are checked in priority order (highest first); the first matching rule wins.\n\n```ts\nconstructor(config: PolicyConfig)\nevaluate(connector: string, operation: string, context?: EvaluationContext): EvaluationResult\n```\n\n- `EvaluationContext` — `{ source?: string; intent?: string; amount?: number }`\n- `EvaluationResult` — `{ autonomy: AutonomyLevel; risk: RiskLevel; matchedRule?: PolicyRule; reason: string }`\n\n### `AutonomyManager`\n\nWraps RuleEngine with rate limiting (hourly action counts, daily spend limits). Provides the primary `canExecute` interface for the orchestration layer.\n\n```ts\nconstructor(config: PolicyConfig)\ncanExecute(connector: string, operation: string, context?: EvaluationContext): AutonomyDecision\nrecordAction(amount?: number): void\nresetCounters(): void\ngetDailySpend(): number\ngetHourlyActionCount(): number\n```\n\n- `AutonomyDecision` — `{ allowed: boolean; requiresApproval: boolean; reason: string }`\n\n### `EscalationManager`\n\nTracks denial counts per task and determines when and to whom issues should be escalated. Prevents tasks from being silently stuck in denial loops.\n\n```ts\nconstructor(config?: EscalationConfig)\nshouldEscalate(taskId: string, denialCount: number): boolean\ngetEscalationTarget(taskId: string): EscalationTarget | undefined\nrecordDenial(taskId: string): void\nrecordEscalation(taskId: string, target: EscalationTarget): void\nclearState(taskId: string): void\n```\n\n- `EscalationTarget` — `{ role: string; channel: string; urgency: 'low' | 'normal' | 'high' | 'critical' }`\n\n### `BudgetTracker`\n\nFine-grained spending management with global daily limits and per-connector breakdowns. Auto-resets at midnight.\n\n```ts\nconstructor(dailyLimit?: number, connectorLimits?: Record<string, number>)\ncanSpend(amount: number, connector: string): { allowed: boolean; reason: string }\nrecordSpend(amount: number, connector: string): void\ngetDailyTotal(): number\ngetConnectorTotal(connector: string): number\ngetBreakdown(): Record<string, number>\ngetRemainingBudget(): number\nsetConnectorLimit(connector: string, limit: number): void\n```\n\n## Related Packages\n\n- [`@ai-operations/shared-types`](../shared-types) — PolicyConfig, PolicyRule, AutonomyLevel types\n- [`@ai-operations/ops-core`](../ops-core) — Workflow engine that checks policy before execution\n- [`@ai-operations/cord-adapter`](../cord-adapter) — CORD safety evaluation layer\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-8e02cc242b4a8a06cc817b110e88f9ac"}