Skip to content

Thread forking + session-based side chats + timeline scroll preservation - #85

Merged
brsbl merged 106 commits into
mainfrom
otto/thread-forking-and-side-chats
Jun 17, 2026
Merged

brsbl merged 106 commits into
mainfrom
otto/thread-forking-and-side-chats

Conversation

@brsbl

@brsbl brsbl commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Thread forking + session-based side chats

Two ways to branch off an existing conversation, both backed by a native
provider-session fork
rather than a text snapshot: a fork continues the
parent's work on its own branch, and a side chat asks a focused question
against the parent's full context without disturbing it. Also includes timeline
scroll preservation so following up doesn't jump the transcript.

Forking model

A fork or side chat branches the parent's actual provider session at its
head
— tool results, reasoning, and prompt cache all carry over — into a child
thread with a fresh providerThreadId. There is no bounded text replay and no
snapshot fallback; forking is always a real session branch.

Provider Native fork
claude-code forkSession(id, { dir }) → new session id
codex thread/fork JSON-RPC → new rollout
pi forkFrom() / createBranchedSession()

The Fork and Start-side-chat affordances are gated on a forkable parent: a
live providerThreadId on the same host. A parent that never ran, or whose
workspace lands on a different host, is not forkable and the affordance is
disabled.

Fork vs. side chat

  • Fork — a full child thread that continues the parent's work on a new
    branch. It is established idle with an empty timeline: the session is
    cloned but no turn runs until you steer the first one.
  • Side chat — a read-only branch for a focused question, surfaced in the
    right-panel tab with send-to-main. Sending the question runs it immediately
    against the cloned session. "From this message" anchors a reply: when the
    anchored message isn't the head, it is shown as the message being replied to
    and included as context in the first turn.

Thread hierarchy & lifecycle

  • Threads carry childOrigin (fork | side-chat) and parentThreadId.
  • The hierarchy is capped at depth 4 (MAX_THREAD_HIERARCHY_DEPTH); the server
    exposes canSpawnChild so clients never recompute the cap.
  • A fork is established idle without running a turn: the daemon's
    no-input-no-turn guard clones the session with empty input, and the thread
    settles starting → idle on the zero-work run's completion — a single,
    explicit transition in the thread lifecycle state machine.
  • The fork descriptor (sourceProviderThreadId) flows server → daemon
    thread.start → runtime.

Sidebar

Threads render in two sections — Projects (per-project lists) and Threads
(project-less threads). Worktree environments are the grouping construct: two or
more threads sharing a worktree environment collapse under a group header, while
a lone worktree thread stays a navigable row. The right edge carries the
disclosure caret and thread status — busy spinner, attention dot, or unread dot.
Row indentation and indent hairlines are driven by shared spacing tokens.

Timeline scroll preservation

Following up keeps your place: the prompt box anchors scroll position so sending
a message no longer jumps the transcript.

brsbl and others added 15 commits June 10, 2026 05:30
Server/domain foundation, timeline message-action scaffolding, and
timeline scroll-position preservation for the thread-forking + side-chats
spec.

- S1: add startedOnBehalfOf to createThreadRequest; plumb it through
  provisioning so a forked thread-start turn renders as an agent-initiated
  "Message from {source}" and is seeded WITHOUT a provider run
  (OQ1 -> approach A via thread-provisioning). Add nullable childOrigin
  (domain + migration 0024 + persist + response + list filter) and a
  server-derived canSpawnChild depth-cap boolean. Foundation tests.
- S2: register Fork/SideChat icons; extract reusable MessageActionBar
  (reuses CopyButton, hover-reveal); forward row identity to assistant props.
- S5: in-memory per-thread scroll-anchor store; throttled capture +
  restore-by-row in BottomAnchoredScrollBody (converges on ResizeObserver
  settle, falls back to bottom); tests.

Typecheck 5/5 packages; @bb/db 281, @bb/app 1046, server-contract +
seed-without-run server tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- [P1] Boundary coherence + anti-forgery in createThreadFromRequest:
  startedOnBehalfOf requires parentThreadId and senderThreadId ===
  parentThreadId (transitively validated live + same-project); childOrigin
  requires parentThreadId. Side-chat combo (childOrigin + null
  startedOnBehalfOf) still valid. +5 tests.
- [P1] Scroll fallback-to-bottom now scrolls inline when the saved anchor
  row never appears (was relying on a later resize that may never fire);
  de-masked the test (mutation-verified).
- [P2] Log a warning when the seed-without-run provisioning->idle
  transition no-ops (stranded seed observable).
- [P2] Name the message hover-reveal group (group/message +
  group-focus-within) to match the disclosure/tab-pill convention.
- Correct the AppCreateThreadRequest comment: the server schema owns the
  null default at runtime; the client echoes null only to satisfy the
  output-typed wire body (input-typed contract is a noted follow-up).

Typecheck @bb/server, @bb/server-contract, @bb/app pass; boundary + scroll
+ message tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fork wiring and session-based side chats, built on the batch-1 foundation.

- S3 (fork): buildForkThreadRequest + useForkThreadFromMessage create the
  forked thread (anchor message; startedOnBehalfOf/childOrigin/parentThreadId
  all = source; managed worktree from the source branch HEAD; provider/model/
  permission inherited), navigate to it, composer auto-focuses on mount
  (Approach A: server seeds the anchor without a provider run). Fork button
  wired into the agent message-action footer with a canSpawnChild depth
  guard; forked anchor renders with the Fork icon via childOrigin; "Forks"
  lineage list in thread metadata via a targeted parentThreadId+childOrigin
  query. Consumes the row-identity props (resolves a batch-1 finding).
