Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ file in the file list goes to that file, a click on a folder opens or closes it,
click on a note selects it and shows its lines. The Send and `Review ▾` buttons in the header are clickable. Drag over lines to
select them: a selection is whole lines on the side where the drag started, as in the
browser's code review, and the lines are shaded while you drag. Drag past the top or bottom
of the diff to scroll. When you let go, a small toolbar next to the lines offers `💬 comment`
and `✎ suggest` (click it, or press `c` or `s`), and the note is anchored on exactly those
of the diff to scroll. When you let go, a small toolbar next to the lines offers `❓ ask`,
`💬 comment` and `✎ suggest` (click it, or press `a`, `c` or `s`), and the note is anchored on exactly those
lines, with their code quoted for the agent. `Esc` clears the selection. Drag works the
same in the whole-file view. Shift-click grows a selection to the clicked line, from the
line the drag started on. A selection stays inside the hunk it started in, as GitHub's
Expand Down Expand Up @@ -365,6 +365,28 @@ review started in the browser continues here and the other way round. A mark sto
counting once its file changes. Set `PLANNOTATOR_REVIEW_PROGRESS=0` to keep marks for the
session only. See [docs/spec-review-progress.md](docs/spec-review-progress.md).

### Ask the agent

`a` (`ask`) on a selection or a line, or `❓ ask` on the toolbar after a drag, opens the
comment box for a question. Enter puts it in a box under the lines and types it into the
agent Send goes to, with the file, the lines and their code, so the question and its
answer are part of the agent's own conversation. When nothing names an agent, it asks
which one first, as Send does. The answer is read back from the agent's transcript and
shows in the box as it is written, whatever the Notes setting, each message under who
wrote it. A question typed while the agent is busy gets its answer when the agent takes
it. Nothing you ask becomes a note.

A question on the same lines, or on lines inside them, goes into the same box: Enter or
`a` on the box asks one, and the question box opens at the box's end. `Delete` on the box,
or on one of its lines, removes the box (the agent's chat keeps the questions).

The answer is read from the agent's own session, found as [`last`](#agent-replies) finds
it from the agent's process: a target that names the process (Rex, hc, or Pi's
`/plannotator-review`) for Claude Code, Copilot or Pi. Anything else would be the newest
session in the folder, a guess, so asking says so instead of sending. Codex is not
supported yet: its transcript reader gives only the agent's replies, so the question cannot
be found there.

### Pick what to review

