> ## Documentation Index
> Fetch the complete documentation index at: https://docs.manthan.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# @parmanasystems/governance

> Policy authoring, compilation, and bundle generation

The governance package handles the full policy lifecycle - creating, compiling, signing, versioning, and validating policies.

## Install

```bash theme={null}
npm install @parmanasystems/governance
```

## Key exports

| Export           | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| `createPolicy`   | Scaffold a new policy directory with a starter `policy.json` |
| `generateBundle` | Compile and sign a policy into a content-addressed bundle    |
| `upgradePolicy`  | Create the next version of a policy                          |
| `validatePolicy` | Verify that all version bundles are valid                    |
| `compilePolicy`  | Run the 8-phase compiler against a policy directory          |
| `definePolicy`   | Construct a `PolicyDefinition` object in code                |

## Creating a policy programmatically

```typescript theme={null}
import { createPolicy, generateBundle } from "@parmanasystems/governance";

// Scaffold the policy directory
const policyDir = createPolicy("loan-approval");
// Creates: policies/loan-approval/1.0.0/policy.json

// Edit policy.json to add your rules, then generate the bundle
const result = generateBundle(
  "loan-approval",
  "1.0.0",
  policyDir,
  { privateKeyPath: "./trust/root.key" }
);

console.log(result.bundle_hash); // deterministic SHA-256 of policy content
```

## Compiling a policy

```typescript theme={null}
import { compilePolicy } from "@parmanasystems/governance";

const result = compilePolicy("./policies/loan-approval/1.0.0");

if (!result.valid) {
  console.error(result.errors);
  // e.g. ["[POL-021] No catch-all rule found"]
}
```

## Upgrading a policy

```typescript theme={null}
import { upgradePolicy } from "@parmanasystems/governance";

// Creates policies/loan-approval/1.0.1/ from 1.0.0/
const newDir = upgradePolicy("loan-approval");
```

## Validating all versions

```typescript theme={null}
import { validatePolicy } from "@parmanasystems/governance";

const valid = validatePolicy("loan-approval", "./trust/root.pub");
// Returns true only when all version bundles are signed and their manifests are intact
```

## Defining a policy in code

```typescript theme={null}
import { definePolicy } from "@parmanasystems/governance";

const policy = definePolicy({
  policyId:      "payment-approval",
  policyVersion: "1.0.0",
  schemaVersion: "1.0.0",
  signalsSchema: {
    amount:   { type: "integer" },
    verified: { type: "boolean" },
  },
  rules: [
    {
      id:        "approve-standard",
      condition: "amount < 10000 && verified == true",
      action:    "approve",
    },
  ],
});
```

## See also

* [Write Your First Policy](/guides/first-policy) - step-by-step CLI and API walkthrough
* [Policy Versioning](/guides/policy-versioning) - safe update strategy
* [Policy Schema Reference](/reference/policy-schema) - complete field reference
