How ravaniroshan/policyctl works
Purpose and entry points
policyctl is a local-first, provider-agnostic policy runtime for coding-agent tool calls and CI diffs, with an optional hosted policy/audit control plane. Main local entry point is the npm CLI at packages/cli/src/cli.ts; its reusable evaluation engine is exported from packages/core/src/index.ts. The hosted Worker starts at packages/server/src/index.ts, while the dashboard SPA starts at web/src/main.tsx and routes from web/src/App.tsx.
Policy engine
@policyctl/core defines the policy schema, loads YAML policy files, and deterministically evaluates rules against hook or CI inputs. Rules combine path, tool/command, and diff matchers; outcomes distinguish blocking, failing, warning, and allow behavior. This package is the shared enforcement boundary: CLI/provider adapters should translate external inputs into core types rather than reimplement matching.
Paths: packages/core/src/types.ts, packages/core/src/load.ts, packages/core/src/evaluate.ts, packages/core/src/matchers.ts.
CLI orchestration and local enforcement
The TypeScript CLI owns repository interaction, stdin/tool-hook handling, user-facing output, and command dispatch. eval is the pre-tool execution path used by generated hooks; check is the CI path that evaluates git changes, including untracked files. init, list, test, trace, and doctor support policy lifecycle and diagnostics.
Paths: packages/cli/src/cli.ts, packages/cli/src/commands/eval.ts, packages/cli/src/commands/check.ts, packages/cli/src/git.ts.
Provider adapter generation
gen converts one repository policy into provider-specific integration artifacts rather than embedding provider logic in the engine. Adapters target Claude settings/hooks, Codex execution policy, Cursor hooks, and a pre-commit/CI-oriented gate; templates and adapter definitions form the provider boundary.
Paths: packages/cli/src/commands/gen.ts, packages/cli/src/adapters.ts, packages/cli/src/templates.ts.
The sample repository demonstrates generated Claude/Codex configuration and a CI workflow: examples/demo/.claude/settings.json, examples/demo/.codex/hooks/hooks.json, examples/demo/.github/workflows/policy.yml.
Hosted policy and reporting flow
Authenticated CLI clients can publish immutable policy versions, pull team policy, and report check results to the hosted plane. The CLI’s hosted client and policy/report commands communicate with the Worker API; local evaluation remains usable offline. The server separates request routing from storage, authentication/session management, cache access, dashboard aggregation, and AI features.
Paths: packages/cli/src/hosted.ts, packages/cli/src/commands/push.ts, packages/cli/src/commands/pull.ts, packages/cli/src/commands/report.ts; packages/server/src/index.ts, packages/server/src/store.ts, packages/server/src/auth.ts, packages/server/src/session.ts.
Cloudflare control-plane infrastructure
The hosted runtime is Cloudflare Workers, configured through packages/server/wrangler.toml. Cloudflare D1/SQLite persists organizations, actors, authentication data, policy versions, and audit/feed records, initialized by migrations. KV caches policy/session lookups; R2 supports CSV exports; Workers AI is exposed through a dedicated server module and is intended for paid semantic-policy functionality. Auth uses session cookies and Turnstile according to the project design.
Paths: packages/server/wrangler.toml, packages/server/migrations/0001_init.sql, packages/server/migrations/0002_actor.sql, packages/server/migrations/0003_auth.sql, packages/server/src/cache.ts, packages/server/src/ai.ts.
Dashboard client
The dashboard is a React/Tailwind SPA consuming the Worker API through an API client and auth context. It presents policy versions, reports, sessions, settings, and AI-related views; dashboard layout is shared separately from page content.
Paths: web/src/lib/api.ts, web/src/lib/auth.tsx, web/src/components/layout/DashboardShell.tsx, web/src/pages/dashboard/Policies.tsx, web/src/pages/dashboard/Reports.tsx, web/src/pages/dashboard/Sessions.tsx.
Main entry points: src/index.ts Worker API · src/index.ts Policy engine · cli.ts policyctl CLI · check.ts CI change check
Components 21
Local runtime
Offline policy authoring and enforcement.
- policyctl CLI · Command dispatch, hooks, repository interaction, and output.
packages/cli/src/cli.ts - Hook evaluation · Pre-tool execution evaluation path.
packages/cli/src/commands/eval.ts - CI change check · Evaluates tracked and untracked git changes.
packages/cli/src/commands/check.ts - Git change reader
packages/cli/src/git.ts - Policy engine · Shared deterministic enforcement boundary.
packages/core/src/index.ts - Policy schema
packages/core/src/types.ts - YAML policy loader
packages/core/src/load.ts - Rule evaluator · Produces block, fail, warn, or allow outcomes.
packages/core/src/evaluate.ts - Rule matchers · Matches paths, tools, commands, and diffs.
packages/core/src/matchers.ts - Hosted client · Used by policy publication, pull, and result reporting commands.
packages/cli/src/hosted.ts
Provider integrations
Generated agent and CI artifacts.
- Integration generator · Turns repository policy into provider artifacts.
packages/cli/src/commands/gen.ts - Provider adapters
packages/cli/src/adapters.ts - Provider templates
packages/cli/src/templates.ts
Hosted control plane
Cloudflare-hosted policy, audit, and auth services.
- Worker API · Routes authenticated control-plane requests.
packages/server/src/index.ts - Control-plane store · Persists policy versions and audit records.
packages/server/src/store.ts - Auth and sessions · Manages authentication and session cookies.
packages/server/src/auth.ts - Policy/session cache
packages/server/src/cache.ts - D1 policy and audit data · Organizations, actors, auth, policy versions, and audit/feed records.
packages/server/migrations/0001_init.sql - Semantic policy AI · Supports paid semantic-policy functionality.
packages/server/src/ai.ts
Dashboard
React client for hosted control-plane data.
- Dashboard SPA · Policy, report, session, settings, and AI views.
web/src/App.tsx - Dashboard API client
web/src/lib/api.ts
Connections 22
- policyctl CLI → Hook evaluation: dispatches
- policyctl CLI → CI change check: dispatches
- Hook evaluation → Policy engine: evaluates inputs
- CI change check → Git change reader: reads changes
- CI change check → Policy engine: evaluates diff
- Policy engine → Policy schema: exports
- Policy engine → YAML policy loader: loads policy
- Policy engine → Rule evaluator: evaluates rules
- Rule evaluator → Rule matchers: uses
- policyctl CLI → Integration generator: dispatches gen
- Integration generator → Policy engine: uses policy schema
- Integration generator → Provider adapters: selects
- Provider adapters → Provider templates: renders
- policyctl CLI → Hosted client: pushes, pulls, reports
- Hosted client → Worker API: authenticated API calls
- Worker API → Auth and sessions: authenticates
- Worker API → Control-plane store: reads and writes
- Worker API → Policy/session cache: caches lookups
- Control-plane store → D1 policy and audit data: persists
- Worker API → Semantic policy AI: invokes
- Dashboard SPA → Dashboard API client: uses
- Dashboard API client → Worker API: consumes API