Repository navigation
feat(fork): a Petal's asks sit above its composer, one at a time, with its status and one-click answers - #374
Conversation
…ick answers, updates fold Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NoahHendrickson
left a comment
There was a problem hiding this comment.
Reviewed 8b059ed114d3e16384d8cbba5c196047ae8409f8 against the PR diff for base 0aa266b5588dc1ea3532a268cf34bde406d98f81. A focused parser check reproduced both parsing issues below. I traced the send state through command handling and the panel lifecycle in source.
| .filter(Boolean) ?? []; | ||
| if ( | ||
| match === null || | ||
| !/[?.!)>]$/.test(line.slice(0, match.index).trimEnd()) || |
There was a problem hiding this comment.
[P2] Recognize answers after a bare PR URL
The seed tells Petals to append the full PR URL before the answer arrow. An ask such as Merge now? https://github.com/acme/app/pull/21 → Merge | Hold ends in a digit before the arrow, so the parser returns zero answers and displays the options as prose. This also happens when a Markdown thread link precedes the PR URL. Recognize supported trailing links in the boundary check and cover a bare PR URL in the parser test.
|
|
||
| function parseItem(line: string): BotDigestItem { | ||
| const source = unmarked(line); | ||
| const split = splitAnswers(unmarked(line)); |
There was a problem hiding this comment.
[P2] Restrict answer parsing to Needs you items
parseItem also parses the headline and update rows. For example, Status: Migrated the job (cron) → scheduler becomes Migrated the job (cron), silently losing the destination. The same happens in New and In progress, where the extracted suffix is never rendered and is excluded from the dismissal key. Only split answer suffixes on Needs you items so status and updates keep their original text.
| ); | ||
| // The answer each ask was given here, for the digest as it read then: once the bot rewrites it, | ||
| // an ask it kept offers its answers again. | ||
| const [sentFor, setSentFor] = useState<{ |
There was a problem hiding this comment.
[P2] Keep sent answers when the Threads panel closes
Closing the panel unmounts BotDigest once the exit transition finishes. If the answer is queued behind an active turn, reopening the panel before the Petal edits the digest shows the same buttons again. A second click creates a new message ID and queues a duplicate or conflicting answer to the same ask. Keep the acknowledgement outside the panel component and scope it to the Petal, digest contents and ask.
| const updateCount = updates.reduce((count, section) => count + section.items.length, 0); | ||
| // An answer goes to the bot as the owner's reply, quoting its ask, behind whatever it is doing. | ||
| const answer = async (item: BotDigestItem, choice: string) => { | ||
| setSent((previous) => new Map(previous).set(item.source, choice)); |
There was a problem hiding this comment.
[P2] Report send failures in the digest
The row shows “Sent” before the command returns, then silently brings back the buttons if it fails. For example, a connection with filesystem read access but without orchestration operate access can see and click the buttons, and the command returns an authorization failure without a user-facing message. Show a pending state until the command succeeds, surface failures so users know to retry, and disable sending where the connection lacks permission.
NoahHendrickson
left a comment
There was a problem hiding this comment.
Thermo-nuclear code-quality review of 8b059ed114d3e16384d8cbba5c196047ae8409f8. Not approving. No file crosses 1k lines (BotDigest.tsx is now 467 lines, botDigestSections.ts 211), so size is fine. The problems are about structure and where the logic lives.
Blocking
-
Answers are parsed in the wrong layer, and that loses words.
splitAnswersruns insideparseItem, which handles every line: Needs you, New, In progress, section headings and the status line. Only Needs you renders answers, but every item'ssource/textgets cut. So an In progress lineDeploy v2 (beta) → stableshows asDeploy v2 (beta), and a status ofShip it? → Yes | Noshows asShip it?. The "finished ask" check/[?.!)>]$/makes this worse. It counts any)or>as a finished ask, so prose likeMigrate (staging) → prodturns into aprodbutton. Answers belong to Needs you only, so split them only there. Decide "after its links" with the link-run walkparseItemalready does, not a second regex that guesses at link endings. -
useTellBotcopies thetellfunction inuseSetBotWork.ts. Both doreadThreadShell→startTurnwithdispatchMode: "queue"and the shell's modes. Move it into onecustom/bots/useTellBot.tsthat both callers use. The copies have already drifted: the new one doesn't check for an archived bot, and only the new one reports failure. One send-to-bot path, one set of rules. -
The "Sent" state is a hand-built reset-on-key.
sentFor+setSent+NO_ANSWERScomparecontentsin two places and copy Maps, all to say "forget this when the file changes". React already does that: move the per-ask state into aBotDigestRequestitem component (useState<string | null>) and key the Needs you list bycontents.sentFor,setSent,NO_ANSWERS, thesentprop, theanswerclosure and the Map rollback all go away, and behavior stays the same.
Strong suggestions
-
One parse, one model. The component calls
parseBotDigestandparseBotDigestStatusbehind the samefile === null || file.exists === falseguard, and the effect parses a third time. One parser is told to skipStatus:lines and the other is told to find them. HaveparseBotDigestreturn{ status, sections }(or{ status, needsYou, updates }). Then theshown.map(… ? … : null)ternary, the secondupdatesfilter and the duplicated guard all disappear, and the empty check becomes one property. -
Fold and dismiss now both hide the same updates. Updates are folded by default, and each card keeps its per-bot dismissal: localStorage, the pruning
useEffect,hiddenCount, "Show N dismissed" andbotDigestSectionKey. With everything dismissed you get an "Updates 0" header with only "Show N dismissed" inside. Folding seems to replace dismissal; if so, removing dismissal deletes a whole layer. Please choose one on purpose rather than keep both.
Smaller
- The
promptprop now holds a nested ternary (answers.length === 0 ? null : given !== undefined ? … : …), and the Reply variant repeats the same condition. Pull out aBotDigestAnswerscomponent and deriveofferingonce. The> ${item.source}\n\nquote is also built twice (answerandreply), so give it one helper. splitAnswerswas added betweenparseItem's doc comment andparseItem. The result is two doc comments stacked onsplitAnswers, andparseItemhas none.
Not covered by tests: the send/rollback path, and the misparse cases above. Add rows for Migrate (staging) → prod and for an arrow inside an In progress item.
— Claude Opus 5.5 in Claude Code
|
|
||
| function parseItem(line: string): BotDigestItem { | ||
| const source = unmarked(line); | ||
| const split = splitAnswers(unmarked(line)); |
There was a problem hiding this comment.
This runs for every line: updates, headings and the status line, not only Needs you. It cuts → … out of their text: - Deploy v2 (beta) → stable under In progress shows as Deploy v2 (beta). Answers are a Needs-you concept, so split them only for that section's items, and keep parseItem a plain line parser.
| .filter(Boolean) ?? []; | ||
| if ( | ||
| match === null || | ||
| !/[?.!)>]$/.test(line.slice(0, match.index).trimEnd()) || |
There was a problem hiding this comment.
) and > are standing in for "a link ended here", but they match any closing paren: Migrate (staging) → prod gives a prod button. parseItem already works out the trailing link run and the sentence end (SENTENCE_END, BETWEEN_LINKS). Use that instead of a second guess at link endings.
| /** Queues `text` as the owner's message to the bot, behind whatever it is doing; false when it | ||
| could not be sent. */ | ||
| function useTellBot(): (botRef: ScopedThreadRef, text: string) => Promise<boolean> { | ||
| const startTurn = useOrchestrationCommand(threadEnvironment.startTurn); |
There was a problem hiding this comment.
This copies tell in useSetBotWork.ts (same readThreadShell → startTurn queue call). Move it into one useTellBot module that both use. The copies already differ: this one doesn't check archivedAt.
| ); | ||
| // The answer each ask was given here, for the digest as it read then: once the bot rewrites it, | ||
| // an ask it kept offers its answers again. | ||
| const [sentFor, setSentFor] = useState<{ |
There was a problem hiding this comment.
This builds "reset when the file changes" by hand (sentFor, setSent, two contents comparisons, Map copies). Move the state into a per-ask component and key the Needs you list by contents: React resets it for you, and this block, NO_ANSWERS, the sent prop and the rollback Map edits go away.
| }); | ||
| const file = AsyncResult.getOrElse(result, () => null); | ||
| const sections = file === null || file.exists === false ? [] : parseBotDigest(file.contents); | ||
| const status = |
There was a problem hiding this comment.
The same file guard and a second pass over the file. Let parseBotDigest return { status, sections } so there's one parse and one model, and the empty check and the shown.map(… : null) partition below become simple reads.
| Show {hiddenCount} dismissed | ||
| </Button> | ||
| </div> | ||
| {updates.length === 0 && hiddenCount === 0 ? null : ( |
There was a problem hiding this comment.
Updates now have two ways to hide (a global fold plus per-bot dismissal with its pruning effect), and with everything dismissed this draws "Updates 0" with only "Show N dismissed" inside. If the fold replaces dismissal, removing dismissal deletes a whole layer. Either way, choose one on purpose.
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code review of 8b059ed (Claude Code, single pass).
The parser tests and the fork-bots guard pass on this commit (18/18). I found three problems, inline below. The first one breaks the main feature for asks that carry a pull request:
- High: answers are never parsed when the ask ends with its PR URL, and the seeded CLAUDE.md tells Petals to write exactly that.
- Medium: a
Status:line anywhere in the file becomes the headline and is dropped from its section. - Low: "Sent" lives only in component state, so after a remount the buttons come back and a second click queues a second answer.
🤖 Generated with Claude Code
| .filter(Boolean) ?? []; | ||
| if ( | ||
| match === null || | ||
| !/[?.!)>]$/.test(line.slice(0, match.index).trimEnd()) || |
There was a problem hiding this comment.
High: answers are lost when an ask ends with its PR URL. The finished-ask check only accepts ?, ., !, ) or > before the arrow. A bare URL ends in a digit, so the check fails. The seeded CLAUDE.md tells Petals to end each item with the thread link and then the PR's full URL, with answers after the links. So any ask about a pull request, which is the main case for → Push | Hold, gets no buttons.
It is worse than no buttons: because the arrow text stays in the line, the trailing links stop being dropped as well. I checked this on the PR head:
- Merge #482? [Fix search](t3-thread://v2/env-1/thread-1) https://github.com/acme/app/pull/482 → Merge | Wait
→ text: "Merge #482? Fix search #482 → Merge | Wait", answers: []
- Merge #483? https://github.com/acme/app/pull/483 → Merge | Wait
→ text: "Merge #483? #483 → Merge | Wait", answers: []
A possible fix: when the text before the arrow ends in a bare URL token (TOKEN's bare-URL group), count it as a finished ask. Or run the test against the line's words after the trailing links are stripped. A test row with a thread link plus a PR URL plus answers would cover it.
| /** The digest's status line in plain words (`Status: Waiting on you · next scan Thu 8:00`), or | ||
| null when the bot wrote none. */ | ||
| export function parseBotDigestStatus(contents: string): string | null { | ||
| for (const raw of contents.split(/\r?\n/)) { |
There was a problem hiding this comment.
Medium: a Status: line inside a section becomes the headline. parseBotDigestStatus returns the first Status: line anywhere in the file. parseBotDigest (line 176) skips every such line in every section. So an unbulleted item like Status: CI red on #9 under In progress does two things: it disappears from its section (which then counts as empty and is dropped), and it shows as the digest's headline. I confirmed this on the PR head. The new test even accepts a Status: line inside Needs you and silently ignores it.
The instructions put the status line under the title. Reading it, and skipping it, only before the first ## heading would keep section content intact.
| ); | ||
| // The answer each ask was given here, for the digest as it read then: once the bot rewrites it, | ||
| // an ask it kept offers its answers again. | ||
| const [sentFor, setSentFor] = useState<{ |
There was a problem hiding this comment.
Low: "Sent" is forgotten on remount, so an answer can go twice. sentFor is plain useState. Closing and reopening the Threads panel or sheet, or switching to another Petal and back, clears it while the digest file is still unchanged. The bot hasn't run its queued turn and rewritten the digest yet, so the buttons come back, and a second click queues a second > ask\n\nanswer turn. The PR description says the buttons give way to "Sent" until the Petal rewrites its digest, which doesn't hold across a remount.
One option is to keep it beside dismissed, in localStorage keyed by the bot and the digest contents. Another is to derive it from the bot's queued or pending user messages.
… the Threads panel lists threads only Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mposer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and its actions below Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…equest's state or by needs-input Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…op fixes for answers, rules refresh and Sent state Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…strip carrying the status and pager Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e status sits under the title, one send-to-bot path, and sent answers outlive a remount Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
These reviews were of Fixed
No longer applies: the Updates fold and the per-section dismissal (Updates aren't drawn any more; each ask has its own dismiss), and the old Declined
🤖 Generated with Claude Code |
A Petal's digest was hard to glance at. It read like a log in the Threads panel, packed several asks into one line, and never said whether anything needed you.
BotDigestAsks, one fenced line in ChatView beside upstream'sChildThreadApprovals, inside the composer stack so the transcript inset counts it). The Threads panel now lists threads only.Status:line (else "Needs you"), "Show N dismissed", and a pager: previous, one dot per ask with the current one a rounded dash, then next. The ask on show is the surface inside.splitBotDigestAsk: the first sentence that asks one), muted detail clamped to two lines, its thread and PR links, and the actions below.→ Push | Hold. Clicking one queues the ask, quoted, plus the answer as the owner's message to the Petal (startTurn,dispatchMode: "queue"). The buttons show "Sent" until the Petal settles a run after the send. A failed send restores that card's buttons and shows an error toast. Reply quotes the ask into the composer, or opens a linked thread that is waiting on a question.BOT_RULES_VERSIONgoes to 4 so existing Petals get the new instructions. New and In progress stay in DIGEST.md for the Petal's own memory and are not drawn.useResizeDrag, which is back to upstream.Tests: parser cases for answers (including after a bare PR URL), arrow prose, long answers, the status line, and the question/detail split. Guards pin the ChatView mount, the panel without a digest, and the seeded instructions.
Reviewed with sol-loop: 3 rounds with gpt-6.2-sol on high. Sol verdict: changes requested. Fixed: answers after a bare PR URL, the rules-version bump, an unbounded stack, stale "Sent" states (expiry, carry-over between Petals) and the failed-send rollback. Declined (S5): a late send failure can clear a newer answer to the same ask if a run settled and the ask was re-answered while the first send was pending. It's rare, and the error toast already reports it. The dots, dismiss and double-vessel layout came after the loop.
Model and harness: Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code