<!-- Generated by scripts/ax-docs.mts from the JSDoc in registry/ouro/ax/. Do not edit; run `pnpm run docs`. -->

# ax-problem

One error shape for every agent surface: the CLI's stderr line, its `--json` error and an MCP tool error all carry the same fields, so an agent learns one repair loop. The line mirrors Ouro HX's dev message format: `<tool>: <thing>: <what's wrong>. Fix: <exact code>.`

```sh
npx shadcn@latest add ourostack/ouro-ui/ax-problem#v1.3.10
```

It installs `lib/ouro/ax/problem.ts`. Its tests are `ax-problem-tests`. Every item runs on Node 22.18 or later as it is copied: the files import each other as `./<file>.ts`. The [Ouro AX guide](ax.md) shows how they fit together.

## Exports

### `AxError`

The error the kit's primitives throw: its message is the one line, its shape the data.

```ts
class AxError extends Error
```

### `AxErrorBody`

The error as data: its shape plus the one-line message. Outcomes, `--json` and MCP all carry this.

```ts
type AxErrorBody = AxErrorShape & { message: string };
```

### `AxErrorShape`

One error shape for every agent surface: the CLI's stderr line, its `--json` error and an MCP tool error all carry the same fields, so an agent learns one repair loop. The line mirrors Ouro HX's dev message format: `<tool>: <thing>: <what's wrong>. Fix: <exact code>.`

```ts
interface AxErrorShape {
  code: string;
  exit: number;
  thing: string;
  problem: string;
  fix: string | null;
}
```

### `commandLine`

A command line from words, each quoted only when it needs it.

```ts
function commandLine(words: readonly string[]): string
```

### `didYouMean`

The candidate an agent most likely meant: a unique prefix, or the nearest within two edits; null when none is close.

```ts
function didYouMean(word: string, candidates: readonly string[]): string | null
```

### `errorJson`

The `--json` and MCP form: `{ error: { code, exit, thing, problem, fix, message } }`.

```ts
function errorJson(shape: AxErrorShape): { error: AxErrorBody; }
```

### `errorLine`

The one stderr line: `<tool>: <thing>: <problem>. Fix: <fix>.` Line breaks in any part become spaces.

```ts
function errorLine(tool: string, shape: Pick<AxErrorShape, "fix" | "thing" | "problem">): string
```

### `errorMessage`

`<thing>: <problem>. Fix: <fix>.`, without the tool's prefix (a CLI adds its own).

```ts
function errorMessage(shape: Pick<AxErrorShape, "fix" | "thing" | "problem">): string
```

### `isAxError`

```ts
function isAxError(value: unknown): value is AxError
```

### `shellWord`

Quotes a word for a POSIX shell only when it needs it, so a fix copies and runs as printed.

```ts
function shellWord(word: string): string
```
