# hookset

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

Source: https://hookset.interlace.tools/docs/api

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

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

## Functions

### checkRepo

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

```ts
function checkRepo(repo: string, pkg: string): CheckResult;
```

| Parameter | Type |
| :-- | :-- |
| `repo` | `string` |
| `pkg` | `string` |

**Returns** `CheckResult`

### checkText

The text a person reads for a check result.

```ts
function checkText(result: CheckResult): string;
```

| Parameter | Type |
| :-- | :-- |
| `result` | `CheckResult` |

**Returns** `string`

### duplicateOf

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

```ts
function duplicateOf(run: Run, stations: Station[]): Station | undefined;
```

| Parameter | Type |
| :-- | :-- |
| `run` | `Run` |
| `stations` | `Station[]` |

**Returns** `Station \| undefined`

### expectedClaudeHooks

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

```ts
function expectedClaudeHooks(stations: Stations): ClaudeHook[];
```

| Parameter | Type |
| :-- | :-- |
| `stations` | `Stations` |

**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.

```ts
function initRepo(repo: string, pkg: string, options?: {
    force?: boolean;
    claude?: boolean;
}): InitResult;
```

| Parameter | Type |
| :-- | :-- |
| `repo` | `string` |
| `pkg` | `string` |
| `options` (optional) | `{ force?: boolean; claude?: boolean; }` |

**Returns** `InitResult`

### lefthookTemplate

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

```ts
function lefthookTemplate(stations: Stations, ref: string): string;
```

| Parameter | Type |
| :-- | :-- |
| `stations` | `Stations` |
| `ref` | `string` |

**Returns** `string`

### loadStations

```ts
function loadStations(pkg: string): Stations;
```

| Parameter | Type |
| :-- | :-- |
| `pkg` | `string` |

**Returns** `Stations`

### localRuns

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

```ts
function localRuns(yaml: string): Run[];
```

| Parameter | Type |
| :-- | :-- |
| `yaml` | `string` |

**Returns** `Run[]`

### packageRoot

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

```ts
function packageRoot(from?: string): string;
```

| Parameter | Type |
| :-- | :-- |
| `from` (optional) | `string` |

**Returns** `string`

### packageVersion

```ts
function packageVersion(pkg: string): string;
```

| Parameter | Type |
| :-- | :-- |
| `pkg` | `string` |

**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.

```ts
function parseRemotes(yaml: string): Remote[];
```

| Parameter | Type |
| :-- | :-- |
| `yaml` | `string` |

**Returns** `Remote[]`

## Interfaces

### CheckResult

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

### ClaudeHook

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

### InitResult

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

### Problem

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

### Remote

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

### Run

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

### Station

```ts
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

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

## Types

### Hook

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

### Mode

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