![ChatHaikuCLI preview](assets/banner.png)

# ChatHaikuCLI — Windows Native Edition

A dependency-free Windows command-line interface for chatting with RootComputer models.

This edition is the **"Can't believe it's not Python"** port of the original ChatHaikuCLI Python clients. It keeps the same terminal workflow, endpoint behavior, slash commands, sampling controls, retry tools, and JSONL feedback collection, but runs with only tools already included on modern Windows.

No Python. No Node. No pip. No installer.

---

## What changed in this port

The original project shipped two Python scripts:

- `chathaiku.py`
- `chathaiku_dev.py`

This Windows-native port replaces them with PowerShell clients and Batch launchers:

| File | Purpose |
|---|---|
| `chathaiku.bat` | Easiest way to launch the public client from Command Prompt, PowerShell, Windows Terminal, or double-click. |
| `chathaiku.ps1` | Public PowerShell client. Mirrors the original everyday chat client. |
| `chathaiku_dev.bat` | Easiest way to launch the developer client. |
| `chathaiku_dev.ps1` | Developer PowerShell client. Mirrors endpoint switching, sampling controls, retry/undo, health checks, latency stats, and JSONL preference collection. |
| `assets/banner.png` | README banner image. |
| `LICENSE` | MIT license. |

The `.bat` files are thin launchers. The actual application logic lives in the `.ps1` files.

---

## Requirements

ChatHaikuCLI Windows Native requires only:

- Windows 10 or newer, or any modern Windows machine with PowerShell
- Windows PowerShell 5.1 or PowerShell 7+
- An internet connection when using the public endpoint
- A reachable RootComputer-compatible server when using a custom endpoint

Windows PowerShell 5.1 is included with modern Windows by default.

No package installation is required.

---

## Quick start

Download or clone the repo, open the folder, then run:

```bat
chathaiku.bat
```

You should see the ChatHaiku banner and the prompt:

```text
you:
```

Type a message and press Enter.

Exit with:

```text
/quit
```

---

## Running from PowerShell

From PowerShell:

```powershell
.\chathaiku.bat
```

or run the script directly:

```powershell
powershell -ExecutionPolicy Bypass -File .\chathaiku.ps1
```

The Batch wrapper already uses `-ExecutionPolicy Bypass` for that one launch, so most users should use the `.bat` files.

---

## Running the public client

The public client is the normal user-facing CLI.

```bat
chathaiku.bat
```

Run with a custom server or endpoint:

```bat
chathaiku.bat --server https://chathaiku.com/api/haiku.php
```

Disable colored output:

```bat
chathaiku.bat --no-color
```

The PowerShell equivalent is:

```powershell
.\chathaiku.ps1 -Server https://chathaiku.com/api/haiku.php -NoColor
```

---

## Running the developer client

The developer client is for model testing, prompt evaluation, endpoint development, and local preference-data collection.

```bat
chathaiku_dev.bat
```

Run against the public endpoint:

```bat
chathaiku_dev.bat --server https://chathaiku.com/api/haiku.php
```

Run against a local server base URL:

```bat
chathaiku_dev.bat --server http://localhost:8000
```

Run against a direct chat route:

```bat
chathaiku_dev.bat --server http://localhost:8000/api/chat
```

Write collected preference data to custom files:

```bat
chathaiku_dev.bat --dpo-out data\my_dpo_pairs.jsonl --sft-positive-out data\my_sft_positive.jsonl
```

Disable colors:

```bat
chathaiku_dev.bat --no-color
```

---

## Default endpoint

Both clients default to:

```text
https://chathaiku.com/api/haiku.php
```

That endpoint is treated as a direct public PHP proxy. It does not expose a health route, so the clients do not mark it offline just because `/api/health` is unavailable. The first chat request performs the real test.

---

## Supported endpoint formats

Both clients accept `--server`.

The value can be:

1. a public PHP proxy endpoint,
2. a direct `/api/chat` endpoint,
3. a base server URL,
4. a pasted `/api/health` URL, or
5. a relative `/api/...` path for the public ChatHaiku site.

Examples:

```bat
chathaiku.bat --server https://chathaiku.com/api/haiku.php
chathaiku.bat --server http://localhost:8000
chathaiku.bat --server http://localhost:8000/api/chat
chathaiku.bat --server http://localhost:8000/api/health
chathaiku.bat --server /api/haiku.php
```

