forked from multica-ai/multica
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: detailed agent operation tracking with diff and command output #48
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
wsrer
wants to merge
18
commits into
furtherref:main
Choose a base branch
from
wsrer:feature/agent-operation-tracking
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
18 commits
Select commit
Hold shift + click to select a range
975f358
feat: add configurable agent execution working directory
wsrer e8d8e19
Merge branch 'furtherref:main' into main
wsrer 66b69d7
Revert "feat: add configurable agent execution working directory"
wsrer 3493ecf
feat: detailed agent operation tracking with diff and command output
wsrer 58e4dc7
fix: add i18n keys for command output and diff viewer components
wsrer c90fc63
fix(views): use theme-aware colors for CommandOutput and DiffViewer
wsrer 70ae2f6
Revert "fix(views): use theme-aware colors for CommandOutput and Diff…
wsrer 4caf1c8
Revert "fix: add i18n keys for command output and diff viewer compone…
wsrer 01d73af
Revert "feat: detailed agent operation tracking with diff and command…
wsrer cc35956
feat(transcript): restore cross-agent file diff viewer with unified/s…
wsrer 7025fab
fix(transcript): render new-file header-only diffs as file changes
wsrer 3957d4d
fix(transcript): render tool_use diffs and restore diff mode toggle
wsrer 86b2738
fix(tests): align AgentTask fixture with current type
wsrer c43147b
fix(views): address transcript diff review issues
wsrer ca4b166
test(views): isolate transcript dialog avatar dependency
wsrer f2d3786
fix(views): handle trailing newline in transcript diffs
wsrer 4d55198
fix(transcript): preserve safe diff rendering
wsrer 58fedd9
fix(agent): preserve diff snapshots and whitespace
wsrer 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
194 changes: 194 additions & 0 deletions
194
packages/views/common/task-transcript/agent-transcript-dialog.test.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,194 @@ | ||
| import { type ReactNode } from "react"; | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { I18nProvider } from "@multica/core/i18n/react"; | ||
| import enCommon from "../../locales/en/common.json"; | ||
| import enAgents from "../../locales/en/agents.json"; | ||
| import { AgentTranscriptDialog } from "./agent-transcript-dialog"; | ||
| import type { TimelineItem } from "./build-timeline"; | ||
| import type { AgentTask } from "@multica/core/types/agent"; | ||
|
|
||
| vi.mock("@multica/core/api", () => ({ | ||
| api: { | ||
| getAgent: vi.fn().mockResolvedValue(null), | ||
| listRuntimes: vi.fn().mockResolvedValue([]), | ||
| }, | ||
| })); | ||
| vi.mock("@multica/core/hooks", () => ({ | ||
| useWorkspaceId: () => "ws-1", | ||
| useCurrentWorkspace: () => ({ id: "ws-1", name: "Test WS", slug: "test" }), | ||
| })); | ||
|
|
||
| vi.mock("../actor-avatar", () => ({ | ||
| ActorAvatar: () => <span data-testid="actor-avatar" />, | ||
| })); | ||
|
|
||
| const TEST_RESOURCES = { | ||
| en: { | ||
| common: enCommon, | ||
| agents: enAgents, | ||
| }, | ||
| }; | ||
|
|
||
| function I18nWrapper({ children }: { children: ReactNode }) { | ||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { retry: false }, | ||
| }, | ||
| }); | ||
| return ( | ||
| <QueryClientProvider client={queryClient}> | ||
| <I18nProvider locale="en" resources={TEST_RESOURCES}> | ||
| {children} | ||
| </I18nProvider> | ||
| </QueryClientProvider> | ||
| ); | ||
| } | ||
|
|
||
| function baseTask(): AgentTask { | ||
| return { | ||
| id: "task-1", | ||
| agent_id: "agent-1", | ||
| runtime_id: "runtime-1", | ||
| issue_id: "issue-1", | ||
| status: "completed", | ||
| priority: 1, | ||
| created_at: "2026-05-13T00:00:00Z", | ||
| started_at: "2026-05-13T00:00:10Z", | ||
| completed_at: "2026-05-13T00:00:20Z", | ||
| dispatched_at: "2026-05-13T00:00:00Z", | ||
| result: null, | ||
| error: null, | ||
| }; | ||
| } | ||
|
|
||
| describe("AgentTranscriptDialog tool_use diff rendering", () => { | ||
| it("redacts secrets before rendering inline edit diffs", () => { | ||
| const rawSecret = "sk-proj-oldsecret1234567890abcdef"; | ||
| const items: TimelineItem[] = [ | ||
| { | ||
| seq: 1, | ||
| type: "tool_use", | ||
| tool: "edit_file", | ||
| input: { | ||
| file_path: "E:/workspace/tests/.env", | ||
| old_string: `OPENAI_API_KEY=${rawSecret}`, | ||
| new_string: "OPENAI_API_KEY=sk-proj-newsecret1234567890abcdef", | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <AgentTranscriptDialog | ||
| open={true} | ||
| onOpenChange={() => {}} | ||
| task={baseTask()} | ||
| items={items} | ||
| agentName="Claude" | ||
| />, | ||
| { wrapper: I18nWrapper }, | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText(".../tests/.env")); | ||
|
|
||
| expect(screen.queryByText(rawSecret, { exact: false })).not.toBeInTheDocument(); | ||
| expect(screen.getAllByText((content) => content.includes("[REDACTED")).length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("renders diff for create-file tool_use with content + file_path", () => { | ||
| const items: TimelineItem[] = [ | ||
| { | ||
| seq: 1, | ||
| type: "tool_use", | ||
| tool: "write_file", | ||
| input: { | ||
| file_path: "E:/workspace/tests/readme.txt", | ||
| content: "hello\nworld\n", | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <AgentTranscriptDialog | ||
| open={true} | ||
| onOpenChange={() => {}} | ||
| task={baseTask()} | ||
| items={items} | ||
| agentName="Claude" | ||
| />, | ||
| { wrapper: I18nWrapper }, | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText(".../tests/readme.txt")); | ||
|
|
||
| expect(screen.getByText("File changes")).toBeInTheDocument(); | ||
| expect(screen.getByText("--- E:/workspace/tests/readme.txt")).toBeInTheDocument(); | ||
| expect(screen.getByText("@@ -0,0 +1,2 @@")).toBeInTheDocument(); | ||
| expect(screen.getByText("+hello")).toBeInTheDocument(); | ||
| expect(screen.getByText("+world")).toBeInTheDocument(); | ||
| expect(screen.queryByText("+")).not.toBeInTheDocument(); | ||
| expect(screen.queryByText("No visual diff available for this file change.")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders diff for replace tool_use with old_string + new_string", () => { | ||
| const items: TimelineItem[] = [ | ||
| { | ||
| seq: 1, | ||
| type: "tool_use", | ||
| tool: "edit_file", | ||
| input: { | ||
| file_path: "E:/workspace/tests/hello.txt", | ||
| old_string: "before", | ||
| new_string: "after", | ||
| replace_all: false, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <AgentTranscriptDialog | ||
| open={true} | ||
| onOpenChange={() => {}} | ||
| task={baseTask()} | ||
| items={items} | ||
| agentName="Claude" | ||
| />, | ||
| { wrapper: I18nWrapper }, | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText(".../tests/hello.txt")); | ||
|
|
||
| expect(screen.getByText("File changes")).toBeInTheDocument(); | ||
| expect(screen.getByText("-before")).toBeInTheDocument(); | ||
| expect(screen.getByText("+after")).toBeInTheDocument(); | ||
| expect(screen.queryByText("No visual diff available for this file change.")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders non-diff edit tool results as text", () => { | ||
| const items: TimelineItem[] = [ | ||
| { | ||
| seq: 1, | ||
| type: "tool_result", | ||
| tool: "patch_apply", | ||
| output: "patched: src/app.ts", | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <AgentTranscriptDialog | ||
| open={true} | ||
| onOpenChange={() => {}} | ||
| task={baseTask()} | ||
| items={items} | ||
| agentName="Codex" | ||
| />, | ||
| { wrapper: I18nWrapper }, | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText("patched: src/app.ts")); | ||
|
|
||
| expect(screen.getAllByText("patched: src/app.ts").length).toBeGreaterThan(1); | ||
| expect(screen.queryByText("No visual diff available for this file change.")).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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
47 changes: 47 additions & 0 deletions
47
packages/views/common/task-transcript/build-timeline.test.ts
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,47 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { isEditTool, looksLikeUnifiedDiff } from "./build-timeline"; | ||
|
|
||
| describe("isEditTool", () => { | ||
| it("recognizes common edit tool names across backends", () => { | ||
| expect(isEditTool("patch_apply")).toBe(true); | ||
| expect(isEditTool("edit_file")).toBe(true); | ||
| expect(isEditTool("file_edit")).toBe(true); | ||
| expect(isEditTool("MultiEdit")).toBe(true); | ||
| expect(isEditTool("Write File")).toBe(true); | ||
| }); | ||
|
|
||
| it("does not classify non-edit tools as edit tools", () => { | ||
| expect(isEditTool("exec_command")).toBe(false); | ||
| expect(isEditTool("terminal")).toBe(false); | ||
| expect(isEditTool("search_files")).toBe(false); | ||
| expect(isEditTool(undefined)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("looksLikeUnifiedDiff", () => { | ||
| it("returns true for valid unified diff text", () => { | ||
| const diff = [ | ||
| "--- a/file.txt", | ||
| "+++ b/file.txt", | ||
| "@@ -1 +1 @@", | ||
| "-old line", | ||
| "+new line", | ||
| ].join("\n"); | ||
| expect(looksLikeUnifiedDiff(diff)).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true for new-file style diff headers without hunks", () => { | ||
| const headerOnly = [ | ||
| "--- src/new-file.ts", | ||
| "+++ src/new-file.ts", | ||
| "(new file, 42 bytes)", | ||
| ].join("\n"); | ||
| expect(looksLikeUnifiedDiff(headerOnly)).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false for non-diff text", () => { | ||
| expect(looksLikeUnifiedDiff("plain output")).toBe(false); | ||
| expect(looksLikeUnifiedDiff("")).toBe(false); | ||
| expect(looksLikeUnifiedDiff(undefined)).toBe(false); | ||
| }); | ||
| }); |
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.