# pi-cc-style-tools

Claude Code-style rendering for the [Pi coding agent](https://pi.dev)'s built-in
`read` / `bash` / `write` / `edit` tools.

**Rendering only.** Every override delegates `execute()` to the original tool,
so behavior, permissions, hooks and command rewriting (e.g. RTK) are untouched.
No file I/O happens in any renderer, so streaming and expansion stay smooth.

```text
● Bash(pnpm build)
  ⎿ done (12 lines)
    line1
    line2
    … +10 more (ctrl+o to expand)

● Read(src/index.ts)
  ⎿ Read 52 lines

● Write(src/foo.ts)
  ⎿ Written

● Update(src/bar.ts)
  ⎿ Updated with +12 −3
  ⎿ 12-18
       12  const a = 1;
    -  13  const b = 2;   ← red
    +  13  const c = 2;   ← green + bold
       14  const d = 3;
  ⎿ 100-110
     …
```

Pi's `edit` tool is labeled **Update**, matching Claude Code.

## Style rules

- **Capitalized tool names** — `Bash()`, `Read()`, `Write()`, `Update()`.
- **Status dots** — gray `●` while running, green when done, red on error.
- **Assistant messages** get a leading white circle (`●`), like Claude Code.
- **Update() shows every diff hunk** — if a file has changes at lines 10-20
  *and* 100-110, both regions render as their own block. Hunks are never
  folded into a single collapsed region.
- **Deleted lines** are red; **added lines** are bright green and bold for
  strong contrast; context lines are gray.
- **Only Update() shows a diff** — Bash/Read/Write never do.

## Expansion (ctrl+o)

`ctrl+o` globally collapses/expands all tool outputs (pi's built-in
`app.tools.expand` binding):

| Tool | Collapsed (default) | Expanded (ctrl+o) |
|---|---|---|
| Bash | up to 20 lines, with `… +N more (ctrl+o to expand)` hint | full output (capped at 500 lines) |
| Read | `⎿ Read N lines` | same — Read stays a one-line summary |
| Write | `⎿ Written` | same — Write stays a one-line summary |
| Update | all diff hunks (always visible) | same — hunks never fold |

## Install

From npm:

```bash
pi install npm:pi-cc-style-tools
```

Or from GitHub:

```bash
pi install git:github.com/newCman1/pi-cc-style-tools
```

Or try it without installing:

```bash
pi -e npm:pi-cc-style-tools
```

> If you previously copied `index.ts` into `~/.pi/agent/extensions/`, remove it
> first to avoid double tool registration.

## Configuration

All styling lives in the `STYLE` constant at the top of [`index.ts`](index.ts):

| Key | Default | Meaning |
|---|---|---|
| `dot` | `●` | tool-call bullet (`⬤` U+2B24 is bigger, if your font has it) |
| `dotGap` | `" "` | gap between bullet and tool name |
| `collapsedOutputLines` | `2` | output lines shown when collapsed |
| `collapsedOutputLines` | `20` | default bash preview: at most this many lines |
| `maxExpandedOutputLines` | `500` | safety cap when ctrl+o expands bash output |
| `maxHunks` | `20` | safety cap: at most this many diff hunks per Update |
| `maxDiffLineLen` | `200` | truncate over-long diff lines |
| `colors.dot` | `success` | bullet color when done |
| `colors.pendingDot` | `muted` | bullet color while running (gray) |
| `colors.errDot` | `error` | bullet color on failure (red) |

Colors use your active Pi theme tokens, so the look follows light/dark themes.

## Requirements

- Pi running in interactive (TUI) mode.
- On startup Pi shows a one-time "overriding built-in tool" notice — expected,
  since this package replaces the renderers of those tools.

## Development

```bash
npm install
npm run typecheck   # type-check index.ts
npm test            # unit tests for the assistant-message dot transformer
```

The assistant white-circle logic lives in [`markdown.ts`](markdown.ts) as a pure,
pi-independent function so it can be unit-tested without a TUI. Tests cover
message-type filtering (thinking/user untouched), the streaming code-fence
flicker fix, inline-code handling, and prefix non-accumulation.

## License

MIT — see [LICENSE](LICENSE).
