Skip to content

Configuration ​

Configuration is validated with Zod when a guard is created. Invalid values throw before enforcement starts.

ts
const guard = createAgentGuard({
  workspace: process.cwd(),
  allowedPaths: ["src", "tests", "docs"],
  deniedPaths: [".env", ".env.*", "secrets/**"],
  policies: { read: "allow", write: "ask", outsideWorkspace: "deny" },
  agentPolicies: { "release-bot": { write: "deny" } },
  defaultDecision: "deny",
  approval: { timeoutMs: 30_000, defaultDecision: "deny", tokenTtlMs: 30_000 },
  audit: {
    enabled: true,
    redactSensitiveData: true,
    file: ".agent-guard/audit.jsonl",
    maxBytes: 5_000_000,
    retentionFiles: 5,
  },
  policyVersion: "1",
});

Fields ​

FieldTypeDefaultDescription
workspacestringRequiredRoot against which relative resources are resolved.
allowedPathsstring[]["."]Allowed relative subtrees or glob patterns.
deniedPathsstring[]Sensitive defaultsHigher-priority deny glob patterns.
policiesobjectSecure operation defaultsGlobal operation and outside-workspace decisions.
agentPoliciesRecord<string, object>{}Per-agent operation overrides.
defaultDecisionallow | deny | askdenyDecision for an unmatched in-workspace resource.
approvalobjectDeny after 30 secondsApproval timeout and token lifetime.
auditobjectEnabled and redactedJSONL location, redaction, rotation, and retention.
policyVersionstring"1"Version included in every audit record.

Policy precedence ​

Evaluation is deterministic:

  1. Reject invalid agent identities or unresolved paths.
  2. Apply outsideWorkspace to canonical resources outside the workspace.
  3. Apply matching deny patterns.
  4. Require the resource to match an allowed path.
  5. Apply an agent-specific operation rule.
  6. Apply the global operation rule.
  7. Use defaultDecision.

Deny patterns always override allowed paths.

Released under the MIT License.