# pi-repeat-tool-guard

Reduce repeated tool calls in Pi.

`pi-repeat-tool-guard` is a Pi package for people who see the model repeatedly
calling the same tool with the same arguments. It keeps your normal Pi workflow
unchanged, but gives the model a clear reminder when it appears to be stuck in
that loop.

Use it when you want Pi to:

- notice repeated read/search/shell-style calls,
- reconsider the latest tool output before trying again,
- choose a different approach instead of burning turns on the same call.

## Install

Install it globally for your Pi user:

```bash
pi install npm:pi-repeat-tool-guard
```

Install it only for the current project:

```bash
pi install npm:pi-repeat-tool-guard -l
```

If you are installing from the GitHub repository instead of npm:

```bash
pi install git:git@github.com:Kingwl/pi-repeat-tool-guard
```

## Use

After installation, start Pi normally:

```bash
pi
```

Pi loads installed packages automatically. You can confirm the package is active
from Pi's startup header or by running:

```bash
pi list
```

## Configuration

The default behavior works without configuration. By default, the package starts
reminding the model after repeated identical calls at counts `3`, `5`, and `8`.

You can adjust the repeat counts:

```bash
PI_REPEAT_TOOL_GUARD_THRESHOLDS=3,5,8 pi
```

Track only selected tools:

```bash
PI_REPEAT_TOOL_GUARD_INCLUDE=read,grep,glob pi
```

Ignore selected tools:

```bash
PI_REPEAT_TOOL_GUARD_EXCLUDE=bash,write,edit pi
```

`*` can be used as a wildcard in include/exclude values:

```bash
PI_REPEAT_TOOL_GUARD_INCLUDE='mcp__*,read,grep' pi
```

## Managing The Package

Update installed Pi packages:

```bash
pi update --extensions
```

Disable, enable, or inspect installed extensions:

```bash
pi config
```

Remove the package:

```bash
pi remove npm:pi-repeat-tool-guard
```

## Notes

This package does not reject tool calls and does not ask for extra user
confirmation. The tool still runs normally; the model simply receives an extra
reminder when it repeats itself.

It is designed as a lightweight Pi extension that you can install, keep enabled,
and forget about until a repeated-tool loop shows up.

## Reference

This package is inspired by Kimi Code's repeated tool-call protection:

- [`packages/agent-core/src/agent/turn/tool-dedup.ts`](https://github.com/MoonshotAI/kimi-code/blob/75a894e9ad5e8d49509664b3daaa1bbc9bb39432/packages/agent-core/src/agent/turn/tool-dedup.ts)
- [`packages/agent-core/src/agent/turn/index.ts`](https://github.com/MoonshotAI/kimi-code/blob/75a894e9ad5e8d49509664b3daaa1bbc9bb39432/packages/agent-core/src/agent/turn/index.ts)
