# Development

Selesai is a fork of [Pi](https://github.com/earendil-works/pi). This page covers working on Selesai itself.

## Setup

```bash
git clone https://github.com/SelesaiInTech/selesai-code.git
cd selesai-code
npm ci --ignore-scripts
npm run build
```

`npm ci --ignore-scripts` does not run the build, so run `npm run build` before tests that use `dist/` (the ACP and packaged-loading tests do).

Run from source:

```bash
npm run dev          # interactive, from src/ through tsx
npm run dev:print    # print mode
node dist/cli.js     # the built CLI
```

The CLI keeps the caller's current working directory.

## Branding

`package.json` sets the app name and config directory:

```json
{
  "piConfig": {
    "name": "selesai",
    "configDir": ".selesai"
  }
}
```

They determine the CLI banner, `~/.selesai/agent/`, project `.selesai/`, and the app-derived environment variables `SELESAI_CODING_AGENT_DIR` and `SELESAI_CODING_AGENT_SESSION_DIR`. Other `PI_*` runtime variables keep their upstream names.

## Path Resolution

Three execution modes: npm install, standalone binary, tsx from source.

**Always use `src/config.ts`** for package assets:

```typescript
import { getBundledSkillsDir, getPackageDir } from "./config.js";
```

Never use `__dirname` directly for package assets.

## Debug Command

`/debug` (hidden) writes to `~/.selesai/agent/selesai-debug.log`:
- Rendered TUI lines with ANSI codes
- Last messages sent to the LLM

## Testing

```bash
npx tsgo -p tsconfig.build.json --noEmit   # typecheck (src/extensions is checked separately)
npm test                                   # all suites
npx vitest run test/specific.test.ts       # one file
bash scripts/verify-deltas.sh              # fork deltas that upstream syncs must keep
```

`npm test` runs an explicit file list. Add new test files to both the `test` and `test:coverage` scripts in `package.json`.

## Docs

`docs/` is synced from upstream Pi. After a docs sync, run `python3 scripts/brand-docs.py` to rename Pi paths, commands and product wording to Selesai, then `python3 scripts/brand-docs.py --check` to confirm nothing is left and anchor links resolve. The script keeps the `pi` package.json manifest key, the `pi` ExtensionAPI object, `@earendil-works/pi-*` package names and URLs.

## Project Structure

```
src/
  core/         # Agent session, tools, resources, package manager
  modes/        # interactive TUI, print, RPC and ACP modes
  extensions/   # bundled extensions (copied to dist/extensions/)
  skills/       # bundled skills (copied to dist/skills/)
test/           # vitest suites
docs/           # guides (synced from upstream, rebranded)
doc-web/        # documentation site
scripts/        # build, verification and maintenance scripts
```

The upstream runtime packages (`@earendil-works/pi-ai`, `pi-agent-core`, `pi-tui`) are npm dependencies, not part of this repository.
