hookset
API reference

hookset

Every export of hookset, with its signature and doc comment: packageRoot, loadStations, packageVersion, parseRemotes, localRuns, duplicateOf and 5 more, plus 10 types.

import { packageRoot, loadStations, packageVersion, … } from 'hookset';

Functions

checkRepo

Everything hookset check reports for the repo at repo, against the presets in pkg.

function checkRepo(repo: string, pkg: string): CheckResult;
ParameterType
repostring
pkgstring

Returns CheckResult

checkText

The text a person reads for a check result.

function checkText(result: CheckResult): string;
ParameterType
resultCheckResult

Returns string

duplicateOf

True when a hand-written step repeats what a preset station already runs.

function duplicateOf(run: Run, stations: Station[]): Station | undefined;
ParameterType
runRun
stationsStation[]

Returns Station \| undefined

expectedClaudeHooks

The pack's hooks, with stop-after-3 also on PostToolUseFailure (a failed Bash call lands there).

function expectedClaudeHooks(stations: Stations): ClaudeHook[];
ParameterType
stationsStations

Returns ClaudeHook[]

initRepo

Write or update the hookset wiring in repo. A lefthook.yml hookset did not write is refused unless force, which puts the remotes block on top and keeps every hand-written step (check then names the duplicates to delete). claude also vendors the Claude pack.

function initRepo(repo: string, pkg: string, options?: {
    force?: boolean;
    claude?: boolean;
}): InitResult;
ParameterType
repostring
pkgstring
options (optional){ force?: boolean; claude?: boolean; }

Returns InitResult

lefthookTemplate

The lefthook.yml hookset init writes into a repo with none.

function lefthookTemplate(stations: Stations, ref: string): string;
ParameterType
stationsStations
refstring

Returns string

loadStations

function loadStations(pkg: string): Stations;
ParameterType
pkgstring

Returns Stations

localRuns

Every run: a lefthook.yml declares itself, outside remotes:, with its hook and command.

function localRuns(yaml: string): Run[];
ParameterType
yamlstring

Returns Run[]

packageRoot

The package root: the folder holding stations.json, presets/ and claude/.

function packageRoot(from?: string): string;
ParameterType
from (optional)string

Returns string

packageVersion

function packageVersion(pkg: string): string;
ParameterType
pkgstring

Returns string

parseRemotes

The remotes: entries of a lefthook.yml. Read line by line: hookset writes this block itself, and a full YAML parser would be this package's only dependency. A remote starts at a list item whose first word is one of its keys; a configs entry is a list item that is a path.

function parseRemotes(yaml: string): Remote[];
ParameterType
yamlstring

Returns Remote[]

Interfaces

CheckResult

interface CheckResult {
    ok: boolean;
    /** The `hookset@…` tag the repo pins, when it pins one. */
    pinned: string | undefined;
    expected: string;
    problems: Problem[];
}

ClaudeHook

interface ClaudeHook {
    event: string;
    matcher: string;
    file: string;
}

InitResult

interface InitResult {
    changed: boolean;
    written: string[];
    refused?: string;
}

Problem

interface Problem {
    id: string;
    severity: 'error' | 'warning';
    message: string;
    fix: string;
}

Remote

interface Remote {
    gitUrl: string;
    ref: string | undefined;
    configs: string[];
}

Run

interface Run {
    hook: string;
    command: string;
    run: string;
}

Station

interface Station {
    id: string;
    hook: Hook;
    mode: Mode;
    /** The command name the preset gives this station's step. */
    command: string;
    /** The repo script the step runs, when the repo decides what the station does. */
    script?: string;
    detail: string;
}

Stations

interface Stations {
    remote: string;
    tagPrefix: string;
    presets: Record<Hook, string>;
    stations: Station[];
    claude: {
        files: string[];
        hooks: ClaudeHook[];
    };
}

Types

Hook

type Hook = 'commit-msg' | 'pre-commit' | 'pre-push';

Mode

type Mode = 'enforce' | 'optional' | 'observe';

On this page