Repository navigation
fix(claude-mod): restore the message picker for /plannotator-last - #1684
Merged
Merged
Conversation
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>
Owner
Author
|
Review fix (bbcb5da): the mod now budgets New tests in
|
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Regression
plannotator annotate-lastnormally 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-lastand theplannotatortool'saction: "last"opened only the newest message: there was no way to go back.Cause
The mod ran
plannotator annotate-last --stdinand wrote onlylastAssistantText(await host.messages())to stdin. The CLI's--stdinbranch setslastMessageand norecentMessages, sopickerMessageswas never passed tostartAnnotateServer.Fix
apps/hook/hooks/mod/launch.ts,controller.ts):recentAssistantTextsbuilds 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).pickerMessagesgives each one a content-derived id (cc-+ 16 hex of its SHA-256,-nfor repeats), stable as newer messages arrive, and drops older messages over the CLI's size limits. With more than one message the launch writesmessages.json({ v: 1, messages: [{ messageId, text }] }) in the launch dir and setsPLANNOTATOR_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.apps/hook/server/host-messages.ts,index.ts): honors the variable only with--stdin, only for amessages.jsonunder<data dir>/claude-code-mod/; takes it at startup and scrubs it from the env (likePLANNOTATOR_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.exportMessageAnnotations). The result record and delivery are unchanged.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-messageson 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--stdincarries 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 everylast.Compatibility
--stdinexactly as before$.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/rewindthat should be the rewound conversation; this is inferred from the API docs, not verified live. After/compactonly 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: thelastlaunch 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 --stdinruns as a real process. The file yields/api/planrecentMessageswith the newest asplan. A malformed file exits 1 with a clear message. Plain--stdinis 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/hookpasses.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.