feat(chat): /btw — side questions in a temporary forked session (#2796)
* feat(chat): /btw command — side questions in a temporary forked session /btw <question> forks the current session (full context inheritance) and opens a compact peek panel docked above the composer. The composer itself becomes the btw input while the panel is open: sends route to the fork, the placeholder and a mode chip reflect the target, and the stop button aborts the fork's turn. Closing the panel (or the chip's ✕) destroys the fork, leaving the main conversation untouched. The panel shows only the fork's own tail (messages at/after the fork creation time) and live permission/question cards scoped to the fork. - chat/btw/BtwPanel: peek sheet (desktop + mobile), fork-tail view, auto-close on disappearance, Esc to close - lib/btw: startBtwSession (fork + rename + routed send), closeBtwPanel (close = destroy), filterBtwTailMessages - ChatInput: btw-mode send routing via SendMessageOptions.sessionId, btw-aware activity (stop/abort), placeholder + mode chip - useSessionActivity: exported for per-session activity reads - i18n: btw keys across all 11 locales * fix(chat): keep btw sends isolated * refactor(chat): rework /btw into a metadata-scoped peek panel - Link the active btw fork through the parent session's metadata (openchamber.btwSessionID) so the panel exists only in the session that invoked /btw, follows parent navigation, and survives reloads; the fork carries a kind:'btw' marker with its originalSessionID. - Replace the wall-clock history boundary with the id of the newest cloned message (server-generated ascending ids), stored in fork metadata. - Derive panel identity in useBtwPanelState; useBtwStore shrinks to transient per-parent UI state (collapsed/creating/destroying). - Panel UX: dropdown-style glass surface, chat ScrollShadow, single title+chevron collapse toggle, muted header controls, promote action (keep as a full session and navigate to it), Esc collapses instead of destroying, reserved Working indicator row, streaming auto-follow via ResizeObserver keyed on content readiness. - Add a 'peek' chat surface mode that suppresses per-message controls and turn footers inside the panel; user bubbles keep a small gap below. - Hide btw forks from the sidebar, session switcher, and command palette until promoted; mark the fork before inserting it into local stores. - Delete/archive lifecycle: removing the fork unlinks the parent; removing the parent also removes its temporary fork. - patchSessionMetadata now mirrors updated sessions into live stores. - Localize new strings across all 12 dictionaries; add unit tests for metadata helpers, the btw flow, and the UI store. * fix(chat): clamp the btw panel below the app header when the keyboard is open Reuse useMobileAutocompleteMaxHeight (the composer autocomplete precedent) on the panel's scroll body, reserving the panel header and bottom spacer height, so the sheet adapts to the visual viewport instead of riding under the app header on mobile. * fix(lint): drop unused destructured bindings in sessionBtwMetadata CI eslint has no underscore ignore pattern; strip metadata keys with typed copies and delete instead of discard-destructuring. --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
a317a156cb
commit
46426e8495
@@ -26,6 +26,7 @@ import {
|
||||
type SessionMetadataRecord,
|
||||
} from "@/lib/sessionReviewMetadata"
|
||||
import { withContextObligatoryMessage, type ContextObligatoryMessage } from "@/lib/contextObligatoryMessages"
|
||||
import { getBtwOriginalSessionID, getBtwSessionID, isBtwSession, withoutBtwSessionLink } from "@/lib/sessionBtwMetadata"
|
||||
import { withLinkedIssue, type LinkedIssue } from "@/lib/linkedIssues"
|
||||
import { getImperativeSessionMessageLoader } from "./session-message-loader"
|
||||
import { cleanupPersistedSessionState } from "./session-deletion-cleanup"
|
||||
@@ -794,6 +795,7 @@ export async function patchSessionMetadata(
|
||||
useGlobalSessionsStore.getState().upsertSession(updated)
|
||||
const sessionDirectory = (updated as { directory?: string | null }).directory ?? targetDirectory
|
||||
if (sessionDirectory) registerSessionDirectory(updated.id, sessionDirectory)
|
||||
mirrorSessionIntoLiveStores(updated, sessionDirectory ?? undefined)
|
||||
return updated
|
||||
}
|
||||
|
||||
@@ -803,11 +805,8 @@ export async function setLinkedIssue(
|
||||
issue: LinkedIssue,
|
||||
linked: boolean,
|
||||
): Promise<Session> {
|
||||
const updated = await patchSessionMetadata(sessionId, directory, (metadata) =>
|
||||
return patchSessionMetadata(sessionId, directory, (metadata) =>
|
||||
withLinkedIssue(metadata, issue, linked))
|
||||
const sessionDirectory = (updated as Session & { directory?: string | null }).directory ?? directory ?? undefined
|
||||
mirrorSessionIntoLiveStores(updated, sessionDirectory ?? undefined)
|
||||
return updated
|
||||
}
|
||||
|
||||
export async function setContextObligatoryMessage(
|
||||
@@ -816,11 +815,8 @@ export async function setContextObligatoryMessage(
|
||||
message: ContextObligatoryMessage,
|
||||
pinned: boolean,
|
||||
): Promise<Session> {
|
||||
const updated = await patchSessionMetadata(sessionId, directory, (metadata) =>
|
||||
return patchSessionMetadata(sessionId, directory, (metadata) =>
|
||||
withContextObligatoryMessage(metadata, message, pinned))
|
||||
const sessionDirectory = (updated as Session & { directory?: string | null }).directory ?? directory ?? undefined
|
||||
mirrorSessionIntoLiveStores(updated, sessionDirectory ?? undefined)
|
||||
return updated
|
||||
}
|
||||
|
||||
async function cleanupReviewMetadataBeforeDelete(
|
||||
@@ -836,18 +832,41 @@ async function cleanupReviewMetadataBeforeDelete(
|
||||
return
|
||||
}
|
||||
if (isStaleRuntime(expectedRuntimeKey)) return
|
||||
if (!isReviewSession(session)) return
|
||||
const originalSessionID = getOriginalSessionID(session)
|
||||
if (!originalSessionID) return
|
||||
try {
|
||||
await patchSessionMetadata(originalSessionID, directory ?? getSessionDirectory(originalSessionID), (metadata) =>
|
||||
withoutReviewSessionLink(metadata, sessionId),
|
||||
expectedRuntimeKey,
|
||||
)
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
if (/not found/i.test(message)) return
|
||||
console.warn("[session-actions] review metadata cleanup failed before delete", error)
|
||||
|
||||
const unlinkParent = async (originalSessionID: string, unlink: (metadata: SessionMetadataRecord) => SessionMetadataRecord) => {
|
||||
try {
|
||||
await patchSessionMetadata(originalSessionID, directory ?? getSessionDirectory(originalSessionID), unlink, expectedRuntimeKey)
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
if (/not found/i.test(message)) return
|
||||
console.warn("[session-actions] linked-session metadata cleanup failed before delete", error)
|
||||
}
|
||||
}
|
||||
|
||||
if (isReviewSession(session)) {
|
||||
const originalSessionID = getOriginalSessionID(session)
|
||||
if (originalSessionID) await unlinkParent(originalSessionID, (metadata) => withoutReviewSessionLink(metadata, sessionId))
|
||||
return
|
||||
}
|
||||
|
||||
if (isBtwSession(session)) {
|
||||
const originalSessionID = getBtwOriginalSessionID(session)
|
||||
if (originalSessionID) await unlinkParent(originalSessionID, (metadata) => withoutBtwSessionLink(metadata, sessionId))
|
||||
return
|
||||
}
|
||||
|
||||
// Deleting or archiving a session that has an active btw fork also removes
|
||||
// the fork: it is a temporary session that only exists for its parent's
|
||||
// panel. Best-effort — a failed fork delete must not block the parent's
|
||||
// operation; the orphaned fork stays visible in the sidebar.
|
||||
const btwSessionID = getBtwSessionID(session)
|
||||
if (btwSessionID) {
|
||||
try {
|
||||
if (isStaleRuntime(expectedRuntimeKey)) return
|
||||
await deleteSession(btwSessionID, { expectedRuntimeKey })
|
||||
} catch (error) {
|
||||
console.warn("[session-actions] failed to delete btw fork before parent delete", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user