# Terminal

URL: https://cogitator.app/docs/channels/terminal

> Chat with your assistant from the local terminal.

## Overview

`TerminalChannel` is a readline-based REPL channel. `cogitator up` adds it automatically so the owner can talk to the assistant from the machine it runs on. It is only active when stdin is a TTY (or `COGITATOR_FORCE_TERMINAL` is set), so it stays silent under systemd/launchd.

## Usage

```typescript
import { Gateway, terminalChannel } from '@cogitator-ai/channels';

const gateway = new Gateway({
  agent,
  cogitator,
  channels: [
    terminalChannel({
      userName: 'Alice',
      userId: 'owner', // default
      prompt: '> ',
      onExit: () => shutdown(),
    }),
  ],
});
```

## Configuration

```typescript
interface TerminalConfig {
  userName?: string; // default: OS user name
  userId?: string; // default: 'owner'
  prompt?: string; // default: '> '
  onExit?: () => void; // default: raise SIGINT
}
```

## Behavior

* Messages arrive with `channelType: 'terminal'` and `channelId: 'terminal'`.
* Streaming edits rewrite the previous output in place (wrapped lines are accounted for).
* Messages that arrive while you are typing (e.g. scheduled reminders) are printed above the prompt and your input line is redrawn.
* The prompt returns after every answer, including when the agent fails.
* **Ctrl+C**, **Ctrl+D**, `/quit`, `/exit` and `exit` call `onExit`. The default raises `SIGINT`, so your process' signal handler (for example `cogitator up`'s graceful shutdown) runs; `gateway.stop()` closes readline without exiting the process.
* `RuntimeBuilder` treats the terminal user as an owner for self-configuration tools, and takes `userName` from a personality line like `assistant for Alex`.
* `sendFile` prints `[filename] url`; there is no typing indicator.