If you provide a server without a URL scheme, the client adds one automatically:

- local/private hosts use `http://`
- public hosts use `https://`

Example:

```bat
chathaiku.bat --server localhost:8000
```

is treated as:

```text
http://localhost:8000
```

---

## Public client commands

| Command | Description |
|---|---|
| `/clear` | Clear the current conversation history. |
| `/save FILE` | Save the conversation transcript to a text file. |
| `/help` | Show command help. |
| `/quit` | Exit the client. |
| `/exit` | Exit alias. |
| `/q` | Exit alias. |
| `/bye` | Exit alias. |

Example:

```text
you: /save conversation.txt
```

The saved public transcript format is:

```text
You: Hello.

Haiku: Hello. How can I help?
```

---

## Developer client commands

The developer client supports the public chat workflow plus model-testing tools.

### Conversation commands

| Command | Description |
|---|---|
| `/clear` | Reset conversation history. |
| `/history` | Show the current conversation transcript. |
| `/save FILE` | Save the transcript to a file. |
| `/retry` | Drop the last bot reply and re-ask the last user message. |
| `/undo` | Drop the last exchange. |
| `/help` | Show the full command list. |
| `/quit` | Exit the client. |
| `/exit` | Exit alias. |
| `/q` | Exit alias. |

The saved developer transcript format is:

```text
[1] you: Hello.
[2] haiku: Hello. How can I help?
```

### Server commands

| Command | Description |
|---|---|
| `/endpoint URL` | Switch to a new endpoint without restarting the client. |
| `/ping` | Check endpoint health or reachability. |
| `/info` | Show the last known endpoint information. |

### Sampling commands

| Command | Description |
|---|---|
| `/temp F` | Set temperature. |
| `/top-p F` | Set nucleus sampling value. |
| `/top-k N` | Set top-k sampling value. `0` disables top-k. |
| `/max-new N` | Set maximum generated tokens per reply. |
| `/rep-penalty F` | Set repetition penalty. |
| `/no-repeat-ngram N` | Block repeated n-grams of size `N`. `0` disables this. |
| `/params` | Show the current sampling parameters. |

### Feedback collection commands

| Command | Description |
|---|---|
| `/good` | Save the last bot reply as a positive SFT example. |
| `/bad` | Mark the last bot reply as bad, enter a corrected answer, and save a DPO pair. |
| `/rewrite` | Rewrite the last bot reply and save a DPO pair. |
| `/stats` | Show collected JSONL counts for this session and on disk. |
| `/dpo-stats` | Alias for `/stats`. |

---

## Sampling controls

The public client sends a fixed sampling payload with each request:

```json
{
  "temperature": 0.85,
  "top_p": 0.92,
  "max_new_tokens": 200
}
```

The developer client sends configurable sampling values.

Current developer defaults:

```json
{
  "temperature": 0.35,
  "top_p": 0.37,
  "top_k": 0,
  "max_new_tokens": 80,
  "repetition_penalty": 1.15,
  "no_repeat_ngram": 4
}
```

Inspect the current values during a developer session:

```text
/params
```

Change values:

```text
/temp 0.7
/top-p 0.9
/top-k 40
/max-new 200
/rep-penalty 1.15
/no-repeat-ngram 4
```

---

## Collecting SFT and DPO data

The developer client can collect local JSONL data while you evaluate the model.

By default, it writes:

```text
data\dpo_pairs.jsonl
data\sft_positive.jsonl
```

