# current-question

[English](./README.md) | [Chinese (Simplified)](./README.zh-CN.md)

> A [pi coding agent](https://pi.dev) extension that pins your recent questions above the editor — navigate, expand, copy, and reply with context.

`current-question` is a pi extension that pins the last N user questions above the editor, so you can quickly find "which of my questions produced the answer below" in long sessions.

## Features

- Shows the last N user questions (default 5; set with `/current-question <number>`)
- One line per question; long lines are truncated with `...` (correctly handles double-width CJK characters)
- Title carries the round counter: `❯ Current Questions (N)` where N is the current question round
- Collapsed by default; `Ctrl+Alt+L` expands the selected entry to show the full question + its answer, `Ctrl+Alt+H` collapses
- Collapsed: `Ctrl+Alt+H` hides the widget; hidden: `Ctrl+Alt+L` shows it again
- Expanded: `Ctrl+Alt+J/K` scrolls the answer; collapsed: `Ctrl+Alt+J/K` switches entries
  (vim-style j=down/k=up; in expanded mode j scrolls the answer forward, in collapsed mode j goes to an earlier question)
- Selection can exceed the visible window: the list holds all history, the window shows a fixed `maxLines` rows and follows the selection; stops silently at top/bottom
- Expanded answer is shown in a fixed-height scrollable window; stops silently at top/bottom
- Expanded height adapts to the terminal: long questions are truncated, the answer window is dynamically compressed by terminal height to avoid hitting the top and causing streaming jitter
- `Ctrl+Alt+B` copies the selected entry's full question + answer
- `Ctrl+Alt+G` opens an external editor to compose a reply with the selected Q&A as context (vi-family editors auto-lock the history region read-only)
- After a new message is sent, the selection snaps back to the newest entry and collapses
- Uses `sessionManager` as the single source of truth; stays consistent after `/undo`, `/redo`, `/tree`, and compaction

## Install

```bash
# Install globally
pi install npm:@zzs-fun/current-question

# Or install for the current project only
pi install -l npm:@zzs-fun/current-question
```

## Shortcuts

| Shortcut | Collapsed | Expanded |
|----------|-----------|----------|
| `Ctrl+Alt+J` | Select an earlier question | Scroll answer down |
| `Ctrl+Alt+K` | Select a newer question | Scroll answer up |
| `Ctrl+Alt+L` | Expand the selected entry (full question + answer) | — |
| `Ctrl+Alt+H` | Hide the widget | Collapse the selected entry |
| `Ctrl+Alt+B` | Copy the full question + answer | Copy the full question + answer |
| `Ctrl+Alt+G` | Open external editor with Q&A context | Same |

> Note: overrides the editor's default `Ctrl+Alt+J` / `Ctrl+Alt+K` cursor movement.

## Command

```
/current-question [on|off|toggle|<number>]
```

- `on` / `off` / `toggle`: toggle the widget
- number: set how many entries to show (e.g. `/current-question 8`), and enables it
- no argument: equivalent to `toggle`

## License

MIT