> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pi Coding Agent

> Run @mariozechner/pi-coding-agent with all 7 built-in tools wired to a Mirage workspace.

[Pi Coding Agent](https://github.com/mariozechner/pi) is a TypeScript coding agent with seven built-in tools (read, write, edit, bash, grep, find, ls). Mirage provides an extension factory that swaps Pi's host-backed operations for `Workspace` operations.

<Note>
  Node only. Pi is a CLI agent; it uses `process.cwd()`, agent directories, and other Node-only APIs.
</Note>

## Install

```bash theme={null}
pnpm add @struktoai/mirage-agents @struktoai/mirage-node @mariozechner/pi-coding-agent @mariozechner/pi-ai
```

## Usage

```ts theme={null}
import { MountMode, OpsRegistry, RAMResource, Workspace } from '@struktoai/mirage-node'
import { getModel } from '@mariozechner/pi-ai'
import {
  createAgentSession,
  DefaultResourceLoader,
  getAgentDir,
  SessionManager,
  SettingsManager,
} from '@mariozechner/pi-coding-agent'
import { buildSystemPrompt, mirageExtension } from '@struktoai/mirage-agents/pi'

const ram = new RAMResource()
const ops = new OpsRegistry()
for (const op of ram.ops()) ops.register(op)
const ws = new Workspace({ '/': ram }, { mode: MountMode.WRITE, ops })

const resourceLoader = new DefaultResourceLoader({
  cwd: process.cwd(),
  agentDir: getAgentDir(),
  settingsManager: SettingsManager.create(process.cwd(), getAgentDir()),
  systemPrompt: buildSystemPrompt({
    mountInfo: { '/': 'In-memory filesystem (read/write)' },
  }),
  extensionFactories: [mirageExtension(ws)],
  noExtensions: true,
  noSkills: true,
})
await resourceLoader.reload()

const { session } = await createAgentSession({
  model: getModel('anthropic', 'claude-sonnet-4-6'),
  resourceLoader,
  sessionManager: SessionManager.inMemory(),
})

await session.prompt("Create /hello.txt with 'hi' and ls /.")
```

## Exports

| Symbol                       | Purpose                                                                                                                         |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `mirageExtension(ws, opts?)` | Returns an `ExtensionFactory` that registers all 7 Pi tools against `ws`.                                                       |
| `mirageOperations(ws)`       | Lower-level: returns the `{ read, write, edit, bash, grep, find, ls }` operation bundle if you want to register tools manually. |
| `buildSystemPrompt`          | Generates a system prompt that describes mounted paths to the model.                                                            |

`mirageExtension` accepts `{ cwd?: string }`, defaults to `'/'`, which tells Pi the working directory inside the mounted workspace.

## Examples

* [`examples/typescript/agents/pi/ram_pi.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/pi/ram_pi.ts), RAM-only sandbox.
* [`examples/typescript/agents/pi/s3_pi.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/pi/s3_pi.ts), Pi exploring an S3 bucket through Mirage.
