# @capotej/pi-mise

Auto-activates [mise](https://mise.jdx.dev/) for [pi](https://github.com/mariozechner/pi-coding-agent) coding sessions.

When this pi package is installed and a `mise.toml`, `.mise.toml`, or `.tool-versions` file is detected in the project root, it automatically:

- **Trusts** the mise configuration (idempotent, safe)
- **Follows `cd`** into other repos/subdirs and trusts their configs too, so the activate hook stays quiet on directory changes
- **Re-trusts after mutation** — when the agent edits a config (`write`/`edit`) or runs `mise use`, trust is re-applied before the next command, because mise revokes trust on change
- **Prepends** a stderr-tolerant `mise activate` to every `bash` tool call, ensuring commands run with the correct tool versions and that non-fatal mise output never fails the actual command
- **Contributes** the `mise` skill for edge cases (manual install, trust, tasks)

## Installation

```bash
pi install @capotej/pi-mise
```

## How It Works

1. On **session start**, the extension checks if `mise` is available in `PATH`
2. It scans the project root for mise config files (`mise.toml`, `.mise.toml`, `.tool-versions`)
3. If a config is found, it runs `mise trust` so mise won't prompt for trust, and remembers it
4. Every subsequent `bash` tool call is prefixed with a stderr-tolerant activation:
   ```bash
   eval "$(mise activate bash 2>/dev/null)" 2>/dev/null || true && <command>
   ```
   so the LLM's commands run with mise-managed tools on `PATH`. If activation hiccups (e.g. an untrusted config somewhere), the failure is swallowed and the real command still runs
5. Before each `bash` tool call, any `cd <target>` in the command is parsed and those configs are trusted first (cached, so already-trusted dirs aren't re-checked)
6. After a config is mutated (`write`/`edit` to a config file, or `mise use`/redirection in a command), the trust cache is invalidated so the next command re-trusts
7. A notification is shown when mise is activated (or if mise is missing)

If no mise config file is found in the project root, the extension does nothing — zero overhead.

> **Note:** Auto-installing `mise` is intentionally not done — this extension runs only where mise is guaranteed present. A missing binary is reported and activation is skipped.

## Requirements

- `mise` must be installed and available in `PATH`
- A mise config file (`mise.toml`, `.mise.toml`, or `.tool-versions`) in the project root

## The `mise` Skill

This package also contributes a `mise` skill that teaches the LLM how to:

- Use `mise exec` for one-off commands
- Run mise tasks with `mise run`
- Install tools with `mise install`
- Handle trust, activation, and common pitfalls

> **Note:** When the pi-mise extension is active, mise activation is already prepended to every bash command. The skill instructs the LLM **not** to manually add `eval "$(mise activate bash)"` — it's handled automatically.

## Development

```bash
# Install dependencies
pnpm install

# Build (compile src/ -> dist/ with tsc)
pnpm build

# Test (pure parsers via node:test)
pnpm test

# Lint (CI gate)
pnpm lint
# Auto-fix lint findings
pnpm lint:fix

# Format in place
pnpm format
# Check formatting only (CI gate)
pnpm format:check
```

Tooling: TypeScript 7 (`tsc`) for compile, **oxfmt** for formatting, **oxlint** for linting. Source lives in `src/` and compiles to `dist/` (gitignored).

## License

MIT © Julio Capote