- S4 (side chat): side-chat panel tab kind; openSideChat opens a tab with a
  PromptBoxInternal composer (OQ4: it drives a non-route thread directly);
  lazy child-thread creation on first submit with an agent-only main-thread
  snapshot (spawning message + N=3 preceding), personal workspace, readonly;
  keep-mounted SideChatTabDeck (BrowserTabDeck pattern); send-back via the
  existing useSendThreadMessage (senderThreadId now forwarded). onSideChat
  wired next to onFork under the shared depth guard.

@bb/app typecheck pass; full app suite 149 files / 1075 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- [P0] Side chats now run in a same-project readonly worktree (shared
  child-thread-environment resolver, reused by fork + side chat) instead of
  a personal workspace, which 400'd in standard projects and broke the
  same-project parentThreadId/send-back invariants. Spec updated.
- [P1] Side-chat context snapshot anchors on the full source message text
  (persisted on the tab) instead of the truncated tab title, so the window
  centers on the real spawning message.
- [P1] Fork button is dropped (not inert) when the source has no host.
- [P1] Server validates senderThreadId is same-project as the target in
  resolveMessageSenderThreadId (rejects cross-project attribution forgery on
  the send/queued paths); +test.
- [P2] Fork icon only on the seed anchor row, not every cross-thread agent
  message; remove dead sourceTurnId field; synchronous re-entrancy guards
  against double-create (fork + side chat); deleted side-chat child shows a
  "no longer available" state instead of endless waiting.

@bb/app 149 files / 1084 tests; @bb/server typecheck + public-thread-data
55 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- [P1] Fork/side-chat child spawns no longer overwrite the project's stored
  execution defaults (childOrigin carve-out in
  shouldRememberProjectExecutionDefaults), so a side chat's forced readonly
  mode / inherited model can't silently become the project default. +test.
- [P2] optimisticallyInsertThread honors the childOrigin list filter, so a
  side chat no longer flashes in the source thread's "Forks" list before
  refetch. +test.
- [P2] Side-chat lazy create waits for a host-backed source's environment to
  resolve before building the request, avoiding a personal-workspace
  fallback that 400s in standard projects.

Deferred (noted in PR): tighten the single-thread cache write-side generics
to ThreadResponse (currently ThreadWithRuntime) — benign today, latent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Completes the previously-deferred final-review P2: the threadQueryKey
(single-thread) cache slot is read as ThreadResponse but was written through
helpers typed ThreadWithRuntime, so a future writer could drop the required
canSpawnChild/childOrigin without a type error. Type updateCachedThread, the
create/send/stop transaction writers, and their previousThread fields against
ThreadResponse for that slot (list/sidebar entries stay ThreadWithRuntime).

Type-only change; typecheck clean and cache/mutation tests green (every
existing writer already supplied a full ThreadResponse).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address the three P2 findings from the full-PR review:

- [P2] Couple startedOnBehalfOf and childOrigin at the create boundary:
  startedOnBehalfOf now requires childOrigin, so a seed-without-run thread is
  always a tagged child (can't be untagged or silently reshape project
  execution defaults). +test.
- [P2] hasAnyThreadMetadata accounts for the lazily-fetched Forks row (the
  gate now takes hasForks, computed via a deduped useThreads), so a forks-only
  thread no longer flashes the "No thread details" fallback while the
  environment query loads. +test.
- [P2] Gate side-chat "Send to main thread" on the child thread being idle, so
  a mid-stream partial can't be posted into the main thread.

@bb/server typecheck + boundary tests (9) green; @bb/app typecheck + full
suite (149 files / 1087 tests) green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The scroll-anchor capture effect's cleanup read scrollAnchorCaptureThrottleRef
.current directly, which eslint flags as possibly-stale. Capture the (stable,
never-reassigned) throttle-state object into a local inside the effect and use
it in the cleanup — same live trailingTimeout is cleared, lint clean.

@bb/app lint + typecheck pass; scroll-preservation tests (6) green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve conflicts with 24 commits of main:
- ThreadMetadataContent.tsx: keep the Forks row + main's new
  environmentDisplayHost prop on EnvironmentRow.
- ThreadMetadataContent.test.tsx: combine the ForksRow/hasAnyThreadMetadata
  tests with main's EnvironmentRow tests and EnvironmentDisplayHostContext import.
- ProjectList.test.tsx: take main's deletion.
- environment-provisioning.test.ts: add the now-required childOrigin/
  startedOnBehalfOf to main's new createThreadFromRequest call.

Typecheck 6/6; @bb/app lint + full suite (150 files / 1093 tests); @bb/server
thread + environment suites (97) green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Forking or opening a side chat from a personal-project thread failed with
"Personal project threads must use a personal workspace". resolveChildThread
Environment keyed on hostId !== null, but a personal-project thread has a host
running a *personal* workspace, so it built a managed worktree the server
rejects. Route to a personal workspace whenever the source's workspace is
personal (carrying the host), not only when there is no host.

Verified live: fork + side chat from a personal-project thread now 201
(was 400). +regression tests in both builders.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the native title tooltips on the per-message copy / fork / side-chat
icon buttons with the Radix Tooltip primitive (faster, styled, consistent).
MessageActionBar wraps each button in a Tooltip under a local TooltipProvider.

CopyButton is now forwardRef + prop-spreading so it can be a Tooltip `asChild`
trigger; a caller can pass `title={undefined}` to drop the native tooltip when
supplying its own (its other 4 usages keep the default title). aria-labels are
retained on all three buttons.

@bb/app typecheck + lint + full suite (150 files / 1095 tests) green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A side chat (or fork) is a child thread, so completing/failing a turn fired
bb's child->parent notification, posting a "child finished" system message into
the main thread (which the main agent then replied to). That's wrong for
user-initiated branches — the user drives them directly.

