Skip to content

annotate-last: pick which message to annotate (fixes #800)#809

Draft
GLips wants to merge 3 commits into
backnotprop:mainfrom
GLips:annotate-last-picker
Draft

annotate-last: pick which message to annotate (fixes #800)#809
GLips wants to merge 3 commits into
backnotprop:mainfrom
GLips:annotate-last-picker

Conversation

@GLips
Copy link
Copy Markdown

@GLips GLips commented May 28, 2026

Fixes #800.

What this changes for users

Running `/plannotator-last` after `/rewind` no longer silently opens on the orphaned pre-rewind message. The annotation UI now surfaces recent messages so you can pick whichever message you like.

Two affordances, both only visible when there's more than one message to choose from:

  • A "Message N of M" button in the document's sticky-top action bar (alongside Copy / Global comment / Attachments). Stays visible while scrolling.
  • A "Messages" tab in the left sidebar with the full list — newest-first, preview + timestamp, default marked with ★. Mirrors the existing Files / Versions / Archive tab pattern.

Default selection (index 0) matches today's "last message" behavior, so anyone who doesn't interact with the picker sees no change.

Coverage

Wired for Claude Code, Codex, and Droid — they all share `apps/hook/server/index.ts` and parse session/rollout files locally, so it was one refactor.

OpenCode, Pi, and Copilot CLI still get the original single-message behavior. They each have their own entry point with their own message source (SDK calls / branch traversal / events.jsonl) — each is ~20 LOC to extend. Happy to do those in this PR if you'd prefer to ship coverage parity, or in a follow-up.

Notes for reviewers

  • The wire payload (`recentMessages` field on `/api/plan`) is omitted entirely when there's nothing to pick, so unsupported harnesses degrade cleanly with zero conditional branches in the server.
  • Switching messages clears existing annotations (they're text-anchored). The picker prompts before discarding work-in-progress.
  • New `MessagesIcon` lives in `packages/ui/components/icons/` — the grouped-icon convention.
  • Added 6 unit tests covering `extractRecentRenderedMessages` (turn-boundary crossing, limit honoring, default-equals-legacy invariant, edge cases). Full suite still 1200/1200.

Test plan

  • Verify default selection matches pre-PR `/plannotator-last` behavior in a non-rewound session
  • Run `/rewind` then `/plannotator-last` — confirm the picker surfaces both the orphaned and current-branch messages
  • Confirm chip + tab are hidden in single-message Claude Code sessions
  • Confirm OpenCode / Pi / Copilot sessions still work (no picker, original message shown)

GLips added 3 commits May 27, 2026 22:17
When running /plannotator-last after /rewind, the newest transcript
entry is no longer the message the user intended to annotate, and there
was no affordance to pick a different one.

Adds a picker UI that surfaces the recent assistant messages so the
user can choose which one to annotate:

- A "Message N of M" button in the Viewer's sticky-top action bar
  (alongside Copy / Global comment / Attachments), so it stays
  accessible while scrolling.
- A "Messages" tab in the left sidebar with the full list
  (newest-first, preview + timestamp, default ★), mirroring the
  existing Files / Versions / Archive tab pattern.

Wired for Claude Code, Codex, and Droid (all share apps/hook/server).
OpenCode, Pi, and Copilot still get the original single-message
behavior — they don't emit recentMessages, so the picker affordances
hide cleanly.

Default selection (index 0) matches today's "last message" behavior,
so users who don't interact with the picker see no change.
The picker UI from backnotprop#800 was wired for Claude / Codex / Droid only. Pull
Copilot and OpenCode onto the same shape so users on those harnesses
also get the recent-messages picker when annotating the last assistant
message.

- Copilot: replace getLastCopilotMessage with getRecentCopilotMessages,
  walking events.jsonl newest-first up to 25 assistant.message events.
- OpenCode: rewrite the session walk to collect up to 25 messages
  (newest first) instead of bailing on the first hit; normalize the SDK
  time.created (ms epoch) to ISO to match the shared picker contract.
- Both pass recentMessages to startAnnotateServer only when length > 1,
  matching the existing Claude/Codex/Droid behavior.

Also trims a leftover narrating comment in MessagesBrowser and refreshes
the stale Copilot session-parser header.

Pi parity follows in the next commit (needs round-trip of the picker
selection through /api/feedback so its post-submit anchoring quotes the
right message).
Extends the picker UI (backnotprop#800) to Pi and fixes a Pi-specific anchoring bug
the picker would otherwise introduce.

Picker plumbing
- assistant-message: getRecentAssistantMessages walks the active branch
  newest-first, returning { messageId, text, timestamp? } in the same
  shape the other harnesses produce.
- Plumbed through plannotator-browser / plannotator-events so the Bun
  server's recentMessages option is populated when the branch has more
  than one assistant message.

Anchoring fix
- Pi quotes the targeted assistant message back to the agent because its
  UX is async — the conversation may have moved on by feedback time.
  With the picker, that target is no longer guaranteed to be the
  snapshot taken when the UI opened. The editor now sends the user's
  selectedMessageId with /api/feedback; Pi looks it up in the current
  branch via findAssistantMessageByEntryId and quotes that message
  instead. Falls back to the original snapshot if the entry is gone.
- The round-trip field is optional and only meaningful in annotate-last
  mode; other harnesses (and other modes) ignore it.

Timestamp safety
- Pi's SDK currently types SessionEntryBase.timestamp as string, but the
  picker contract everywhere else is ISO. Treat the value as unknown and
  normalize string/number(ms)/Date to ISO; drop anything else, rather
  than blind-casting and risking silent drift if the SDK changes.
@GLips
Copy link
Copy Markdown
Author

GLips commented May 28, 2026

Ok I gotta go through some more thorough testing myself tomorrow with Claude Code but this should be pretty close to the final form if you want to take a look @backnotprop

If not I'll explicitly mark it as ready for review once I've had a chance to check it out more deeply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

annotate-last: picks wrong message after /rewind; consider a message-picker UI

1 participant