generated from BlackHatMagic/Template-Bare
feat: edit prompts and retry responses #3
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/retry-edit"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Type Selection
Summary
Adds the T3 Chat / Pi web bare-minimum message actions that were missing:
Both actions navigate Pi's native session tree in place, preserving the old branch in the session file and keeping the current session ID. Actions appear on hover/focus and are hidden while Pi is working. This also loads the active branch from
get_entries, so displayed messages carry native entry IDs and raw user text across reloads.Related Issues
None. Follow-up to the Pi Chat plugin and the user's report that retry/edit were missing.
Design Overview
fork. A probe confirmed RPCforkresponds successfully and then exits the Pi child process, which would break a long-lived sidebar session.loadEntries()followsleafIdthroughparentIdto build the active branch and attaches tool results bytoolCallId.ChatMessagenow storesentryIdand raw user text.reloadTranscript()refreshes authoritative entries afteragent_settledand after navigation.PiSession.editUser(entryId, text)andPiSession.regenerate(assistantKey);PiEditMessageModal; message action buttons;SessionHost.extensionPath;get_entriesprotocol types.Implementation Notes
pi-obsidian-tree.tsextension into its plugin folder and loads it with--extension. The extension registers/pi-obsidian-tree, validates a per-process nonce fromPI_OBSIDIAN_NONCE, checksctx.isIdle()/ctx.hasPendingMessages(), callsctx.navigateTree(targetId, { summarize: false }), and reports the result throughsetStatus.main.js,manifest.json, andstyles.css.get_commandsis checked during hydration to enable the actions only when the extension loaded.revisingguard. A stale transcript reload cannot overwrite a newly started prompt (epochguard).fork/clone, because the child exits after the fork response and the plugin would have to restart the process and guess the new session state.Testing Evidence
tests/chat-state.test.tscovers active-branch loading, entry IDs, raw user text, tool-result attachment, and compaction summaries.tests/extension-source.test.tsimports the generated extension and verifies nonce enforcement, idle checks, and status reporting.bun run checkpasses: typecheck + 21 tests.bun run buildpasses.get_entriesshowed the old branch retained.Documentation
Checklist (Feature-Specific)
Additional Notes
Pi code review
2 new actionable findings
src/session.ts:392src/chat-view.ts:568Merged three candidate reviews of Edit/Retry via native Pi tree navigation; verified both surviving defects against current session, view, and chat-state code. No checks were run and live Pi behavior could not be exercised from this environment.
Change walkthrough
src/chat-state.ts,src/chat-view.ts,src/dialogs.ts,src/extension-source.ts(+6 more)README.mdtests/chat-state.test.ts,tests/extension-source.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
df38299aee33ddb6957a15ab2a13fbcbc937169dwithproxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.@ -524,0 +565,4 @@event.preventDefault();event.stopPropagation();handler();});[P2] Editing a skill prompt drops its skill instructions
Edit prefills and resends from rendered text blocks instead of rawText, so saving an edit on a skill-expanded prompt resends bare user text without its skill wrapper.
Trigger: Send a skill invocation with accompanying user text, then open Edit on that user message and save.
Impact: Replacement request loses the selected skill name/location/content context, materially changing how Pi performs the task without user intent.
Evidence: chat-state.ts toMessage keeps skill blocks as only trailing userText while rawText preserves full messageText; chat-view.ts editMessage builds initial from blocks text and calls editUser(entryId,text) with bare text, while session.ts regenerate correctly reuses user.rawText.
@ -252,0 +389,4 @@if (index < 0) throw new Error("That reply is no longer on the active branch.");const user = [...this.state.messages.slice(0, index)].reverse().find((message) => message.role === "user" && message.entryId && message.rawText !== undefined);[P2] Retry can resend an older prompt before transcript refresh
Preceding-user lookup skips user messages without entryIds instead of stopping at the immediate predecessor, so Retry on a newly completed response can select an older saved prompt and branch from the wrong turn.
Trigger: Complete a second or later prompt while an earlier user already has an entryId, then click Retry on the latest reply while its post-settlement get_entries refresh is still pending or has failed.
Impact: Pi regenerates an unrelated earlier request and removes the later conversation from the active branch instead of retrying the selected response.
Evidence: applyRecord creates streamed messages via toMessage without entryId; agent_settled clears busy and starts reloadTranscript asynchronously with errors swallowed, while canRevise is true immediately. Both PiChatView.precedingUser (src/chat-view.ts:544 skips users lacking entryId/rawText) and PiSession.regenerate search backward for a user with entryId, then navigateNative plus prompt with that older entryId/rawText.
Pi code review
1 new actionable finding
src/session.ts:402Earlier findings: 2 rechecked
src/session.ts:392, first reported in review #250) — precedingUserMessage in src/chat-state.ts now returns the nearest preceding user or undefined immediately without skipping unrefreshed turns, and both PiChatView.precedingUser and PiSession.regenerate use it to hide Retry or throw Wait for refresh; covered by does not skip past an unrefreshed user test.src/chat-view.ts:568, first reported in review #250) — PiChatView.editMessage now passes message.skill to editUser and PiSession.editUser rebuilds with composeSkillPrompt(skill, trimmed), restoring the <skill> wrapper; covered by rebuilds skill instructions test.Merged three reviews of the Edit/Retry tree-navigation change at head
07cb0fdagainst basece3ebf3. Verification was read-only code inspection without running tests or a live Pi session.Change walkthrough
.gitignore,manifest.json,src/chat-state.ts,src/chat-view.ts(+7 more)README.mdpackage.jsontests/chat-state.test.ts,tests/extension-source.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
07cb0fdf22aa8f8bdba4cbf11103dc47d2f54eb8withproxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.@ -252,0 +399,4 @@this.host.changed();try {await this.navigateNative(user.entryId, "Retrying response");await this.prompt(user.rawText, "steer");[P2] Composer sends can interleave with an unfinished Edit or Retry
The revising guard blocks concurrent Edit/Retry but ordinary composer prompt() has no revising check, so a composer message sent during the post-navigation transcript reload runs on the rewound branch and the revision then unconditionally sends its own replacement prompt as steer.
Trigger: Click Edit/Save or Retry, then send a composer message while the post-navigation get_entries reload is pending; a slow or large transcript widens the window and composer sends while busy are intentionally queued as steer/followUp.
Impact: The new composer request runs without the expected replacement turn in context, and the edited/retried instructions become steering input to that unrelated request, producing unintended agent work instead of independent turns.
Evidence: PiChatView.send() calls PiSession.prompt() directly with only empty-draft gating, and prompt() only bumps epoch without checking revising, while editUser/regenerate only check revising against each other. navigateNative awaits reloadTranscript after the branch change and doReloadTranscript merely skips load on busy/epoch change, but regenerate then still executes prompt(user.rawText, steer) and editUser executes prompt(prompt, steer). Extension idle checks occur before navigation and do not protect this later interval.
Pi code review
1 new actionable finding
src/session.ts:503Earlier findings: 1 rechecked
src/session.ts:402, first reported in review #251) — src/session.ts:420 prompt() now throws when revising and src/session.ts:487 compact() does the same; src/chat-view.ts send() early-returns on isRevising and refreshSendButton disables send while revising, and revising remains true across navigateNative including reloadTranscript until the finally block.Outside the diff
[P2] New chat or restart during Edit/Retry can move replacement prompt to fresh session
editUser/regenerate hold revising across navigateNative plus sendPrompt but newSession/restart have no revising check, so a New chat or Restart issued after navigation succeeds can run before the queued replacement prompt and send it on the new client.
Trigger: Click Edit Save or Retry, then before navigation plus reload completes use New chat view action, New chat command, Restart command, or settings New chat; busy is false during navigation so newChat busy confirmation does not block it.
Impact: The edited or retried prompt is lost from the intended branch and instead starts unintended agent work in the fresh session with possible vault reads or edits and model cost, plus stale-branch transcript or error pollution.
Evidence: src/session.ts editUser/regenerate set revising=true then call navigateNative then sendPrompt without snapshotting the client while sendPrompt uses this.client at call time; prompt() at line 420 and compact() at line 487 reject when revising but newSession() at line 503 and restart() at line 518 have no such guard; src/chat-view.ts newChat() only confirms on state.busy which is false while navigateNative sets status Editing/Retrying.
Suggested fix:
Location:
src/session.ts:503(outside the diff; posted here because it can't anchor inline).Merged three candidate reviews of Edit/Retry tree navigation, transcript reloads, and UI gating; verified revision guards in current code. No execution environment was available, so Pi-side navigation and timing behavior were inferred from code and callers.
Change walkthrough
src/chat-state.ts,src/session.ts,src/extension-source.ts,src/chat-view.ts(+3 more)tests/chat-state.test.ts,tests/extension-source.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
6c7f6202ffa98fbba70d1da2ffb3f3184ff5d7fdwithproxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.Pi code review
2 new actionable findings
src/session.ts:203src/session.ts:335Earlier findings: 1 rechecked
src/session.ts:503, first reported in review #254) — Head src/session.ts newSession() and restart() reject when revising is true before enqueuing lifecycle work, and src/chat-view.ts newChat()/restart() block on isRevising; replacement prompt can no longer land in a fresh session.Merged three independent reviews of the Edit/Retry tree-navigation change at head
41502ce. Verification was read-only code inspection; Pi-side RPC behavior and live Obsidian runs could not be exercised.Change walkthrough
.gitignore,manifest.json,src/chat-state.ts,src/chat-view.ts(+7 more)README.mdpackage.jsontests/chat-state.test.ts,tests/extension-source.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
41502ce7e9454a1d4493a257b4ba617b986876b6withproxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.@ -163,3 +201,3 @@client.request({ type: "get_available_models" }),client.request({ type: "get_available_thinking_levels" }),client.request({ type: "get_messages" }),client.request({ type: "get_entries" }),[P1] Hydrate hard-requires get_entries, breaking older Pi CLIs
hydrate() requests get_entries without fallback; if Pi lacks that RPC the Promise.all rejects and doStart marks the session Pi unavailable, leaving chat unusable where get_messages previously worked.
Trigger: Start the plugin against a Pi binary without get_entries RPC (custom piPath, older Pi). Authors anticipate older versions via the navigateTree version check.
Impact: Full chat hydration fails and shows Pi unavailable instead of degrading to history without revise actions, blocking all use for affected users.
Evidence: Head src/session.ts hydrate does Promise.all with client.request get_entries with no catch while get_session_stats and get_commands have .catch fallbacks; base hydrate used get_messages. Head doStart catch sets status Pi unavailable and notifies on hydrate failure.
Suggested fix:
@ -252,0 +332,4 @@const epoch = this.epoch;const entries = await client.request({ type: "get_entries" });// A new turn may have started while the request was in flight.if (this.state.busy || epoch !== this.epoch) return;[P2] Manual compact can skip transcript refresh due to busy guard
compact() now calls guarded reloadTranscript() which early-returns when busy is true, while compaction_start sets busy true without a clear on compaction_end. If Pi emits compaction events around the manual compact RPC, the post-compact reload is skipped and the view keeps pre-compaction messages while status shows Ready.
Trigger: Idle session with history, invoke Compact context; Pi emits compaction_start/end during the compact RPC.
Impact: User sees stale pre-compaction transcript with no compaction summary while status reports Ready, hiding that compaction occurred.
Evidence: Head src/chat-state.ts compaction_start sets busy true and compaction_end only sets status without clearing busy; head src/session.ts doReloadTranscript returns if state.busy, and compact() calls reloadTranscript where base did unconditional get_messages plus loadHistory.
Pi code review
0 new actionable findings
No new actionable findings. Previously reported issues, if any, are tracked below.
Earlier findings: 2 rechecked
src/session.ts:335, first reported in review #256) — Head src/session.ts compact() sets compacting/busy then clears both (compacting=false, busy=state.running) before awaiting reloadTranscript(), so doReloadTranscript's busy guard no longer skips idle manual-compact refresh; head src/chat-state.ts compaction_end also clears compacting and derives busy from running.src/session.ts:203, first reported in review #256) — Head src/session.ts hydrate() uses client.request get_entries with .catch(()=>null) and branches to loadEntries when present else get_messages+loadHistory, so missing get_entries no longer rejects Promise.all or fails hydration.Merged three candidate reviews of the Edit/Retry tree-navigation PR; verified prior hydration and compact-refresh defects are fixed in head code via reads only, with no runnable checks.
Change walkthrough
src/session.ts,src/chat-state.ts,src/extension-source.ts,src/chat-view.ts(+7 more)tests/chat-state.test.ts,tests/extension-source.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
837a8d297ef5ff5787ba8b77efca95633bb12305withproxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.