Extract isAgentDelegatedChildThread(thread) = has a parent AND childOrigin is
null, and gate all three child->parent notification sites on it
(turn-completion in internal/events, command-failure in thread-lifecycle,
needs-attention in internal/interactive-requests). Agent-delegated children
(childOrigin null) still notify their parent; forks/side chats do not.

@bb/server typecheck + thread-parent (incl. new helper tests) + child-thread-
notifications / interactive-requests / parenting suites green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…nd-side-chats

# Conflicts:
#	apps/app/src/components/secondary-panel/ThreadSecondaryPanel.tsx
#	apps/app/src/components/secondary-panel/useThreadFileTabs.ts
#	apps/app/src/components/thread/timeline/ConversationMessageContent.tsx
#	apps/app/src/components/ui/icon.tsx
#	apps/app/src/lib/api.ts
#	apps/app/src/lib/fixed-panel-tabs-state.test.ts
#	apps/app/src/lib/fixed-panel-tabs-state.ts
#	apps/app/src/views/thread-detail/ThreadDetailSecondaryContent.tsx
#	apps/app/src/views/thread-detail/ThreadDetailView.tsx
#	apps/app/src/views/thread-detail/threadSecondaryPanelSelection.ts
#	apps/server/src/services/threads/thread-provisioning.ts
#	packages/db/drizzle/meta/0024_snapshot.json
#	packages/db/drizzle/meta/_journal.json
The loopback/LAN firewall allows a same-origin subresource only when the
requesting frame's origin matches the committed main-frame origin, derived from
`details.frame.origin`. Electron reports a blank origin for a document's initial
subresource requests (before it has run script and committed its origin), so a
loopback SPA dev server's own JS modules were cancelled and the page rendered
blank.

Add resolveRequestingFrameLocalOriginKey: prefer the frame origin, and for a
top frame with a blank origin fall back to the frame's committed URL. The
fallback is top-frame-only, so a sub-iframe presenting a blank origin still
cannot be mistaken for the trusted main frame. Use it in the onBeforeRequest
firewall.

@bb/desktop typecheck + browser policy/view-manager/main-ipc suites green
(incl. new resolver unit tests + a same-origin-SPA-subresource regression that
also asserts a blank-origin sub-iframe stays blocked).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The tab-strip useMemo body uses main's consolidated activeFixedSecondaryTabId
(plus our activeSideChatTabId); drop the now-unused granular active*Path/Id
fields from its dependency list. Those fields are still consumed elsewhere for
file-preview content, so the hook destructuring keeps them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
brsbl and others added 14 commits June 11, 2026 01:36
…nd-side-chats

# Conflicts:
#	apps/app/src/components/thread/timeline/ConversationMessageContent.tsx
#	apps/app/src/views/thread-detail/ThreadDetailView.tsx
The parent thread's prompt-context banner counted every active child thread,
including user-opened forks and side chats, so opening a side chat showed
"1 active child thread" on the main thread. Filter the banner's child list to
agent-delegated children (childOrigin === null) — the same distinction used for
parent notifications — so only delegated work the parent is waiting on appears.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the side chat's single bottom "Send to main thread" button (which always
sent the latest reply, ambiguously) with a per-message action: each side-chat
agent reply now carries a "send to main thread" icon in its action bar, so the
user hands back exactly the answer they want.

Threads a ThreadTimelineSendToMainMessageHandler from the side-chat timeline host
(SideChatTabContent) through ThreadTimelineRows → ConversationMessageContent →
MessageActionBar, mirroring the existing fork/side-chat per-message wiring. The
action is supplied only inside a side chat (the main timeline has none) and is
gated on the child being idle so a mid-stream partial can't be posted. Delivery
still uses the cross-thread senderThreadId transport. Drops the now-dead
lastAssistantText/canSendBack/bottom-button plumbing.

@bb/app typecheck + lint clean; new MessageActionBar test covers the action
rendering, firing, and that it is not gated by the fork/side-chat depth flag.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Four changes from the design discussion:

- Shared conversation-context snapshot. Generalize the side-chat snapshot into
  buildConversationContextSnapshot (fork + side-chat scopes). Its header now
  carries the parent thread id + total message count + a `bb thread show <id>`
  pointer, so a child agent can pull the full parent on demand instead of being
  limited to the bounded window. Wider default window for forks (10) than side
  chats (6).
- Seed forks with prior context. Thread the source timeline rows into
  buildForkThreadRequest and prepend an agent-only lead-up snapshot (the messages
  before the anchor; the anchor itself stays the visible seed) so a fork isn't
  amnesiac about how it reached the branch point.
- Drop the "(fork)" title suffix. Omit the title so a fork auto-titles from its
  first real turn (distinct from the source) rather than echoing the parent name.
- Hide side chats from the sidebar tree. projectThreadGroups skips
  childOrigin === "side-chat" so only forks (and agent-delegated children) nest
  there; side chats stay panel-only.

@bb/app typecheck + lint clean; new conversation-context-snapshot tests (both
scopes + the bb-thread-show pointer) and updated fork-thread-request tests green.
(projectThreadGroups.test.ts can't run locally — pre-existing @pierre/diffs
navigator load issue on main — but the filter typechecks and is exercised in CI.)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…filter

The sidebar-filter test (and 4 other node-environment test files) couldn't load:
they transitively import @pierre/diffs, which reads navigator.userAgent at module
load, and Node < 21 has no global navigator. Add a minimal navigator stub to the
shared vitest setup (only when one isn't already present, so jsdom/browser envs
are untouched).

