mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 21:49:18 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The task detail view uses a chat-style thread: agent turns, activity phases, and a message composer. > - A colleague's UX review found three defects: the composer draft stayed visible after send, disclosure carets in turns and status pills were misaligned, and the composer was not horizontally aligned with the thread column. > - These defects make the chat surface feel unpolished and cause confusion about whether a message was sent. > - This pull request fixes all three defects with small, targeted UI changes and adds regression tests for each. > - The benefit is a chat surface that behaves and aligns like users expect from a messaging UI. ## Linked Issues or Issue Description No public GitHub issue exists for this. Description of the underlying problems: **What happened?** Three UI defects in the chat-style task view: 1. After a user pressed send, the composer kept the draft text until the server round-trip finished. Fast typers could see stale text and doubt the message was sent. 2. The disclosure carets on collapsed agent turns and the caret inside the status pill did not share one alignment axis. They rendered at different x-offsets and sizes. 3. The composer container had different horizontal padding than the thread column above it, so the input box did not line up with the message bubbles. **Expected behavior** The composer clears the instant a send starts. All disclosure carets sit on one vertical axis with one size. The composer's left and right edges align with the thread column. **Steps to reproduce** Open any task in the chat-style task view. Type a message and press Enter — watch the composer text. Collapse and expand agent turns — compare caret positions. Compare the composer's horizontal edges with the message bubbles above it. ## What Changed - `TaskChatComposer.tsx`: clear the draft synchronously when a send starts instead of after the request resolves; restore the draft if the send fails. - `TaskChatTurn.tsx` and `TaskChatStatusPill.tsx`: use one shared caret alignment (size, x-offset) for turn disclosure and status pill carets, with supporting utility styles in `ui/src/index.css`. - `TaskChatThread.tsx`: align the composer container with the thread column padding. - Added or updated unit tests in `TaskChatComposer.test.tsx`, `TaskChatTurn.test.tsx`, `TaskChatActivityPhase.test.tsx`, and `TaskChatThread.test.tsx`. ## Verification - Run `pnpm vitest run src/components/task-chat/TaskChatComposer.test.tsx src/components/task-chat/TaskChatActivityPhase.test.tsx src/components/task-chat/TaskChatTurn.test.tsx src/components/TaskChatThread.test.tsx` in `ui/` — 4 files, 64 tests, all pass. - Manual: open a task in the chat view, send a message, and confirm the composer clears immediately. Collapse/expand turns and confirm the carets align. Compare composer edges with the thread column; the alignment fixes were also pixel-verified with screenshots during local review. ## Risks - Low risk. All changes are render-layer only; no server or data changes. - The composer now clears optimistically. If a send fails, the draft is restored, so no user text is lost. - Caret alignment uses shared CSS utilities; visual regressions would show in the existing component tests and in any screenshot diff. ## Model Used - Implementation: OpenAI Codex CLI coding agent (Codex model family, agentic tool use) via Paperclip's Codex adapter. - Review, verification, rebase, and PR preparation: Anthropic Claude, model id `claude-fable-5` (extended thinking, tool use), via Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
149 lines
6.7 KiB
TypeScript
149 lines
6.7 KiB
TypeScript
import { useState, type ReactNode } from "react";
|
||
import { cn } from "@/lib/utils";
|
||
import { Check, ChevronRight, X } from "lucide-react";
|
||
import type { TaskChatTurnItem, TaskChatTurnChildItem } from "./task-chat-model";
|
||
import { TaskChatStatusPill } from "./TaskChatStatusPill";
|
||
|
||
interface TaskChatTurnProps {
|
||
item: TaskChatTurnItem;
|
||
renderChild: (child: TaskChatTurnChildItem) => ReactNode;
|
||
/**
|
||
* When the settled turn is attached to its reply bubble (round 9), the
|
||
* bubble's timestamp leads the summary line — "2:34 PM · ✓ Worked · 38s" —
|
||
* always visible, in the slot the hover-only timestamp used to occupy.
|
||
*/
|
||
timestampPrefix?: string;
|
||
/**
|
||
* Content rendered on the header row, leading the summary line (PAP-413: the
|
||
* copy/👍/👎 action cluster). It sits beside the summary button — NOT inside
|
||
* the expandable fold — so it stays anchored to the summary line when the
|
||
* tool history expands beneath it, instead of drifting to the fold's center.
|
||
*/
|
||
leading?: ReactNode;
|
||
}
|
||
|
||
/** Metric segments after the label: "38s · 3 tools · +34 −3 · 12.3k tokens". */
|
||
export function turnSummaryMetrics(summary: TaskChatTurnItem["summary"]): string {
|
||
const parts: string[] = [];
|
||
if (summary.durationLabel) parts.push(summary.durationLabel);
|
||
if (summary.toolCount > 0) parts.push(`${summary.toolCount} tool${summary.toolCount === 1 ? "" : "s"}`);
|
||
if (summary.added > 0 || summary.removed > 0) parts.push(`+${summary.added} −${summary.removed}`);
|
||
if (summary.tokensLabel) parts.push(summary.tokensLabel);
|
||
return parts.join(" · ");
|
||
}
|
||
|
||
/** "✓ Worked · 38s · 3 tools · +34 −3 · 12.3k tokens" (parts omitted when unknown). */
|
||
export function turnSummaryText(summary: TaskChatTurnItem["summary"]): string {
|
||
const metrics = turnSummaryMetrics(summary);
|
||
const label = summary.failed ? "Stopped" : "Worked";
|
||
return metrics ? `${label} · ${metrics}` : label;
|
||
}
|
||
|
||
/**
|
||
* One agent turn's activity behind a single expandable header row.
|
||
*
|
||
* While the turn is live and carries `liveStatus`, that status line (whimsy or
|
||
* taxonomy gerund + elapsed + tokens) IS the turn: one parent row, collapsed
|
||
* by default, owning all activity (PAP-354). Expanding nests the chronological
|
||
* tool/thinking history underneath — each row keeping its own expand — and new
|
||
* rows append live while open. On settle the header morphs in place into the
|
||
* "✓ Worked · …" summary, preserving the expand state, so the running line
|
||
* reads as being replaced by the summary in the same slot.
|
||
*
|
||
* Both directions of the fold reuse the .tc-turn-fold grid-rows motion
|
||
* (--motion-turn-fold, zeroed under prefers-reduced-motion). The fold class
|
||
* only transitions on state CHANGE, so first paint in the folded state (e.g. a
|
||
* turn that loads already settled) never animates. A live turn without
|
||
* `liveStatus` (harness fixtures) renders its children expanded with no header
|
||
* and folds when it settles.
|
||
*/
|
||
export function TaskChatTurn({ item, renderChild, timestampPrefix, leading }: TaskChatTurnProps) {
|
||
const parentRow = !item.settled && item.liveStatus != null;
|
||
// Parent-row live turns and settled turns start as their one-line header;
|
||
// only the headerless legacy live turn starts expanded.
|
||
const [open, setOpen] = useState(() => !item.settled && item.liveStatus == null);
|
||
const [prevSettled, setPrevSettled] = useState(item.settled);
|
||
const [wasParentRow, setWasParentRow] = useState(parentRow);
|
||
|
||
// Render-adjusted state (not effects) so transitions land in the same
|
||
// commit — no flash of the wrong fold state.
|
||
if (parentRow && !wasParentRow) setWasParentRow(true);
|
||
// Live → settled while mounted: a parent-row turn keeps its expand state
|
||
// (the header morphs in place); a headerless expanded turn folds (animated
|
||
// via CSS unless reduced motion).
|
||
if (item.settled !== prevSettled) {
|
||
setPrevSettled(item.settled);
|
||
if (item.settled && !wasParentRow) setOpen(false);
|
||
}
|
||
|
||
const expandable = item.items.length > 0;
|
||
const folded = (item.settled || parentRow) && !open;
|
||
const SummaryIcon = item.summary.failed ? X : Check;
|
||
|
||
const header = item.settled ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => setOpen((o) => !o)}
|
||
aria-expanded={open}
|
||
className="group flex items-center gap-2 px-1 py-0.5 text-xs text-muted-foreground transition-colors hover:text-foreground"
|
||
data-testid="task-chat-turn-summary"
|
||
>
|
||
<ChevronRight className={cn("h-3 w-3 shrink-0 transition-transform", open ? "rotate-90" : null)} aria-hidden />
|
||
{timestampPrefix ? (
|
||
<>
|
||
<span className="text-(length:--text-micro)">{timestampPrefix}</span>
|
||
<span aria-hidden className="text-(length:--text-micro)">·</span>
|
||
</>
|
||
) : null}
|
||
<SummaryIcon className="h-3.5 w-3.5 shrink-0" />
|
||
<span>{item.summary.failed ? "Stopped" : "Worked"}</span>
|
||
{turnSummaryMetrics(item.summary) ? (
|
||
// Time/tools/tokens is demoted, not deleted (PAP-502): it stays in the
|
||
// DOM (and the accessible tree) but fades in only on hover/focus so the
|
||
// settled line reads as "2:34 PM · ✓ Worked" at rest. Revealed too when
|
||
// the fold is open, so the metrics don't vanish while you read below.
|
||
<span className="tc-turn-metrics" data-visible={open ? "true" : "false"}>
|
||
<span className="min-w-0 overflow-hidden whitespace-nowrap font-mono text-(length:--text-micro)">
|
||
{turnSummaryMetrics(item.summary)}
|
||
</span>
|
||
</span>
|
||
) : null}
|
||
</button>
|
||
) : parentRow ? (
|
||
// The pill renders the expand button itself, wrapped around only the
|
||
// gerund status line — the interstitial row above stays outside the
|
||
// hover/click target (PAP-376). Without activity there is no
|
||
// chevron/button.
|
||
<TaskChatStatusPill
|
||
item={item.liveStatus!}
|
||
chevronOpen={expandable ? open : undefined}
|
||
onToggle={expandable ? () => setOpen((o) => !o) : undefined}
|
||
/>
|
||
) : null;
|
||
|
||
return (
|
||
<div data-testid="task-chat-turn" data-settled={item.settled ? "true" : "false"}>
|
||
{leading ? (
|
||
// Actions ride the header row (items-center matches them to the summary
|
||
// line), and the fold below is a separate sibling — so expanding the
|
||
// tool history never moves the actions off the summary line (PAP-413).
|
||
<div className="flex items-center gap-1">
|
||
{leading}
|
||
{header}
|
||
</div>
|
||
) : (
|
||
header
|
||
)}
|
||
<div className="tc-turn-fold" data-folded={folded ? "true" : "false"} aria-hidden={folded}>
|
||
<div>
|
||
<div className="flex flex-col gap-2 pt-1">
|
||
{item.items.map((child) => (
|
||
<div key={child.id}>{renderChild(child)}</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|