← Back to Pull requests

feat(workbench): inline handoff composer with attachments, KaTeX math, cancelled-turn text preservation, and activity-bell reveal #9698

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 01, 2026 03:01 UTC
Author

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Self-contained Workbench usability and rendering fixes targeting main (37 files under apps/workbench/).

  • Goal/source and gap: Resolves four day-to-day Workbench friction points:

  • 1. Cramped modal handoff dialog missing native composer controls & attachments: Triggering "Continue / Handoff" or "Fork" previously opened a narrow centered modal (440px) over a backdrop scrim with custom <select> dropdowns, no image paste/upload, no effort/speed controls, and no @ references — while the main thread composer already offered a full-width liquid-glass input bar with native pickers.
    2. Raw LaTeX formulas in Markdown replies and previews: Inline ($...$, \(...\)) and block ($$...$$, \[...\]) mathematical expressions rendered as literal TeX source across chat messages, file previews, and skills docs.
    3. Cancelled turns hid already-streamed prose: Stopping an active turn mid-response folded the assistant's already-generated prose into the collapsed work block instead of keeping it readable in the conversation timeline and persisted history summary.
    4. Turning off sidebar Activity Bell lost track of the active conversation: Leaving the activity filter returned to the project view without expanding collapsed project/section/done folders or folded branch drawers, leaving the currently viewed thread hidden or scrolled out of sight.
  • Observable before → after, with the validation row that proves it:

  • 1. Handoff/fork composer: Replaces ForkSubchatDialog.tsx with inline bottom HandoffComposer.tsx reusing the New Thread Composer width and native AgentPicker, WorkspacePicker, and ModelPicker (effort + speed), with direct + image attach, Cmd/Ctrl+V image paste, image-only handoffs, @ references, isolated handoff draft keys, and upfront model/effort/speed/images validation in POST /api/threads/:id/fork before worktree/thread creation (unit daemon fork-subchat.test.ts + real_entrypoint fork-subchat.spec.mjs, fork.spec.mjs, auto-handover.spec.mjs).
    2. LaTeX math rendering: Adds remark-math, rehype-katex, katex, and remarkLatexMath (markdown-math.ts) across ThreadView, FilesPanel, and SkillsPage, plus .woff2 CSP/MIME serving in http.ts. Renders inline/display formulas cleanly while preserving currency ranges ($5-$10), shell variables ($HOME/$USER), code spans, and XSS guards (unit markdown-math.test.ts + real_entrypoint Chromium KaTeX & .woff2 font verification).
    3. Cancelled-turn prose retention: Updates timeline.ts (closeTurn(endedAt, keepNotes) + mergeWorkEntries), web history.ts, ThreadView.tsx, and daemon history.ts so trailing prose produced before a cancellation stays visible as the turn summary while earlier intermediate notes remain in the work block (unit daemon history.test.ts + web history.test.ts & timeline.test.ts + real_entrypoint interrupted-work.spec.mjs).
    4. Activity Bell reveal & centering: Adds locateThreadInSidebar (sidebar.ts) and Sidebar.tsx layout reveal so toggling the Activity Bell off auto-expands any collapsed project/section/done group and folded branch drawer containing the active thread and centers it inside .sidebar-scroll (unit sidebar.test.ts + real_entrypoint sidebar.spec.mjs).
  • Issue/task and intended base: Self-contained Workbench contribution targeting main.
  • Author Declaration

  • Written by: model_agent (Antigravity / Gemini) directed and reviewed by human_operator (maxliux5).
  • Implemented against

  • Specification and revision: No external written RFC; this PR addresses the four concrete Workbench issues described above against origin/main (1bdf851e9).

  • Criteria:
  • | Criterion | Disposition | Symbol / path | Test or command |
    | --- | --- | --- | --- |
    | Inline handoff/fork composer matching New Thread geometry with native pickers, images, references, and backend validation | implemented | apps/workbench/packages/web/src/components/HandoffComposer.tsx, Composer.tsx, ThreadActions.tsx, App.tsx, fork-subchat.css, apps/workbench/packages/daemon/src/{http,threads}.ts | fork-subchat.test.ts, fork-subchat.spec.mjs, fork.spec.mjs, auto-handover.spec.mjs |
    | LaTeX math rendering with currency/shell guards, CSP font delivery, and XSS safety | implemented | apps/workbench/packages/web/src/markdown-math.ts, markdown-html.{ts,css}, ThreadView.tsx, FilesPanel.tsx, SkillsPage.tsx, apps/workbench/packages/daemon/src/http.ts | markdown-math.test.ts, Chromium built-bundle KaTeX check |
    | Keep trailing prose visible on cancelled turns across live timeline and persisted summaries | implemented | apps/workbench/packages/web/src/{timeline,history}.ts, ThreadView.tsx, apps/workbench/packages/daemon/src/history.ts | daemon history.test.ts, web {history,timeline}.test.ts, interrupted-work.spec.mjs |
    | Auto-expand collapsed group/branch and center active thread when turning off Activity Bell | implemented | apps/workbench/packages/web/src/sidebar.ts, Sidebar.tsx | web sidebar.test.ts, sidebar.spec.mjs |

  • Self-check before submission: Ran full Workbench workspace typecheck, full web unit test suite (688/688), targeted daemon unit suites (20/20), full Workbench production build, 7 Playwright E2E specs (26 passed, 1 pre-existing legacy-assistant skip), and headless Chromium KaTeX/font + desktop/phone light/dark visual inspection against the built bundle. Deliberately left unrelated sidebar badge/date work out of scope (tracked separately in #9635).
  • Scope And Continuation

  • Completed scope and remaining work: Complete within apps/workbench/. No core Python control-plane, RFC, or protocol files touched. Does not modify existing sidebar branch badge styling to stay conflict-free with #9635.

  • Slice boundary / successor: N/A — all four issues are complete and independently reversible within apps/workbench/.
  • Validation

  • Tested revision: dfdce35864d9838ef6cd78f3dbc329c1ac4d868a

  • Run state: finished

  • Input classes: synthetic, public_fixture
  • | Check kind | Result | Public-safe evidence / limitation |
    | --- | --- | --- |
    | static | passed | cd apps/workbench && npm run typecheck — passed across all 6 Workbench workspaces (0 errors). |
    | unit | passed | cd apps/workbench && npm test -w @loopx/loochat-web — 688/688 passed (markdown-math.test.ts, history.test.ts, timeline.test.ts, sidebar.test.ts, i18n.test.ts, etc.). |
    | unit | passed | cd apps/workbench && npx --prefix packages/daemon tsx --import ./packages/daemon/test/home-env.mjs --test packages/daemon/test/fork-subchat.test.ts packages/daemon/test/history.test.ts — 20/20 passed (including image/effort/non-image-model fork validation and cancelled-turn summary parity). |
    | static | passed | cd apps/workbench && npm run build — production daemon, Vite web bundle (with KaTeX CSS/woff2 assets), and extension checks passed. |
    | real_entrypoint | passed | cd apps/workbench && node --test packages/e2e/test/fork-subchat.spec.mjs packages/e2e/test/fork.spec.mjs packages/e2e/test/auto-handover.spec.mjs packages/e2e/test/sidebar.spec.mjs against the packaged build — 23/23 passed (1 pre-existing skipped test for the unshipped legacy assistant page). |
    | real_entrypoint | passed | cd apps/workbench && node --test packages/e2e/test/interrupted-work.spec.mjs packages/e2e/test/markdown-links.spec.mjs packages/e2e/test/composer-layout.spec.mjs against the packaged build — 3/3 passed. |
    | real_entrypoint | passed | Headless Chromium verification against the built Workbench daemon with synthetic fixtures confirmed inline & display KaTeX rendering (3 .katex, 1 .katex-display, 0 .katex-error), literal preservation of $5-$10 and $HOME/$USER, and 3/3 KaTeX .woff2 font responses with HTTP 200. |

  • Coverage and gaps: All changed daemon routes, timeline/history reducers, math parser/sanitizer paths, sidebar reveal logic, and inline handoff composer flows are covered by unit tests and packaged-build Playwright E2E specs. Full non-Workbench Python control-plane suites were not run because all edits are strictly under apps/workbench/.
  • Frontend / Visual Evidence

  • UI impact: changed

  • Before:

  • - Handoff/fork rendered as a 440px centered modal over a dark backdrop scrim with custom <select> controls and no image attachment or effort/speed UI.
    - LaTeX expressions in Markdown rendered as raw $...$ / $$...$$ text.
    - Turning off the sidebar Activity Bell left collapsed groups/branches closed and did not scroll to the active thread.
  • After:

  • - Inline bottom handoff composer matches the main composer's exact width (652px on 1440×900 desktop, asserted within ≤4px), preserves the native liquid-glass surface in light and dark modes with zero backdrop scrim, exposes native AgentPicker + optional WorkspacePicker + subtle mode indicator + × exit on top, spacious textarea in the middle, and direct + image attach, @ references, native ModelPicker (with effort/speed dial), and circular send button on the bottom.
    - Phone (390×844) light and dark layouts compact cleanly into single-row pickers and icon-only mode badge with zero horizontal overflow.
    - Inline ($\Delta S$, $T=30\text{–}100$) and display ($$\Delta C = \sum_{t=1}^{T} \Delta S_t$$) KaTeX math renders cleanly in both light and dark themes with bundled .woff2 fonts while leaving $5-$10 and $HOME/$USER untouched.
  • First viewport and preview: Tested at revision dfdce35864d9838ef6cd78f3dbc329c1ac4d868a against the packaged production Workbench build (npm run build) served by the real Workbench daemon in headless Chromium. Captures retained locally in git-ignored output/playwright/workbench-handoff-math-timeline-bell/ (desktop-card-{light,dark}.png, phone-card-{light,dark}.png, desktop-drawer-{light,dark}.png, phone-drawer-{light,dark}.png, desktop-math-{light,dark}.png).

  • States and viewports shown: Desktop (1440×900 & 1280×800) and phone (390×844), light and dark themes, inline handoff composer, topic drawer, and KaTeX math rendering.

  • Source data: synthetic

  • Attention review: Removes the separate modal dialog and custom form styling in favor of reusing the existing New Thread Composer pattern, hiding non-applicable project/machine/permission pickers so only decision-relevant handoff controls remain visible while keeping Escape/cancel and model capability errors one step away.

  • Craft review: Reuses existing liquid-glass surface tokens, icons (icons.tsx), Popover pickers, and theme danger tokens (var(--danger) for KaTeX parse errors) with zero new raw hex values, zero native form controls, and zero layout overlap on phone or desktop.
  • Type of Change

  • Bug fix

  • New feature

  • Breaking change

  • Refactoring (no functional changes)

  • Documentation update

  • Test update
  • LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)

  • Capability or extension (providers, adapters, skills)

  • Public docs or presentation surface (README, protocols, dashboard)

  • Build, packaging, installer, or CI

  • Host or runtime integration
  • Technical Direction

  • Direction / acceptance reference, when applicable: Operator surface and IM integration (Workbench UI & thread ergonomics).
  • Shared-authority RFC fixture impact

    N/A — changes are scoped strictly to apps/workbench/.

    Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).

  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.

  • I kept the change scoped to the linked issue/task.

  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.

  • I completed the visual evidence section for UI changes, or marked UI impact none.

  • Every commit includes a DCO Signed-off-by trailer (git commit -s).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: loopx-agent Review duration: 79m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9698"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%