# How PAI Algorithm v1.4.0 Extracts Constraints from Source Material

> Discover how PAI Algorithm v1.4.0 extracts constraints by adding a sub-step to OBSERVE, scanning source material for four classes, and saving them verbatim in IdealState.

- Repository: [Daniel Miessler 🛡️/Personal_AI_Infrastructure](https://github.com/danielmiessler/personal_ai_infrastructure)
- Tags: internals
- Published: 2026-02-16

---

**PAI Algorithm v1.4.0 extracts constraints by injecting a dedicated "Constraint Extraction" sub-step into the OBSERVE phase, scanning source material for four specific constraint classes, and persisting them verbatim in the IdealState data structure.**

The `danielmiessler/Personal_AI_Infrastructure` repository implements this mechanical constraint extraction to prevent drift during the AI-assisted development workflow. By capturing quantitative limits, prohibitions, requirements, and implicit domain conventions directly from the Product Requirements Document (PRD), the algorithm creates an immutable audit trail that downstream phases reference for verification.

## The Four Constraint Classes

PAI Algorithm v1.4.0 directs the LLM to scan source material systematically for four distinct constraint categories. This classification ensures comprehensive coverage of both explicit directives and subtle domain assumptions.

### Quantitative Constraints

The algorithm prioritizes **quantitative constraints**—explicit numbers, percentages, limits, and ranges that define hard boundaries. The prompt instructs the LLM to preserve these values verbatim, warning that paraphrasing numbers or thresholds will break subsequent verification steps.

### Prohibitions and Requirements

**Prohibitions** capture statements of what must not happen (e.g., "don't", "must not", "avoid"), while **requirements** capture mandatory actions (e.g., "must", "shall", "required"). The algorithm treats these as binary constraint types that directly influence the verification logic in later phases.

### Implicit Constraints

**Implicit constraints** represent domain conventions or assumed norms not explicitly stated in the PRD. The algorithm prompts the LLM to infer these patterns and document them with accompanying reasoning, ensuring tacit knowledge becomes explicit and verifiable.

## Technical Implementation in the OBSERVE Phase

The constraint extraction logic resides in [`Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts) (lines 101-140). This file contains the markdown specification that drives the **CONSTRAINT EXTRACTION** sub-step within the broader OBSERVE phase.

### Prompt Architecture

The algorithm streams a second output block titled **"🔬 CONSTRAINT EXTRACTION"** immediately after the initial reverse-engineering bullets. This block contains explicit scanning instructions for the four constraint classes, formatted as a structured prompt template:

```typescript
// OUTPUT 1.5 — 🔬 CONSTRAINT EXTRACTION (v1.3.0 — scales by effort level):

/**
 * Scan the source material systematically for FOUR constraint types:
 *
 * SCAN 1 — Quantitative Constraints (numbers, percentages, limits, ranges)
 *   [EX-1: {verbatim constraint with number preserved}]
 *
 * SCAN 2 — Prohibitions (must NOT happen)
 *   [EX-N: {verbatim prohibition}]
 *
 * SCAN 3 — Requirements (must happen)
 *   [EX-N: {verbatim requirement}]
 *
 * SCAN 4 — Implicit Constraints (domain conventions, assumed norms)
 *   [EX-N: {inferred constraint with reasoning}]
 */

```

Each discovered item receives an `EX-N` identifier (e.g., EX-1, EX-2), creating a referenceable index for the verification phase.

## Persisting Constraints in IdealState

Extracted constraints are stored in the **IdealState** data structure, which serves as the persistent representation of the algorithm's goal state. The `Constraint` interface is defined in [`Releases/v2.3/.claude/hooks/lib/IdealState.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/Releases/v2.3/.claude/hooks/lib/IdealState.ts) (lines 73-77):

```typescript
export interface Constraint {
  type: 'must' | 'should' | 'could';
  description: string;
  verifiable: boolean;
}

```

### State Update Triggers

When the algorithm discovers a new constraint, it triggers a `constraint_discovered` state update. The `StateUpdateTrigger` type includes this specific event:

```typescript
export type StateUpdateTrigger = 'initial' | 'new_info' |
  'constraint_discovered' | 'phase_feedback' |
  'user_interrupt' | 'agent_finding';

```

The `appendStateUpdate` function (lines 655-667 in [`IdealState.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/IdealState.ts)) persists these constraints to the JSON-Lines state file, incrementing the version counter and ensuring immutability:

```typescript
import { appendStateUpdate } from './IdealState';

// `workDir` is the active work directory for the PRD
const newConstraint: Constraint = {
  type: 'must',
  description: "Do not exceed 15 damage on turn 1",
  verifiable: true,
};

appendStateUpdate(
  workDir,
  'constraint_discovered',
  state.current_phase || 'EXECUTE',
  { constraints: [...state.constraints, newConstraint] },
  'Extracted quantitative constraint from PRD'
);

```

Later phases such as **BUILD** and **VERIFY** reference these stored constraints via `readIdealState`, creating a closed-loop system where extracted requirements directly inform implementation and validation.

## Summary

PAI Algorithm v1.4.0 implements mechanical constraint extraction through four key mechanisms:

- **Four-class scanning** of quantitative limits, prohibitions, requirements, and implicit domain conventions during the OBSERVE phase.
- **Verbatim preservation** of constraints with `EX-N` identifiers to prevent drift during later verification.
- **IdealState persistence** using the `constraint_discovered` trigger and `appendStateUpdate` function in [`IdealState.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/IdealState.ts).
- **Immutable audit trail** that downstream BUILD and VERIFY phases reference for validation.

## Frequently Asked Questions

### What are the four constraint classes in PAI Algorithm v1.4.0?

The four constraint classes are **quantitative constraints** (numbers, ranges, percentages), **prohibitions** (what must not happen), **requirements** (what must happen), and **implicit constraints** (domain conventions not explicitly stated). The algorithm scans for these categories during the OBSERVE phase to ensure comprehensive coverage of both explicit directives and tacit assumptions.

### How does PAI Algorithm v1.4.0 prevent constraint drift during implementation?

PAI Algorithm v1.4.0 prevents drift by requiring **verbatim extraction** of constraints with unique `EX-N` identifiers (e.g., EX-1, EX-2). The prompt explicitly warns that paraphrasing numbers or thresholds will break verification. These constraints are stored immutably in the IdealState data structure via the `constraint_discovered` trigger, creating an audit trail that the VERIFY phase references to ensure implementation matches the original PRD requirements.

### Where is the constraint extraction logic implemented in the codebase?

The constraint extraction logic is implemented in [`Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/Releases/v3.0/.claude/skills/PAI/Tools/algorithm.ts) (lines 101-140), which contains the markdown prompt specification driving the **CONSTRAINT EXTRACTION** sub-step. The data persistence layer resides in [`Releases/v2.3/.claude/hooks/lib/IdealState.ts`](https://github.com/danielmiessler/Personal_AI_Infrastructure/blob/main/Releases/v2.3/.claude/hooks/lib/IdealState.ts), which defines the `Constraint` interface (lines 73-77) and the `appendStateUpdate` function (lines 655-667) used to store discovered constraints.

### What happens to extracted constraints after the OBSERVE phase?

After extraction during the OBSERVE phase, constraints are persisted to the **IdealState** data structure using the `constraint_discovered` state update trigger. The `appendStateUpdate` function appends them to a JSON-Lines state file, incrementing the version counter to maintain immutability. These stored constraints are then accessible to downstream phases—particularly **BUILD** (which uses them to guide implementation) and **VERIFY** (which checks compliance against the extracted requirements)—via the `readIdealState` function.