The `data\` folder is created automatically when needed.

### Positive SFT examples with `/good`

After a good model reply:

```text
/good
```

The client appends one JSON object to `data\sft_positive.jsonl`:

```json
{
  "prompt": "User message that caused the reply",
  "chosen": "The model reply marked as good",
  "history": [],
  "server": "https://chathaiku.com/api/haiku.php",
  "model": "Haiku public PHP proxy",
  "ts": "2026-01-01T12:00:00"
}
```

### DPO pairs with `/bad`

After a bad model reply:

```text
/bad
```

The client asks what the reply should have been. Enter the corrected reply, then finish with:

```text
/end
```

Cancel with:

```text
/cancel
```

The client appends one JSON object to `data\dpo_pairs.jsonl`:

```json
{
  "prompt": "User message that caused the reply",
  "chosen": "Your corrected reply",
  "rejected": "The model's original bad reply",
  "history": [],
  "source": "bad",
  "server": "https://chathaiku.com/api/haiku.php",
  "model": "Haiku public PHP proxy",
  "ts": "2026-01-01T12:00:00"
}
```

### DPO pairs with `/rewrite`

Use `/rewrite` when the model answer is not necessarily bad, but you want to provide a better preferred answer.

```text
/rewrite
```

The saved JSONL object uses:

```json
"source": "rewrite"
```

---

## Expected server API

ChatHaikuCLI expects a RootComputer-compatible HTTP API.

### Chat route

For a server base URL, the chat route should be:

```text
/api/chat
```

The route accepts `POST` requests with JSON.

Example request:

```json
{
  "history": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "temperature": 0.85,
  "top_p": 0.92,
  "max_new_tokens": 200
}
```

The developer client may also send:

```json
{
  "top_k": 0,
  "repetition_penalty": 1.15,
  "no_repeat_ngram": 4
}
```

Expected response:

```json
{
  "reply": "Hello. How can I help?"
}
```

If the response contains an `error` field and no usable `reply`, the developer client reports it as a server error.

### Health route

For self-hosted servers, the optional health route is:

```text
/api/health
```

Expected response:

```json
{
  "model": "Haiku",
  "params": 217000000,
  "device": "cuda"
}
```

The clients can still use a direct PHP proxy or direct chat route without a health route.

---

## Endpoint fallback behavior

The original Python clients included a fallback for public PHP proxy requests that receive HTTP `412` from shared-host security rules.

This Windows-native port keeps that behavior.

When the active endpoint is a PHP proxy and it returns `412`, the clients retry the same chat request against:

```text
http://haiku.rootcomputer.dev/api/chat
```

If the fallback also fails, the client prints the fallback error.

---

## Color output

Both clients use `Write-Host` foreground colors instead of ANSI escape codes. That keeps the output clean in normal Windows terminals.

Disable colors with:

```bat
chathaiku.bat --no-color
chathaiku_dev.bat --no-color
```

or set the standard `NO_COLOR` environment variable before launching.

Command Prompt:

```bat
set NO_COLOR=1
chathaiku.bat
```

PowerShell:

```powershell
$env:NO_COLOR = "1"
.\chathaiku.bat
```

---

## Troubleshooting

### Double-click opens and closes instantly

Open Command Prompt or Windows Terminal in the project folder and run:

```bat
chathaiku.bat
```

That keeps the terminal open so you can read any error.

### PowerShell says script execution is disabled

Use the Batch launcher:

```bat
chathaiku.bat
```

The launcher runs PowerShell with:

```text
-ExecutionPolicy Bypass
```

for that one invocation only.

### The client says the server is offline

Check that:

- the endpoint is typed correctly,
- your internet connection is working,
- the public endpoint is currently online,
- your local server is actually running if using `localhost`,
- the server exposes `/api/chat` if using a base URL.

Try the developer client:

```bat
chathaiku_dev.bat --server YOUR_ENDPOINT
```

Then run:

```text
/ping
```

### Public endpoint has no health route

This is expected for PHP proxy endpoints such as:

```text
https://chathaiku.com/api/haiku.php
```

The client will say no health endpoint is exposed and will test the endpoint on the first chat request.

### HTTP 412 from the public PHP endpoint

Some shared-host or WAF setups can block command-line POST requests to a public PHP proxy. The clients include a backend fallback for this case. If both the public endpoint and fallback fail, the client prints the fallback error.

### Server returns invalid JSON

The endpoint did not return valid JSON. Common causes:

- the URL points to an HTML page instead of `/api/chat`,
- the server crashed and returned an error page,
- a proxy or firewall injected an HTML response,
- the server route is not RootComputer-compatible.

### Server returned an empty reply

The server responded, but the `reply` field was missing or empty.

Confirm the response format is:

```json
{
  "reply": "text here"
}
```

### Conversation history gets too long

The public client sends the full in-memory conversation history.

The developer client sends only the most recent 10 turns to match the public frontend behavior.

Use:

```text
/clear
```

to reset the session.

---

## Security notes

ChatHaikuCLI sends your conversation text to the configured server endpoint.

When using the public endpoint, do not send secrets, passwords, private keys, or sensitive personal data. When using a self-hosted endpoint, review your own server logging and retention behavior.

The developer client writes feedback data locally to JSONL files. Review those files before sharing them or using them for model training.

---

## License

MIT License