With the file loadable again, refactor buildProjectThreadGroups to drop
childOrigin === "side-chat" threads up front (so they neither nest nor resurface
as orphan roots in the cycle-recovery pass) and add a test asserting a side chat
is excluded from the tree while a fork stays nested under its parent.

@bb/app full suite now green: 160 files / 1218 tests (previously 5 files failed to
load). Typecheck + lint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Fork threads now read "Forked from <source>" in the prompt-context banner
  (and "This thread was forked from …" in the expanded body) instead of the
  generic "Parent <source>"; driven by a new relationship: "parent" | "fork" on
  ThreadPromptParentThreadSection, set from thread.childOrigin. Also drop the
  redundant "Parent " prefix from the id-based loading fallback.
- Thread-header pill shows "fork" for forks (was always "child"); the header
  prop becomes childPillLabel: "child" | "fork" | null.
- Pill padding bumped (px-1.5 py-0 rounded-sm → px-2 py-0.5 rounded) so it reads
  like a tag rather than a tight chip.
- Stories: pill story shows the child/fork pills; banner story adds a
  "Forked from …" variant. New ThreadDetailHeader pill tests.

@bb/app typecheck + lint clean; header + banner suites green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fork threads now show a small Fork icon before their title in the sidebar tree
(thread.childOrigin === "fork"), so a fork reads as a fork at a glance alongside
its nesting under the source. Adds a "fork" row to the ThreadRow story.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A turn-backward arrow reads as "return/hand this reply back to the parent" —
truer to the action than the prior vague ArrowUpRight, and a clean pair with the
ArrowTurnForward the message renders with when it lands in the parent. Registers
the ArrowTurnBackward icon.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…d builders

The feature made childOrigin (on Thread) and startedOnBehalfOf/childOrigin (on
CreateThreadRequest) required-nullable, but main's CLI fixture, CLI spawn, and
integration request helpers — reintroduced by the catch-up merge — built those
objects without the fields, so @bb/cli and @bb/integration-tests failed
typecheck in CI (the frontend already handles this via AppCreateThreadRequest;
these typed Hono/SDK clients can't omit defaulted fields, so they pass the
explicit null a normal thread actually has).

- command-output-fixtures.makeThread: childOrigin: null
- thread spawn command + integration createHostThread/createReuseThread:
  startedOnBehalfOf: null, childOrigin: null
- update thread-spawn command-output expectations to match the request body

Root cause was only typechecking @bb/app locally; full `turbo run typecheck`
across all 32 packages is now green, as are lint and @bb/cli (226) / @bb/app
(1218) tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…llowlist

A later merge dropped the allowlist entry our own earlier fix added (commits
1a44eb0/514f807), so the contract guard test went red once typecheck stopped
masking it. Restore the documented entry for the main-inherited optional field.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- [P1] Document why CLI/integration thread builders pass explicit
  startedOnBehalfOf/childOrigin nulls (the typed $post client requires the
  schema-defaulted fields; z.input would re-optionalize the SDK arg type but the
  underlying $post still requires them, so the null lives at the call site).
- [P2] Remove the dead `windowSize` override from buildConversationContextSnapshot
  (only tests ever set it); boundary tests now exercise the real per-scope
  default windows.
- [P2] Document resolveAnchorIndex's newest-first match + the fork tail-as-anchor
  fallback + the duplicate-text limitation (mitigated by the bb-thread-show
  pointer).
- [P2] Model childOrigin "side-chat" explicitly in the detail view: a side-chat
  thread opened directly now shows a "side chat" pill and a "Side chat of …"
  banner instead of a misleading "child"/"Parent". Consolidated the banner's
  per-relationship copy into one PARENT_SECTION_COPY source of truth; added a
  side-chat pill test + banner story.

@bb/app full suite (1222) + @bb/cli typecheck + lint green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e path)

The sidebar worktree icon was GitBranch, which reads as "branch" (the same glyph
used for the branch name in env summaries) and doesn't match the info page. Point
getEnvironmentWorkspaceDisplayIconName at FolderGit (FolderGitTwoIcon): a worktree
is a git-backed folder, it matches the convention PR #86 adds to the info-page
workspace-path row, and it's clearly distinct from the fork glyph. The registry
entry is placed to match PR #86 exactly so the two branches merge cleanly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…convention

Pills are all one component with color variants (uniform padding); the only
casing outlier was the story's hard-coded "Failed". Lowercase it ("failed") to
match how real status/type pills render (the workflow-run status enum is all
lowercase; thread-type pills are child/fork/side chat). Descriptive multi-word
labels (e.g. "Invalid local path") intentionally stay sentence case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
brsbl and others added 5 commits June 16, 2026 03:37
The guide sat on the children's caret column (one step in from the parent),
which read as under-indented — it didn't line up with the parent header's
icon. Move it to the parent's glyph-center column (caret box + gap + half the
glyph box) so nested children visibly branch from the folder / no-project /
worktree icon above them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The caret box, leading gap, and glyph slot were duplicated across ThreadRow,
the project/worktree headers, and the chevron (5x glyph slot, 3x cluster,
2x caret box), and the indent-guide offset was a hand-computed 34 coupled to
all of them — so retuning any size would silently break the guide.

Centralize the geometry in sidebarRowClasses as paired class tokens + px
constants, derive the guide's glyph-center offset from the px, and have every
call site render from the tokens. Output is unchanged; the column is now one
maintainable system — edit a value here and rows + guide move together.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Threads-section rows sit at depth 0 (base pad 0), so a hovered parent's caret
background painted flush against the row's rounded left edge — clashing with
the selection corner, unlike the inset, floating caret in the Projects
section. Add a small base inset (spacing-1) so even level-0 carets clear the
row edge, and give project headers the same depth-0 padding so their folder
icons stay aligned with projectless-thread glyphs.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…guide

