Skip to content

fix(claude-mod): restore the message picker for /plannotator-last - #1684

Merged
backnotprop merged 2 commits into
mainfrom
fix/mod-last-message-picker
Oct 4, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/mod-last-message-picker

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Regression

plannotator annotate-last normally shows a message picker (up to 25 recent assistant messages, newest open) so the reviewer can annotate an earlier message, e.g. after /rewind. Pi and OpenCode still do. Under the Claude Code mod, /plannotator-last and the plannotator tool's action: "last" opened only the newest message: there was no way to go back.

Cause

The mod ran plannotator annotate-last --stdin and wrote only lastAssistantText(await host.messages()) to stdin. The CLI's --stdin branch sets lastMessage and no recentMessages, so pickerMessages was never passed to startAnnotateServer.

Fix

  • Mod (apps/hook/hooks/mod/launch.ts, controller.ts): recentAssistantTexts builds the list from $.session.messages(): newest first, at most 25, text-less rows skipped, consecutive assistant rows joined as one response (the transcript path groups chunks by message id the same way). pickerMessages gives each one a content-derived id (cc- + 16 hex of its SHA-256, -n for repeats), stable as newer messages arrive, and drops older messages over the CLI's size limits. With more than one message the launch writes messages.json ({ v: 1, messages: [{ messageId, text }] }) in the launch dir and sets PLANNOTATOR_HOST_MESSAGES_FILE. stdin still carries the newest text. With exactly one message the launch is byte-identical to before. The file is removed with the other launch files on cleanup.
  • CLI (apps/hook/server/host-messages.ts, index.ts): honors the variable only with --stdin, only for a messages.json under <data dir>/claude-code-mod/; takes it at startup and scrubs it from the env (like PLANNOTATOR_HOST_RESULT_FILE). Validation is fail-closed: v 1, 1..25 entries, string fields, unique ids, 2 MiB per message, 8 MiB per file. Error text never quotes the payload. A malformed file exits 1 with the reason. Index 0 opens by default, as on the classic path.
  • Subject: with a picker the subject is "Claude's recent messages" (status line, open text, the plugin turn's first line), because the feedback may be about an older message. The feedback body already carries an excerpt of each message it covers (exportMessageAnnotations). The result record and delivery are unchanged.
  • The subagent refusal for action: "last" is unchanged (the harness test still passes).

Why an env var and not a flag

The plugin and binary update separately. An old CLI ignores the variable and opens the stdin text, which is exactly today's behavior. An unknown flag is not safe. I checked it: annotate-last --stdin-messages on today's CLI silently ignores the flag, falls through to the Claude transcript lookup and starts a server for whatever session it resolves. Changing what --stdin carries would make an old CLI show the JSON as the message. A version probe would add a process run and a hook-budget cost to every last.

Compatibility

Old CLI New CLI
Old mod unchanged (newest message only) unchanged: no variable, --stdin exactly as before
New mod newest message only (variable ignored), no failure. The subject/open text still say "recent messages · N messages", a cosmetic mismatch during the version skew picker with up to 25 messages, newest open

$.session.messages()

Rows are { role, text, toolUses, toolResults? }: no ids, no timestamps (so the picker shows no timestamps under the mod). They are the engine's live conversation (newest 4096 entries). After /rewind that should be the rewound conversation; this is inferred from the API docs, not verified live. After /compact only post-compaction messages are present, so the picker can be shorter than on the classic path, which falls back to the pre-compaction file.

Tests

  • apps/hook/hooks/mod/controller.test.ts: the last launch carries the recent messages newest-first, skips text-less rows, joins one response's rows, keeps stdin = newest, sets the env var, and names "Claude's recent messages" in the open text and the delivered turn. A single message launches exactly as before (no file, no variable). Ids stay stable as newer messages arrive, and the list stops at 25.
  • apps/hook/server/host-messages.test.ts: annotate-last --stdin runs as a real process. The file yields /api/plan recentMessages with the newest as plan. A malformed file exits 1 with a clear message. Plain --stdin is unchanged. There are also unit tests for the parser and the path guard.
  • bun test apps/hook/server apps/hook/hooks: 414 pass, 0 fail. Mod typecheck (apps/hook/hooks/mod/tsconfig.json) is clean. scripts/test-claude-code-mod.sh: 10 pass. claude plugin validate apps/hook passes.

Docs: the CLAUDE.md (AGENTS.md) Claude Code mod section, the launch-dir file list and the env table row. No skill change: no user-facing flag was added.

backnotprop and others added 2 commits October 4, 2026 13:02
Under the Claude Code mod, /plannotator-last and the plannotator tool's
action "last" handed the CLI only the newest assistant text on stdin, so
the picker the classic path shows (up to 25 recent messages) never
appeared and an earlier message could not be annotated.

The mod now builds the recent list from $.session.messages() (newest
first, at most 25, text-less rows skipped, consecutive assistant rows
joined, content-derived stable ids) and, when there is more than one,
writes messages.json and points PLANNOTATOR_HOST_MESSAGES_FILE at it.
stdin still carries the newest text, so a CLI that predates the variable
behaves exactly as before. The CLI reads the file only with --stdin, only
under the data dir's claude-code-mod/, scrubs the variable at startup and
validates it fail-closed (malformed is a startup error, exit 1).

Co-Authored-By: Claude <noreply@anthropic.com>
The mod budgeted ~7 MiB of raw text while the CLI caps the serialized
file at 8 MiB. JSON escaping inflates text (quotes, backslashes, newlines
double; ESC becomes \u001b), so escape-heavy responses could cross the
cap and make /plannotator-last fail although stdin held a usable newest
message. pickerFile now measures the JSON exactly as written, 256 KiB
under the cap: older messages that do not fit are dropped, and when the
newest alone does not fit no file is written (stdin only).

Co-Authored-By: Claude <noreply@anthropic.com>
@backnotprop

Copy link
Copy Markdown
Owner Author

Review fix (bbcb5da): the mod now budgets messages.json on its serialized size, not its raw text. pickerFile measures the JSON exactly as written and keeps it 256 KiB under the CLI's 8 MiB cap. Older messages that don't fit are dropped. If the newest alone doesn't fit, no file is written and the launch is stdin-only, as before. The CLI is still fail-closed and unchanged.

New tests in apps/hook/server/host-messages.test.ts:

  • Escape-heavy text (quote, backslash, ESC): the file stays under the cap and a real CLI process accepts it. A raw-text budget would have written about 23 MiB here.
  • A newest message that only fits as raw text gives no file.
  • The mod's copied limits must equal the CLI's.

@backnotprop
backnotprop merged commit 815009e into main Oct 4, 2026
28 checks passed
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.

1 participant