# pi-session-slice

A [Pi](https://github.com/earendil-works/pi) extension that starts a new session
from a chosen range of the current one.

## Why

A long session can cover several unrelated topics. While working on one project,
you find a bug in another and spend a few turns investigating it. You want to
continue that investigation separately without bringing the rest of the
conversation along or explaining everything again.

Session Slice copies the part you choose into a new session, including the
replies and tool results. Your original session stays unchanged.

## Requirements

- Tested only against the latest stable release of
  [Pi](https://github.com/earendil-works/pi)

## Install

```shell
pi install npm:@sherif-fanous/pi-session-slice
```

Or try it without installing:

```shell
pi -e npm:@sherif-fanous/pi-session-slice
```

To uninstall:

```shell
pi remove npm:@sherif-fanous/pi-session-slice
```

## Usage

1. Run `/slice` when Pi has finished replying.
2. Choose the first message you want to keep.
3. Choose the first message you want to leave out, or select
   `Keep everything to the end`.

Pi opens the new session. If you chose a message to leave out, its text appears
in the editor so you can edit or send it again. Press `Esc` in either picker to
cancel without creating a session.

For example, choosing your third message as the start and your fifth as the end
keeps your third and fourth messages, along with Pi's replies and any tool
activity between them. Your fifth message goes into the editor; it is not part
of the copied conversation.

Use `/resume` to return to the original session. The new session starts without
a name; use `/name` to give it one.

### Commands

| Command  | What it does                                                                            |
| :------- | :-------------------------------------------------------------------------------------- |
| `/slice` | Opens the pickers that choose the range to copy. It needs Pi's interactive terminal UI. |

### The pickers

The start and end pickers list your messages in the current conversation. Both
use the same keys:

| Key             | Action                            |
| :-------------- | :-------------------------------- |
| `↑` / `↓`       | Move the selection                |
| `PgUp` / `PgDn` | Move one page                     |
| `Enter`         | Select the message                |
| `Esc`           | Cancel without creating a session |

If you have remapped Pi's keys, the pickers follow your bindings.

## Configuration

Session Slice has no configuration file. Each slice is a new Pi session, and
your original session stays unchanged.

## Troubleshooting

`/slice` explains in a notification when it can't run. It needs a saved session,
so it doesn't work in sessions started with `--no-session`. Wait until Pi has
finished replying, and make sure the conversation has at least one of your
messages.

## License

[MIT](LICENSE)
