Skip to content

Process Guard Reference

Purpose: Reference document: Process Guard Reference Detail Level: Full reference


Configure Process Guard as a pre-commit hook using Husky.

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-process --staged
{
"scripts": {
"lint:process": "lint-process --staged",
"lint:process:ci": "lint-process --all --strict"
}
}

Use Process Guard programmatically for custom validation workflows.

import {
deriveProcessState,
detectStagedChanges,
validateChanges,
hasErrors,
summarizeResult,
} from '@libar-dev/delivery-process/lint';
// 1. Derive state from annotations
const state = (await deriveProcessState({ baseDir: '.' })).value;
// 2. Detect changes
const changes = detectStagedChanges('.').value;
// 3. Validate
const { result } = validateChanges({
state,
changes,
options: { strict: false, ignoreSession: false },
});
// 4. Handle results
if (hasErrors(result)) {
console.log(summarizeResult(result));
process.exit(1);
}
CategoryFunctionDescription
StatederiveProcessState(cfg)Build state from file annotations
ChangesdetectStagedChanges(dir)Parse staged git diff
ChangesdetectBranchChanges(dir)Parse all changes vs main
ValidatevalidateChanges(input)Run all validation rules
ResultshasErrors(result)Check for blocking errors
ResultssummarizeResult(result)Human-readable summary

Process Guard uses the Decider pattern: pure functions with no I/O.

graph LR
    A[deriveProcessState] --> C[validateChanges]
    B[detectChanges] --> C
    C --> D[ValidationResult]

ProcessGuardDecider - Pure Validation Logic

Section titled “ProcessGuardDecider - Pure Validation Logic”

Pure function that validates changes against process rules. Follows the Decider pattern from platform-core: no I/O, no side effects.

  • When validating proposed changes against delivery process rules
  • When implementing custom validation rules for the process guard
  • When building pre-commit hooks that enforce FSM transitions
  • Pure Function: (state, changes, options) => result
  • No I/O: All data passed in, no file reads
  • Composable Rules: Rules are separate functions combined in decider
  • Testable: Easy to unit test with mock data
  1. Protection Level - Completed files require unlock-reason
  2. Status Transition - Transitions must follow PDR-005 FSM
  3. Scope Creep - Active specs cannot add new deliverables
  4. Session Scope - Modifications outside session scope warn

Error Guide Content (convention: process-guard-errors)

Section titled “Error Guide Content (convention: process-guard-errors)”

Invariant: Completed specs are immutable without an explicit unlock reason. The unlock reason must be at least 10 characters and cannot be a placeholder.

Rationale: The completed status represents verified, accepted work. Allowing silent modification undermines the terminal-state guarantee. Requiring an unlock reason creates an audit trail and forces the developer to justify why completed work needs revisiting.

SituationSolutionExample
Fix typo in completed specAdd unlock reason tag@libar-docs-unlock-reason:Fix-typo-in-FSM-diagram
Spec needs reworkCreate new spec insteadNew feature file with roadmap status
Legacy importMultiple transitions in one commitSet roadmap then completed

Invariant: Status transitions must follow the PDR-005 FSM path. The only valid paths are: roadmap to active, roadmap to deferred, active to completed, active to roadmap, deferred to roadmap.

Rationale: The FSM enforces a deliberate progression through planning, implementation, and completion. Skipping states (e.g., roadmap to completed) means work was never tracked as active, breaking session scoping and deliverable validation.

AttemptedWhy InvalidValid Path
roadmap to completedMust go through activeroadmap to active to completed
deferred to activeMust return to roadmap firstdeferred to roadmap to active
deferred to completedCannot skip two statesdeferred to roadmap to active to completed

Invariant: Active specs cannot add new deliverables. Scope is locked when status transitions to active.

Rationale: Prevents scope creep during implementation. Plan fully before starting; implement what was planned. Adding deliverables mid- implementation signals inadequate planning and risks incomplete work.

SituationSolutionExample
Need new deliverableRevert to roadmap firstChange status to roadmap, add deliverable, then back to active
Discovered work during implementationCreate new specNew feature file for the discovered work

Invariant: Files outside the active session scope trigger warnings to prevent accidental cross-session modifications.

Rationale: Session scoping ensures focused work. Modifying files outside the session scope often indicates scope creep or working on the wrong task. The warning is informational (not blocking) to allow intentional cross-scope changes with --ignore-session.


Invariant: Files explicitly excluded from a session cannot be modified in that session. This is a hard error, not a warning.

Rationale: Explicit exclusion is a deliberate decision to protect certain files from modification during a session. Unlike session-scope (warning), exclusion represents a conscious boundary that should not be violated without changing the session configuration.


Invariant: Removing a deliverable from an active spec triggers a warning to ensure the removal is intentional and documented.

Rationale: Deliverable removal during active implementation may indicate descoping or completion elsewhere. The warning ensures visibility — the commit message should document why the deliverable was removed.