`plannotator-tui review --pick`, or `p` (`pick-changes`) in a review, opens the change
Expand Down Expand Up @@ -713,6 +735,7 @@ added in a later release leaves its default key to whatever your file already bo
| `review-menu` | `m` | the Review menu |
| `pick-target` | `P` | choose the agent Send goes to (see [Choosing the agent](#choosing-the-agent)) |
| `pick-changes` | `p` | code review: [pick what to review](#pick-what-to-review); in the picker, back to the review |
| `ask` | `a` | code review: [ask the agent](#ask-the-agent) about the lines; on its box, ask again |
| `resend-all` `finish-review` `undo-finish` `archive` | `R` `F` `U` `H` | file and folder review actions |
| `toggle-hidden` | `.` | show/hide dot-prefixed entries in the tree |
| `edit` `remove` | `e` `x`, `Delete` | the selected note |
Expand Down
15 changes: 13 additions & 2 deletions crates/plannotator-tui-hosts/src/claude/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub(crate) struct Entry {
pub(crate) is_sidechain: bool,
pub(crate) hidden: bool,
pub(crate) is_compact_summary: bool,
/// A prompt typed while the agent worked: Claude Code takes it into the running turn and
/// records it as a `queued_command` attachment, not as a `user` entry.
pub(crate) queued: bool,
}

impl Entry {
Expand All @@ -41,7 +44,14 @@ impl Entry {
let string = |key: &str| object.get(key).and_then(Value::as_str).map(str::to_owned);
let flag = |key: &str| object.get(key).and_then(Value::as_bool).unwrap_or(false);
let message = object.get("message").and_then(Value::as_object);
let queued_prompt = object
.get("attachment")
.filter(|a| a.get("type").and_then(Value::as_str) == Some("queued_command"))
.filter(|a| a.get("commandMode").and_then(Value::as_str) == Some("prompt"))
.and_then(|a| a.get("prompt"))
.and_then(Value::as_str);
let texts = match message.and_then(|m| m.get("content")) {
_ if let Some(prompt) = queued_prompt => vec![prompt.to_owned()],
Some(Value::String(text)) => vec![text.clone()],
Some(Value::Array(blocks)) => blocks
.iter()
Expand Down Expand Up @@ -71,6 +81,7 @@ impl Entry {
is_sidechain: flag("isSidechain"),
hidden,
is_compact_summary: flag("isCompactSummary"),
queued: queued_prompt.is_some(),
})
}

Expand All @@ -83,15 +94,15 @@ impl Entry {
}

pub(crate) fn is_skipped(&self) -> bool {
SKIPPED_TYPES.contains(&self.kind.as_str()) || self.hidden || self.is_sidechain
(SKIPPED_TYPES.contains(&self.kind.as_str()) && !self.queued) || self.hidden || self.is_sidechain
}

/// A typed human prompt with text: not meta, not a compact summary, not machinery.
pub(crate) fn is_human_prompt(&self) -> bool {
if self.is_skipped()
|| self.is_meta
|| self.is_compact_summary
|| self.effective_role() != Some("user")
|| (self.effective_role() != Some("user") && !self.queued)
{
return false;
}
Expand Down
23 changes: 23 additions & 0 deletions crates/plannotator-tui-hosts/tests/claude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,26 @@ fn garbage_input_yields_no_messages_rather_than_an_error() {
[] as [plannotator_tui_hosts::Message; 0]
);
}

#[test]
fn a_prompt_queued_while_the_agent_worked_is_a_human_prompt_and_other_attachments_are_not() {
let jsonl = [
r#"{"type":"user","uuid":"u1","parentUuid":null,"message":{"role":"user","content":"first"}}"#,
r#"{"type":"assistant","uuid":"a1","parentUuid":"u1","message":{"role":"assistant","id":"m1","content":[{"type":"text","text":"working"}]}}"#,
r#"{"type":"attachment","uuid":"q1","parentUuid":"a1","attachment":{"type":"queued_command","prompt":"asked meanwhile","commandMode":"prompt"}}"#,
r#"{"type":"attachment","uuid":"f1","parentUuid":"q1","attachment":{"type":"edited_text_file","filename":"a.rs"}}"#,
r#"{"type":"assistant","uuid":"a2","parentUuid":"f1","message":{"role":"assistant","id":"m2","content":[{"type":"text","text":"the answer"}]}}"#,
]
.join("\n");
let messages = parse_messages(&jsonl, 5);
let shown: Vec<(Role, &str)> = messages.iter().map(|m| (m.role, m.text.as_str())).collect();
assert_eq!(
shown,
[
(Role::Assistant, "the answer"),
(Role::Human, "asked meanwhile"),
(Role::Assistant, "working"),
(Role::Human, "first")
]
);
}
4 changes: 4 additions & 0 deletions crates/plannotator-tui/src/delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pub(crate) trait Delivery {
fn agent_host(&self) -> Option<&str> {
None
}
/// The receiving agent's process, when the target knows it: Ask finds its transcript.
fn agent_pid(&self) -> Option<u32> {
None
}
fn deliver(&self, feedback: &str) -> Result<(), DeliveryError>;
/// What the person still has to do after the last `deliver` succeeded, shown with its
/// status: the feedback reached the agent but did not finish, e.g. it waits unsubmitted.
Expand Down
2 changes: 1 addition & 1 deletion crates/plannotator-tui/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) fn feedback(name: &str, entries: &[Entry<'_>]) -> String {
}

/// A fence longer than any backtick run inside the text, so quoted markdown cannot escape.
fn fenced(text: &str) -> String {
pub(crate) fn fenced(text: &str) -> String {
let longest = text.split(|c| c != '`').map(str::len).max().unwrap_or(0);
let fence = "`".repeat(longest.max(2) + 1);
format!("{fence}\n{text}\n{fence}\n")
Expand Down
4 changes: 4 additions & 0 deletions crates/plannotator-tui/src/hc/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl Delivery for HcAgent {
self.agent.as_deref()
}

fn agent_pid(&self) -> Option<u32> {
Some(self.pid)
}

fn describe(&self) -> String {
format!("{} in {}", self.agent.as_deref().unwrap_or("agent"), self.terminal)
}
Expand Down
15 changes: 11 additions & 4 deletions crates/plannotator-tui/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ pub(crate) enum Action {
/// Pick what the code review shows: uncommitted, unstaged or staged changes, the branch,
/// or one of the recent commits.
PickChanges,
/// Ask the agent about the selected lines: the question goes to it as Send goes, and its
/// answer shows in a box under the lines.
Ask,
}

use Action::{
Expand All @@ -143,12 +146,12 @@ use Action::{
Reload, Remove, RemoveImage, ResendAll, ReviewMenu, Right, Send, SendAndClose, ToggleHidden, ToggleTree,
Top, UndoFinish, Up, Visual, VisualLine, WordBack, WordEnd, WordForward, Yes,
};
use Action::{Ask, DiffSettings, PickChanges, SplitLeft, SplitRight, ToggleWhitespace};
use Action::{
ChangeComment, FileComment, Help, NextFile, NextHunk, NextMatch, NextUnviewed, PreviousFile,
PreviousHunk, PreviousMatch, PreviousUnviewed, Search, Suggest, ToggleFiles, ToggleLayout, ToggleViewed,
ToggleWrap, WholeBase, WholeFile,
};
use Action::{DiffSettings, PickChanges, SplitLeft, SplitRight, ToggleWhitespace};
use Action::{FilterFiles, FilterKinds, GoToDefinition, HideViewed, JumpBack, JumpForward};
use Action::{NarrowColumn, NarrowFiles, NarrowNotes, ToggleNotes, WidenColumn, WidenFiles, WidenNotes};

Expand Down Expand Up @@ -251,6 +254,7 @@ pub(crate) const DIFF: &[Action] = &[
Comment,
Suggest,
FileComment,
Ask,
Down,
Up,
PageDown,
Expand Down Expand Up @@ -542,14 +546,16 @@ const DEFAULTS: &[(Action, &[Key])] = &[
(SplitLeft, &[ch('(')]),
(SplitRight, &[ch(')')]),
(PickChanges, &[ch('p')]),
(Ask, &[ch('a')]),
];

/// Actions added after configs were written: `approve` (live only in a gated review), `copy`
/// (on a waiting selection), `word-end`, `visual-line`, the code review's own, the reading
/// column's, `toggle-notes` and search. The newest come first (`pick-changes`, then
/// `toggle-whitespace`, then `diff-settings`, `split-left` and `split-right`, then
/// `copy-lines`), so they yield a key before an older action does.
/// column's, `toggle-notes` and search. The newest come first (`ask`, then
/// `pick-changes`, then `toggle-whitespace`, then `diff-settings`, `split-left` and
/// `split-right`, then `copy-lines`), so they yield a key before an older action does.
const LATE: &[Action] = &[
Ask,
PickChanges,
ToggleWhitespace,
DiffSettings,
Expand Down Expand Up @@ -798,6 +804,7 @@ impl Action {
Self::SplitLeft => "split-left",
Self::SplitRight => "split-right",
Self::PickChanges => "pick-changes",
Self::Ask => "ask",
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/plannotator-tui/src/keys/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,11 @@ fn pick_changes_is_p_in_the_code_review_and_yields_to_an_older_config_that_gave_
assert_eq!(keymap.hint(PickChanges), key, "pick-changes in {config:?}");
}
}

#[test]
fn a_config_that_gave_asks_key_away_still_loads() {
// Written before `ask` existed: `a` is the user's file-comment key, and ask is left unbound.
let keymap = parse("file-comment = [\"a\"]\n").expect("an older config keeps loading");
assert_eq!(keymap.action(&press(KeyCode::Char('a'), KeyModifiers::NONE), DIFF), Some(FileComment));
assert_eq!(keymap.hint(Ask), "");
}
3 changes: 3 additions & 0 deletions crates/plannotator-tui/src/last/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mod fallback;
mod locate;
mod readers;
mod roots;
mod transcript;

pub(crate) use transcript::Transcript;

use std::io::Read as _;
use std::path::PathBuf;
Expand Down
67 changes: 67 additions & 0 deletions crates/plannotator-tui/src/last/transcript.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! An agent's transcript, found the way `last` finds it, then read again as it grows: the
//! code review's Ask reads its answers from there.

#[cfg(test)]
use std::path::Path;
use std::path::PathBuf;

use anyhow::{Result, bail};
use plannotator_tui_hosts::{Host, Message};

use super::fallback::Discovery;
use super::{LastOptions, locate, readers};

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Transcript {
host: Host,
path: PathBuf,
/// The host's session id, for hosts whose transcript holds several sessions.
session_id: Option<String>,
/// The agent process, for hosts that read their place in the session from it (Pi).
pid: Option<u32>,
}

impl Transcript {
/// The transcript of agent process `pid`, of host `host` when the target names one
/// (`claude`, `pi`, ...), else as detected. Only the agent's own session: the newest one
/// in its folder is a guess, and another session's answer would show as this one's.
pub(crate) fn find(host: Option<&str>, pid: Option<u32>) -> Result<Self> {
let options = LastOptions { host: host.map(str::to_owned), pid, pick: 1, ..LastOptions::default() };
let located = locate::locate(&options)?;
if located.discovery != Discovery::Exact {
bail!(
"only a guess ({}) for {}: asking needs the agent's own session, which a target that names its \
process gives for Claude Code, Copilot and Pi",
located.transcript.display(),
located.host.label()
);
}
Ok(Self { host: located.host, path: located.transcript, session_id: located.session_id, pid })
}

/// A transcript of `host` at `path`, without looking anything up.
#[cfg(test)]
pub(crate) fn at(host: Host, path: &Path) -> Self {
Self { host, path: path.to_path_buf(), session_id: None, pid: None }
}

pub(crate) fn host(&self) -> Host {
self.host
}

/// The file that grows as the agent writes: Copilot's session is a folder whose
/// `events.jsonl` it appends to.
pub(crate) fn file(&self) -> PathBuf {
match self.host {
Host::Copilot => self.path.join("events.jsonl"),
_ => self.path.clone(),
}
}

/// Prompts and replies, newest first, through the `pick`th reply.
pub(crate) fn conversation(&self, pick: usize) -> Result<Vec<Message>> {
let (_, messages) =
readers::explicit(self.host, &self.path, self.session_id.as_deref(), self.pid, pick)?;
Ok(messages)
}
}
6 changes: 6 additions & 0 deletions crates/plannotator-tui/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ fn first_code(doc: &Document) -> Vec<(String, String)> {
samples
}

/// `markdown` styled as the document view styles a block, one `Line` per logical line and
/// unwrapped: an agent's answer in the code review's Ask panel.
pub(crate) fn styled(markdown: &str) -> Text<'static> {
own(tui_markdown::from_str_with_options(markdown, &Options::new(Styles { fences: true })))
}

pub(crate) fn own(text: Text<'_>) -> Text<'static> {
let lines = text
.lines
Expand Down
4 changes: 4 additions & 0 deletions crates/plannotator-tui/src/pi/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl Delivery for PiSession {
Some("pi")
}

fn agent_pid(&self) -> Option<u32> {
Some(self.entry.pid)
}

fn deliver(&self, feedback: &str) -> Result<(), DeliveryError> {
self.last.set(None);
match super::send(&self.entry, feedback) {
Expand Down
Loading
Loading