A fork child's leading fork glyph buffers its title from the indent guide,
but a glyph-less child (a plain child or worktree-group member) had its title
sitting ~4px off the divider — cramped. Reserve the glyph column for those
nested, glyph-less rows so their title clears the guide and lines up with a
fork sibling's title. Top-level glyph-less rows still reserve nothing (no
guide beside them), so the earlier dead-gap fix is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…h with fork icon

Replace the reserved empty glyph column with a left pad on the leading column
for rows nested under an indent guide. The fork icon (and any leading glyph)
now clears the divider with a real gap, and a glyph-less child carries the same
pad on its title so it lands flush with a fork sibling's leading icon — not a
column further right at the fork's title. Top-level rows still pad nothing.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
brsbl and others added 18 commits June 16, 2026 11:13
Each leading identity glyph now shows a styled hover tooltip naming it
("Forked thread", "Not in a project", the worktree label). The glyph is
lifted to relative z-10 so it sits above the row's absolute NavLink overlay
and actually receives the hover; the shared SidebarLeadingGlyph helper keeps
the three call sites identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The row NavLink no longer sets a `title`, so hovering a thread row no longer
pops the browser "Open <thread>" tooltip (noisy alongside the new glyph
tooltips). The aria-label is kept for screen readers.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a real parent → fork → fork chain to the Sidebar/Overview tree and a
"3 levels of ancestry" row to the Sidebar/Threads catalog so every sidebar
row type — including depth-3 nesting where the middle node carries both the
disclosure chevron and the fork glyph — has a reviewable story.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
main replaced the thread status model (created/provisioning + tryTransition +
stop_requested_at) with a five-status machine (idle/starting/active/stopping/
error) driven by logged lifecycle events. Take main's model wholesale and
re-express this PR's native-fork + side-chat seed lifecycle on top of it
(Option A in plans/thread-lifecycle-alignment.md):

- Add one cell to THREAD_LIFECYCLE: starting --run.succeeded--> idle. A start
  that establishes a thread without running a turn (a native fork cloned with
  empty input, or a seed-without-run anchor) settles its zero-work run here,
  landing idle with an empty timeline. Also closes the race where a real turn's
  turn/completed arrives before the start command settles run.started.
- Port the lazy seed-without-run path from tryTransition(idle) to firing
  run.succeeded via applyLoggedThreadLifecycleEvent; delete thread-transitions.ts.
- Keep the fork-aware failure-notification guard (isAgentDelegatedChildThread)
  over main's parentThreadId one: forks/side-chats are user-initiated branches,
  not agent-delegated sub-tasks, so a failed turn must not notify their parent.
- Renumber the child_origin migration to 0036 after main's 0033-0035.
- Reconcile test fixtures with main's dropped columns and required fork fields.

Typecheck green across domain/db/server/app/host-daemon; full suites pass
(domain 106, db 296, server 637, app 531).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Revert the sidebar's leading caret+glyph column to main's row layout while
keeping this PR's features (worktree env groups, the project-less Threads
section, side-chat filtering):

- The disclosure caret moves to the right of the title; no leading column.
- Forks render as top-level rows (not nested) and carry no fork glyph; nesting
  is reserved for delegated parent/child threads.
- Drop the project-less FolderMinus glyph; the worktree/env icon moves to the
  trailing indicator like main.
- Geometry tokens take main's values (base 8 / step 24 / offset 8); indent
  hairlines sit at pad+8. Removed the now-dead leading-column tokens.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… file

The codex thread/fork RPC params type is vendored (main's checked-in codex
app-server schema has no fork RPC). Importing it from the generated dir into
codex/adapter.ts fails to resolve on CI's clean Linux build while resolving
locally; move the type into a regular codex/ source file (reusing the generated
sibling schemas for its field types) and import that from adapter.ts. The
generated copy stays for ClientRequest.ts's RPC union.

Also reconcile the cli thread-spawn fixture with the required childOrigin /
startedOnBehalfOf request fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
# Conflicts:
#	apps/app/src/components/secondary-panel/ThreadMetadataContent.tsx
#	apps/app/src/components/thread/timeline/rows/UserMessage.stories.tsx
#	apps/app/src/views/thread-detail/threadParentSelectorOptions.test.ts
#	apps/server/src/services/scheduling/automation-sweep.ts
#	apps/server/src/services/threads/project-execution-defaults.ts
#	apps/server/src/services/threads/thread-create-request.ts
#	apps/server/test/environments/environment-provisioning.test.ts
#	apps/server/test/services/threads/project-execution-defaults.test.ts
#	packages/db/drizzle/meta/0036_snapshot.json
#	packages/db/drizzle/meta/_journal.json
#	packages/db/test/migrate.test.ts
…y-in-side-chat)

Select text in an agent timeline message to get a floating menu: Add to chat (insert the selection into the composer as an editable > blockquote to reply under) and Reply in side chat (open a side chat anchored to the selection). Quotes render as styled blockquotes across agent messages, user messages, the side-chat anchor, and queued-message previews. Entirely client-side — no server, daemon, schema, or DB changes.

