-
Notifications
You must be signed in to change notification settings - Fork 110
π€ feat: coalesce consecutive file_read/file_edit tool calls in transcript #3379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ammar-agent
wants to merge
9
commits into
main
Choose a base branch
from
feat/transcript-tool-coalescing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f5d6b3
π€ feat: coalesce consecutive file_read/file_edit tool calls in transcβ¦
ammar-agent e2f85ab
tests: replace empty arrows with named no-op for lint
ammar-agent 201bf0e
feat: dedupe repeated file names from coalesced summary
ammar-agent c50c781
fix: do not coalesce a group with an interrupted member
ammar-agent c48ea47
fix: only coalesce tool groups where every member is completed and noβ¦
ammar-agent 8fba3d4
ci: re-run codex comments check after resolving stale review threads
ammar-agent 82afffe
fix(stories): wrap CoalescedToolCall stories so TooltipProvider applies
ammar-agent 26c7860
tests(stories): replace no-op CoalescedToolCall stories with real plaβ¦
ammar-agent 9caa9fd
tests(stories): add Chromatic baseline for CoalescedToolCall (+budgetβ¦
ammar-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
src/browser/features/Tools/CoalescedToolCall.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import type { ReactNode } from "react"; | ||
| import { useState } from "react"; | ||
| import { expect, userEvent, waitFor, within } from "@storybook/test"; | ||
|
|
||
| import { CoalescedToolCall } from "@/browser/features/Tools/CoalescedToolCall"; | ||
| import { CHROMATIC_DISABLED, lightweightMeta } from "@/browser/stories/meta.js"; | ||
|
|
||
| /** | ||
| * Layout shell rendered inside each story so the meta-level decorator | ||
| * stack (which provides `TooltipProvider` via `StoryUiShell`) is not | ||
| * shadowed by a story-local `decorators` override. | ||
| */ | ||
| function StoryLayout(props: { children: ReactNode }) { | ||
| return ( | ||
| <div className="bg-background p-6"> | ||
| <div className="w-full max-w-3xl">{props.children}</div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Interactive wrapper that owns the expansion state so play functions can | ||
| * exercise the real click-to-expand / click-to-collapse UX. The static | ||
| * `expanded` prop on stories is treated as the initial state. | ||
| */ | ||
| function InteractiveCoalesced( | ||
| args: React.ComponentProps<typeof CoalescedToolCall> | ||
| ): React.ReactElement { | ||
| const [expanded, setExpanded] = useState(args.expanded); | ||
| return ( | ||
| <StoryLayout> | ||
| <CoalescedToolCall | ||
| kind={args.kind} | ||
| filePaths={args.filePaths} | ||
| expanded={expanded} | ||
| onToggle={() => setExpanded((prev) => !prev)} | ||
| /> | ||
| </StoryLayout> | ||
| ); | ||
| } | ||
|
|
||
| // Chromatic visual coverage is intentionally disabled β the global snapshot | ||
| // budget is tight, and the meaningful surface (header copy, click toggle, | ||
| // dedupe, kind verb) is exercised here via `play` functions that run under | ||
| // `test-storybook` in CI. | ||
| const meta = { | ||
| ...lightweightMeta, | ||
| title: "App/Chat/Tools/CoalescedToolCall", | ||
| component: CoalescedToolCall, | ||
| parameters: { | ||
| ...lightweightMeta.parameters, | ||
| chromatic: CHROMATIC_DISABLED, | ||
| }, | ||
| render: (args) => <InteractiveCoalesced {...args} />, | ||
| } satisfies Meta<typeof CoalescedToolCall>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| const NOOP = () => undefined; | ||
|
|
||
| // Storybook's test runner uses the document body as the canvas root in some | ||
| // configurations. Querying the body ensures we still find rendered content | ||
| // when the decorator stack inserts wrappers above the story root. | ||
| function getCanvas(canvasElement: HTMLElement) { | ||
| return within(canvasElement.ownerDocument.body); | ||
| } | ||
|
|
||
| /** | ||
| * Two consecutive file_read calls coalesce into a "Read files β¦" row. The | ||
| * play function clicks it and verifies it toggles to expanded. | ||
| */ | ||
| export const TwoReadsClickToExpand: Story = { | ||
| args: { | ||
| kind: "file_read", | ||
| filePaths: ["src/App.tsx", "src/main.ts"], | ||
| expanded: false, | ||
| onToggle: NOOP, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = getCanvas(canvasElement); | ||
|
|
||
| // Header copy: past-tense verb + plural noun + joined paths. | ||
| const summary = await canvas.findByText(/Read files/); | ||
| await expect(canvas.findByText("src/App.tsx, src/main.ts")).resolves.toBeTruthy(); | ||
|
|
||
| // Toggle starts collapsed, then expanded after a click. | ||
| const header = summary.closest("[aria-expanded]"); | ||
| if (!(header instanceof HTMLElement)) { | ||
| throw new Error("Coalesce header missing aria-expanded element"); | ||
| } | ||
| await expect(header).toHaveAttribute("aria-expanded", "false"); | ||
| await userEvent.click(header); | ||
| await waitFor(() => expect(header).toHaveAttribute("aria-expanded", "true")); | ||
|
|
||
| // Clicking again collapses; covers both branches of the toggle. | ||
| await userEvent.click(header); | ||
| await waitFor(() => expect(header).toHaveAttribute("aria-expanded", "false")); | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * A burst of five reads β exercises the joined-paths layout and the icon | ||
| * column hugging the leading path. | ||
| */ | ||
| export const ManyReads: Story = { | ||
| args: { | ||
| kind: "file_read", | ||
| filePaths: [ | ||
| "src/App.tsx", | ||
| "src/main.ts", | ||
| "src/preload.ts", | ||
| "src/config.ts", | ||
| "src/browser/features/Tools/CoalescedToolCall.tsx", | ||
| ], | ||
| expanded: false, | ||
| onToggle: NOOP, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = getCanvas(canvasElement); | ||
| await canvas.findByText(/Read files/); | ||
| // All five paths render in chronological order, joined by ", ". | ||
| await expect( | ||
| canvas.findByText( | ||
| "src/App.tsx, src/main.ts, src/preload.ts, src/config.ts, src/browser/features/Tools/CoalescedToolCall.tsx" | ||
| ) | ||
| ).resolves.toBeTruthy(); | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * file_edit groups use the past-tense "Wrote" verb. Mirrors the canonical | ||
| * file-edit icon variant. | ||
| */ | ||
| export const TwoEdits: Story = { | ||
| args: { | ||
| kind: "file_edit", | ||
| filePaths: ["src/App.tsx", "src/main.ts"], | ||
| expanded: false, | ||
| onToggle: NOOP, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = getCanvas(canvasElement); | ||
| await canvas.findByText(/Wrote files/); | ||
| await expect(canvas.findByText("src/App.tsx, src/main.ts")).resolves.toBeTruthy(); | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * Display-only dedupe: a burst that touches the same file repeatedly should | ||
| * still render it once. Verifies the React.useMemo dedupe path in | ||
| * `CoalescedToolCall`. | ||
| */ | ||
| export const DeduplicatedPaths: Story = { | ||
| args: { | ||
| kind: "file_edit", | ||
| // 5 raw calls; 3 unique files. First-occurrence order: a, b, c. | ||
| filePaths: ["src/a.ts", "src/b.ts", "src/a.ts", "src/c.ts", "src/b.ts"], | ||
| expanded: false, | ||
| onToggle: NOOP, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = getCanvas(canvasElement); | ||
| await canvas.findByText(/Wrote files/); | ||
|
|
||
| // Each unique path appears exactly once in the joined list, in | ||
| // first-occurrence order. Asserting on the exact string is the simplest | ||
| // way to express both the order and the dedupe simultaneously. | ||
| await expect(canvas.findByText("src/a.ts, src/b.ts, src/c.ts")).resolves.toBeTruthy(); | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * Expanded state β verifies aria-expanded reflects the initial prop and the | ||
| * chevron indicator rotates. | ||
| */ | ||
| export const InitiallyExpanded: Story = { | ||
| args: { | ||
| kind: "file_read", | ||
| filePaths: ["src/App.tsx", "src/main.ts", "src/preload.ts"], | ||
| expanded: true, | ||
| onToggle: NOOP, | ||
| }, | ||
| play: async ({ canvasElement }) => { | ||
| const canvas = getCanvas(canvasElement); | ||
| const summary = await canvas.findByText(/Read files/); | ||
| const header = summary.closest("[aria-expanded]"); | ||
| if (!(header instanceof HTMLElement)) { | ||
| throw new Error("Coalesce header missing aria-expanded element"); | ||
| } | ||
| await expect(header).toHaveAttribute("aria-expanded", "true"); | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.