Merged into otto/thread-forking-and-side-chats (stacks on PR #85), not main.
@brsbl
brsbl merged commit 6a0b0df into main Jun 17, 2026
6 checks passed
@brsbl
brsbl deleted the otto/thread-forking-and-side-chats branch June 17, 2026 07:22
ymichael added a commit that referenced this pull request Sep 15, 2026
## Root cause

The focused pane title chip cancels its own horizontal padding with
`-mx-2` so the grey surface bleeds outward without shifting the title
text. The header's center row separates its children with `gap-2`
(`apps/app/src/components/layout/AppPageHeader.tsx:90`) — exactly the
8px that the right-side bleed removes. The chip's painted right edge
therefore landed at 0px from the next sibling: the `child` / `side chat`
pill, or the actions menu button's hover box when no pill is present.

Measured in the running app before the fix: `chipRight: 1028, pillLeft:
1028`.

This is not a recent regression. The focused-pane title surface arrived
in 4422445 (#682, 2026-07-14) as an absolutely-positioned overlay
with `-inset-x-2`, which produced the same flush edge; dbdcc20 (#934,
2026-08-01) rewrote the technique to padding plus negative margin and
faithfully reproduced the same offsets. The pill (#85) and the row's
`gap-2` both predate the surface, so the collision existed from the
surface's first commit.

It stayed unnoticed because the surface only paints on the *focused*
pane, only in a split, and is only visibly flush when the thread carries
a `child` / `side chat` pill — without a pill the neighbour is the
actions button, which is transparent until hover.

## Change

Keep the left bleed, which is load-bearing (it aligns the title text
with the header's `px-4`), and drop the right bleed so the row gap
survives. Applied to both headers that share the chip pattern:

- `apps/app/src/views/thread-detail/ThreadDetailHeader.tsx:164`
- `apps/app/src/views/thread-detail/SplitThreadArea.tsx:1134`

## Verification

Drove a real dev instance with a parent thread, a child thread (so the
`child` pill renders), and a new-thread pane, arranged as three split
panes, and measured the live DOM:

| | chip `margin-right` | gap to next sibling |
| --- | --- | --- |
| before | `-8px` | **0px** |
| after | `0px` | **8px** |

All three pane-header variants (thread, child-pill thread, new-thread
pane) report `margin-right: 0px` and an 8px gap after the change, with
the title text position unchanged (`margin-left` stays `-8px`).

Checks: `pnpm exec turbo run typecheck lint test
--filter='...[origin/main]'` — 533 test files, 4675 passed / 3 skipped,
0 lint errors, exit 0.

> AGENT GENERATED

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ymichael added a commit that referenced this pull request Dec 1, 2026
## Human comments

## What was wrong

`slots.messageAction` had no way to say which messages an action works
on, so every plugin action showed on every user and assistant message.
Conductor's "Fork to new workspace" and Side chat's "Reply in side chat"
showed on user messages, and Conductor's fork also showed on threads
that cannot fork. `ThreadChatProps.messageActions` was a second shape
for the same thing, with `roles` and a `run(message)` that got no
thread, panel, composer or selection. bb's own Copy, Edit, Copy link,
Add to chat and Fork could not have been built on the slot: they were
hand-wired into `MessageActionBar` and `TimelineSelectionMenu` with
their own role rules, availability, streaming state and placement. This
closes audit finding a-thread F4 and core-contributions rank 10.

## What changed

Message actions now use the model thread actions already use: an
optional `useData` hook per timeline, and a pure `item` per message that
returns the action or null. bb's five actions are ordinary registrations
on that model, using only the public SDK.

**Slot contract** (`packages/plugin-sdk/src/app-contract.ts`, SDK
0.6.215):

- `PluginMessageActionRegistration<Data>` adds:
- `experimental_useData?({ threadId }): Data`. A React hook bb calls
once per mounted timeline with that timeline's thread, never per
message. Plugins read thread facts there with `experimental_useThread`
and return only what `item` needs.
- `experimental_item?(input)`: pure and synchronous, called per message
while rendering. Returns null or `{ label, icon?, disabled?, run({
invokedFrom, confirm }) }`.
- `experimental_selectionItem?(input)`: the same for text selected in an
assistant message. Its input adds `selection: { text, markdown }`.
  - `experimental_placement?: "inline" | "menu"` (default `"inline"`).
- `experimental_group?: string` and `experimental_order?: number`. The
row, its overflow menu and the selection menu sort by group (string
compare; unset sorts after every group), then order within the group
(ascending; unset last), then registration order with bb's own first:
the rule thread actions use with `group` and `order`.
`experimental_MESSAGE_ACTION_GROUPS` exports bb's groups: `copy` (Copy
link 10, Copy 20), `edit` (Edit 10), `compose` (Add to chat 10, row menu
and selection menu) and `branch` (Fork 10). The group is optional,
unlike other slots', because `slots.messageAction` is stable and its
run-only form predates groups. Groups only order actions; the menus draw
no separator.
- `run` returns `void` like every other plugin action. Calling
`confirm()` shows a check mark on the inline button for 2 s; it does
nothing from a menu. bb's Copy calls it after a successful copy.
- The item input (`ExperimentalMessageActionItemInput<Data>`) is the
callback context plus `message`, `requestEdit` and `data`. `composer` is
the composer of the message's thread on this surface. `requestEdit`
opens bb's inline sent-message editor and is null where bb would not
offer Edit. There are no fork flags: a fork action computes its
availability in `useData`.
- The original run-only form (`{ id, title, icon?,
experimental_surfaces?, run }`) still works and shows where it always
did. A registration mixing `run` with `item` or `selectionItem` fails
registration.
- New `experimental_appendQuoteToDraft(draft, text, attachments?)` on
`@get-bb/plugin-sdk/app`: bb's Add to chat quoting, pure, for
`composer.replace`. Its implementation moved from client-core into the
SDK's composer draft transforms. bb's message Add to chat, the diff,
file-preview and terminal Add to chat, root compose's quote, the retired
`composer.addQuote` and the test harness all run that one copy.
- `ThreadChatMessageReference` adds `experimental_settled`,
`experimental_attachments` (`ComposerAttachment[]`) and
`experimental_imageUrls`. `ExperimentalClipboardContent` adds
`imageUrl`, copied through bb's own image clipboard writer.
- `ThreadChatProps.experimental_messageActions` takes item-form
registrations (without `experimental_surfaces` or
`experimental_useData`) for one embedded chat.
- `ThreadChatProps.messageActions` and `ThreadChatMessageAction` are
removed from the types, docs and test harness. Compiled plugins that
still pass the prop keep working: `PluginThreadChat` adapts each entry
into an inline item that returns null outside its roles, and warns once
per plugin.

**Core on the shared path:**

- `apps/app/src/core-contributions/message-actions.ts` registers Copy
link, Copy, Edit, Add to chat (row menu), Add to chat (selection menu)
and Fork through `definePluginApp`, with public SDK imports only.
- Add to chat is `composer.replace((d) =>
experimental_appendQuoteToDraft(d, text, attachments))`, then
`composer.focus()`.
- Fork's `useData` reads `experimental_useThread` and
`experimental_useProviders` and returns whether the thread has an
environment, is not archived and its provider supports forking. Its
`item` offers Fork on assistant messages when that is true and the
surface has a composer. Running it is `sdk.threads.fork({
sourceThreadId, sourceSeqEnd, origin: "app" })` then
`navigate.toThread`, once per click, with bb's error toast on failure.
It replaces `useForkThreadFromMessage` and client-core's
`isThreadForkable`.
- `MessageActionCollectors` (`apps/app/src/components/plugin/`) runs
each registration's `useData` for the timeline. `ThreadTimelineRows`
holds the values and passes them through a context. Rows hand
`MessageActionBar` their action source, and the bar resolves its own
actions. So a new `useData` value re-renders the action bars, not the
message content.
- `lib/plugin-message-actions.ts` `buildMessageActions` resolves items,
placement and order for the row and the selection menu.
`MessageActionBar` and `TimelineSelectionMenu` render only that list.
`TimelineSelectionMenu` keeps its `onAddToChat` path for the diff,
file-preview and terminal selection menus, which are not message
actions.
- `ConversationMessageContent`, `ThreadTimelineRows`,
`ThreadTimelineSurface`, `ThreadScreen`, `ThreadDetailView` and
`PluginThreadChat` drop the per-action props and the `canFork` /
`canSpawnChild` plumbing.
- The plugin-bound `sdk.threads.fork` puts the new thread in the app's
cache before the caller navigates, as bb's button did. It imports the
thread cache owner on demand to keep it out of the boot payload.
- bb's message action registrations load with the timeline, as bb's
hand-wired actions did on main: `useSurfaceMessageActionSlots`
(`lib/message-action-surface.tsx`) puts them ahead of the plugin slots
instead of the plugin slot store collecting them at boot.
`experimental_useProviders` also moves from `plugin-sdk-hooks.ts` into
its own `provider-directory-state.ts`; importing it from
`plugin-sdk-hooks.ts` had pulled that whole module and its imports into
the boot payload (32 KB raw over main).

**Server fork changes (every caller of `POST /api/v1/threads/fork`):**

- A fork takes the model and reasoning level chosen in the source's
model picker, falling back to its last turn's (`thread-fork.ts` resolves
the source's next-turn execution plan).
- A visible fork goes into the source's section, and is pinned if the
source is. A hidden fork, such as Side chat's, gets neither, because it
has no place in the sidebar. Before, only bb's button copied section and
pin, so Conductor, the SDK and `bb thread fork` now do too.
- A thread at the nesting limit can be forked. #85 ran the child-nesting
depth check on fork sources so that forks and side chats would "consume
the same spawn allowance" as `canSpawnChild`. But a fork has no parent,
so it never deepens the tree. An agent at the limit can already create
top-level threads with `bb thread spawn`. The check only stopped bb's
Fork, Side chat and Conductor working in threads four levels deep. The
other source checks (missing, other project, archived, deleted) stay.

**Queued-message edit:** message actions get the composer of the
message's own thread on that surface, including the inline editor of one
of its queued messages while that is open. So during a queued-message
edit, Add to chat quotes into that edit instead of the main draft.
Before, it disappeared while the edit was open.

**First-party callers:**

- Side chat: "Reply in side chat" is an assistant-only `item` and
`selectionItem`. "Send to main thread" moves to
`experimental_messageActions`.
- Conductor: "Fork to new workspace" is an assistant-only `item`, with
the same fork check as bb's Fork in its own `useData`. Its `run` reads
the source thread with `sdk.threads.get`.
- Both raise `engines.bbPluginSdk` to `>=0.6.215`.

**Docs:**

- `docs/api_to_audit.md`: the message-action entry (contract, core and
plugin callers, the fork and Add to chat paths, the retired prop, audit
questions) and a new `experimental_appendQuoteToDraft` entry.
- The Plugin Guide message-actions card
(`plugins/plugin-api-docs/src/surfaces.ts`).
- The bb-plugin-authoring references `frontend-renderer-slots.md` and
`frontend-components.md`.
- The `bb thread fork` guide describes the model, section and pin a fork
takes.

**Visible differences from main:**

- Plugin actions now show only on the messages their `item` returns an
action for. Side chat and Conductor are assistant-only, and Conductor's
fork is hidden where the thread cannot fork.
- Inline Edit and plugin buttons share Copy's hover transition and
`focus-visible` opacity, because Copy is now an ordinary action button.
No positions move.
- bb's Fork is no longer greyed out in threads at the nesting limit; it
works there.
- Forks from the CLI, SDK and plugins follow the source's picker choice,
section and pin (above).
- Add to chat during a queued-message edit quotes into that edit
(above).
- The message "…" menu is non-modal, as thread action menus are. On main
its focus trap pulled focus back from the composer that Add to chat had
just focused, so focus fell to the page when the menu closed; now it
stays in the composer, as it does from the selection menu.

**Community callers (not edited):**

- `slots.messageAction` in the run-only form: brsbl timeline-comments;
vburojevic handoff and linear; rebryk bookmarks; and about 20 more in
the corpus. All keep today's behavior.
- `ThreadChatProps.messageActions`: brsbl desktop, robdodson
side-chat-links, xMinor-1 sticker-note, cristoslc focus-board and
anirudhranganath thread-tabs. Their compiled code keeps working through
the adapter and gets a one-time warning; rebuilding against SDK 0.6.215
needs `experimental_messageActions`.

## How you verified

- New or changed tests that fail on main:
  - `ThreadTimelineRows.actions.test.tsx`:
- `item` runs per message with that message's input; its action runs
with `invokedFrom` and `confirm`, and `confirm()` turns the inline
button into a check mark
- `useData` runs once for the timeline with its `threadId`; items
re-evaluate when its value changes, and it unsubscribes on unmount
- bb's Fork is offered only with a composer, on an unarchived thread
with an environment whose provider can fork
- bb's Fork calls `sdk.threads.fork` once at a time; a rejected fork
stays on the source and can be retried, and the retry opens the fork
    - inline order and menu placement of plugin actions among bb's own
- a selection-only action after bb's Add to chat, with the selection's
Markdown
- `experimental_messageActions` with the full item input, and retired
`messageActions` filtered by role
- message actions get only their own thread's composer, including its
queued-message editor
- Add to chat (row, for user and assistant messages with files, and
selection) writes the quote into the draft and focuses the composer
- `MessageActionBar.test.tsx`: an inline run that confirms shows a check
mark and ignores clicks meanwhile; the menu invocation and disabled
rows. Both check-mark tests fail if the bar stops passing `confirm`.
- `MessageActionBar.test.tsx`: a menu row whose `run` focuses another
element keeps that focus after the menu closes; fails with the modal
menu (focus ends on `<body>`).
- `plugin-app-message-action.test.ts`: defaults and validation for the
item form.
- `public-thread-fork.test.ts`: a fork takes the source's picker model
and reasoning over its last turn's. A visible fork takes the source's
section and pin and a hidden fork takes neither; the hidden half fails
on the previous route with `expected 'sec_…' to be null`.
- `thread-create-seed-without-run.test.ts`: a thread at the nesting
limit forks into a top-level thread.
- `plugin-bound-sdk.test.ts`: a plugin fork is in the thread cache
before the caller navigates.
- `PluginThreadChat.test.tsx`: a retired `messageActions` list still
runs and warns once.
- The existing row-isolation guard
(`ThreadTimelineRows.row-isolation.test.tsx`) still sees each row render
once on mount with per-timeline `useData`.
- After rebasing on `a6e31224a29`:
- `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`: 167
of 167 tasks pass.
- Tests pass for app (7553), plugin SDK (512), Plugin Guide cards (76),
Plugin Guide skill docs (15), Conductor (30) and Side chat (27).
- `public-thread-fork.test.ts` and
`thread-create-seed-without-run.test.ts`: 62 of 62 pass. Locally both
files still fail at teardown on main's query-plan guard bug (below);
with CI's `BB_QUERY_PLAN_EXECUTED` set they pass.
- On the previous base (`5be1d105359`), `pnpm exec turbo run test
--filter='...[origin/main]'` passed apart from two causes unrelated to
this branch:
- `isThreadQueueAutoSendPaused` (from #8367) trips the query-plan guard
at file teardown in local runs only: the guard names the caller where
the statement runs locally but where it is prepared in CI, and the
allowlist names `prepareIsThreadQueueAutoSendPaused`. A clean
`origin/main` checkout fails the same way. Every test in those files
passes.
- Timeouts and a temp-file race under the full parallel run
(`install-machine-script`, the Guide's `plugin-authoring-docs`,
storage-retention, the provider-literal ratchet, host-daemon
`injected-skills`, 3 integration files) pass when re-run alone.
- Live, on `pnpm start:worktree` with Codex turns and Side chat and
Conductor installed:
- In headed Chrome, Add to chat from the "…" menu (user and assistant
messages) and from the selection menu each leave focus in the composer
with the caret on a new line below the quote; before the menu change,
the "…" path left focus on `<body>`.
- bb's Fork into new thread from an assistant message opens the fork
("Forked from ok").
- From a pinned source in a section: Conductor's "Fork to new workspace"
creates a new worktree thread that is pinned and in that section. Side
chat's "Reply in side chat" (from two different messages) creates hidden
forks that are neither pinned nor sectioned.
- Before "Copy the source's section and pin only into visible forks", a
Side chat fork from that source came out pinned and sectioned.
- The row, menu, selection-menu and 390 px touch-drawer parity checks
from the first four commits (with real Claude Code turns) still describe
what renders; the later commits change how actions are computed, not
where they render.
- `check-bundle-budget.mjs` on a local production build of
`b6a39273c9d`: boot payload 1667.4 KB raw / 418.5 KB brotli against
main's 1665.1 / 417.8 at `a6e31224a29` (budget 1682.1 / 419.1). Against
current main the boot payload grows only by this PR's registration
validation (+2.7 KB raw), Add to chat's quoting with attachments (net
+0.55 KB), the plugin fork's cache insert (+0.65 KB) and image copy
(+0.1 KB).
- Measured on a production build with a 32-row Codex thread, sending one
turn: 80 message-row renders and 42 ms of timeline rendering. The
thread's bookkeeping updates during the turn (turn start, turn end,
mark-read) re-ran Fork's `useData` but re-rendered no rows. The branch's
earlier design, which passed the thread in the item input, did 183
renders and 113 ms on a similar turn. I did not measure main.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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