Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(cowork): alignment and tool-call labelling in the transcript

Akarshan Biswas674bb385edeb
diff --git a/web-app/src/components/left-sidebar/NavCowork.tsx b/web-app/src/components/left-sidebar/NavCowork.tsx
index db8489fc4..30ef8697a 100644
--- a/web-app/src/components/left-sidebar/NavCowork.tsx
+++ b/web-app/src/components/left-sidebar/NavCowork.tsx
@@ -204,8 +204,10 @@ export function NavCowork() {
})}
</SidebarMenu>
+ {/* px-0: the group's own p-2 would indent the session rows past the nav
+ rows above it, which share the header's px-1. */}
{visibleSessions.length > 0 && (
- <SidebarGroup className="group-data-[collapsible=icon]:hidden">
+ <SidebarGroup className="px-0 group-data-[collapsible=icon]:hidden">
<SidebarGroupLabel>{t('common:sessions')}</SidebarGroupLabel>
<SidebarMenu>
{visibleSessions.map((session) => (
diff --git a/web-app/src/containers/MessageItem.tsx b/web-app/src/containers/MessageItem.tsx
index 408593459..1f0084102 100644
--- a/web-app/src/containers/MessageItem.tsx
+++ b/web-app/src/containers/MessageItem.tsx
@@ -594,8 +594,9 @@ export const MessageItem = memo(
)}
>
- {/* Render message parts */}
- {renderedParts}
+ {/* Render message parts. A turn alternates collapsed traces with
+ answer paragraphs, and with no gap the two read as one block. */}
+ <div className="flex flex-col gap-3">{renderedParts}</div>
{message.role === 'assistant' && !isStreaming && webCitations.length > 0 && (
<WebSourcesRow citations={webCitations} />
diff --git a/web-app/src/containers/message/AgentToolWidget.tsx b/web-app/src/containers/message/AgentToolWidget.tsx
index 1d9971e48..ac0127f13 100644
--- a/web-app/src/containers/message/AgentToolWidget.tsx
+++ b/web-app/src/containers/message/AgentToolWidget.tsx
@@ -133,13 +133,6 @@ export const TerminalWidget = memo(
{running && <Caret />}
</span>
</div>
- {running && (
- <div className="mt-1">
- {/* The command is already on screen above, so the tool-named
- `running` string would just repeat it. */}
- <Shimmer duration={1}>{t('tools:toolCall.working')}</Shimmer>
- </div>
- )}
{!running && body && (
<pre className="mt-1 max-h-56 overflow-auto whitespace-pre-wrap wrap-break-word text-muted-foreground">
{body}
@@ -184,6 +177,31 @@ const TOOL_ICONS: Record<string, typeof IconFile> = {
/** Tools whose whole call is the verb: there is no argument worth a bar. */
const LISTING_TOOLS = new Set(['memory_list', 'skill_list', 'ls'])
+// A workspace call is not always a read: `Reading...` under a `write` is simply
+// wrong, and the verb is the only progress signal the widget has.
+const RUNNING_KEYS: Record<string, string> = {
+ write: 'tools:toolCall.writing',
+ memory_write: 'tools:toolCall.writing',
+ skill_write: 'tools:toolCall.writing',
+ edit: 'tools:toolCall.editing',
+ find: 'tools:toolCall.searching',
+ grep: 'tools:toolCall.searching',
+ ls: 'tools:toolCall.listing',
+ memory_list: 'tools:toolCall.listing',
+ skill_list: 'tools:toolCall.listing',
+}
+
+// find/grep bars carry a pattern and memory/skill an entry name, so `path` is
+// the wrong prompt for both.
+const PLACEHOLDER_KEYS: Record<string, string> = {
+ find: 'tools:toolCall.patternPlaceholder',
+ grep: 'tools:toolCall.patternPlaceholder',
+ memory_read: 'tools:toolCall.namePlaceholder',
+ memory_write: 'tools:toolCall.namePlaceholder',
+ skill_read: 'tools:toolCall.namePlaceholder',
+ skill_write: 'tools:toolCall.namePlaceholder',
+}
+
export type AgentToolWidgetProps = {
bar: Extract<ToolCallBar, { variant: 'workspace' }>
state: ToolUIPart['state']
@@ -217,7 +235,9 @@ export const AgentToolWidget = memo(
<ToolBar
icon={<Icon size={16} />}
value={value}
- placeholder={t('tools:toolCall.pathPlaceholder')}
+ placeholder={t(
+ PLACEHOLDER_KEYS[bar.tool] ?? 'tools:toolCall.pathPlaceholder'
+ )}
typing={running}
mono
trailing={
@@ -237,7 +257,9 @@ export const AgentToolWidget = memo(
{running && !errorText && (
<div className="px-2 text-sm">
- <Shimmer duration={1}>{t('tools:toolCall.reading')}</Shimmer>
+ <Shimmer duration={1}>
+ {t(RUNNING_KEYS[bar.tool] ?? 'tools:toolCall.reading')}
+ </Shimmer>
</div>
)}
diff --git a/web-app/src/containers/message/ChainOfThoughtGroup.tsx b/web-app/src/containers/message/ChainOfThoughtGroup.tsx
index ae6e72bfd..3d24f3fb8 100644
--- a/web-app/src/containers/message/ChainOfThoughtGroup.tsx
+++ b/web-app/src/containers/message/ChainOfThoughtGroup.tsx
@@ -21,14 +21,6 @@ import { segmentReasoningSteps } from '@/lib/reasoning'
import { ToolCallCard } from './ToolCallCard'
import { CONTENT_TYPE, isToolPart, type PartEntry } from './types'
-// Turn a tool identifier (e.g. "web_search", "exa_search") into a readable
-// label for the streaming step header (e.g. "Web search").
-function humanizeToolName(name: string): string {
- const spaced = name.replace(/[_-]+/g, ' ').trim()
- if (!spaced) return 'tool'
- return spaced.charAt(0).toUpperCase() + spaced.slice(1)
-}
-
export type ChainOfThoughtGroupProps = {
/** Reasoning and tool parts belonging to this trace, in message order. */
entries: PartEntry[]
@@ -113,10 +105,6 @@ export const ChainOfThoughtGroup = memo(
lastMeaningful && isToolPart(lastMeaningful.part)
)
- const currentToolLabel = currentStepIsTool
- ? humanizeToolName(lastMeaningful.part.type.split('-').slice(1).join('-'))
- : ''
-
// While streaming, expand for a tool call -- its card carries the live
// search/address bar and the result, all of which sit inside this
// collapsible -- or for reasoning that has a settled step to show, i.e. the
@@ -270,9 +258,12 @@ export const ChainOfThoughtGroup = memo(
defaultOpen={hasDisplayableContent && !hasFollowingContent}
>
<ChainOfThoughtHeader
+ // The tool card rendered right below names the call, its origin and
+ // its elapsed time, so repeating the tool here printed it twice one
+ // row apart. This row speaks for the trace, not the step.
streamingLabel={
currentStepIsTool
- ? t('chat:reasoning.usingTool', { tool: currentToolLabel })
+ ? t('chat:reasoning.working')
: t('chat:reasoning.thinking')
}
completedVariant={hasTools ? 'worked' : 'thought'}
diff --git a/web-app/src/containers/message/__tests__/AgentToolWidget.test.tsx b/web-app/src/containers/message/__tests__/AgentToolWidget.test.tsx
new file mode 100644
index 000000000..c38ec4a17
--- /dev/null
+++ b/web-app/src/containers/message/__tests__/AgentToolWidget.test.tsx
@@ -0,0 +1,45 @@
+import { describe, expect, it, vi } from 'vitest'
+import { render, screen } from '@testing-library/react'
+import '@testing-library/jest-dom'
+
+vi.mock('@/i18n/react-i18next-compat', () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}))
+
+vi.mock('@/hooks/useToolCallRuntime', () => ({
+ useToolCallRuntime: (selector: (s: unknown) => unknown) =>
+ selector({ diffs: {} }),
+}))
+
+import { AgentToolWidget } from '../AgentToolWidget'
+
+const renderRunning = (tool: string, target = '') =>
+ render(
+ <AgentToolWidget
+ bar={{ variant: 'workspace', tool, target }}
+ state="input-available"
+ toolCallId="tc1"
+ />
+ )
+
+describe('AgentToolWidget', () => {
+ // A workspace call is not always a read; the verb is the only progress
+ // signal the widget has while the call runs.
+ it.each([
+ ['write', 'tools:toolCall.writing'],
+ ['edit', 'tools:toolCall.editing'],
+ ['grep', 'tools:toolCall.searching'],
+ ['ls', 'tools:toolCall.listing'],
+ ['read', 'tools:toolCall.reading'],
+ ])('names what %s is doing while it runs', (tool, key) => {
+ renderRunning(tool, tool === 'ls' ? '' : 'a.txt')
+ expect(screen.getByText(key)).toBeInTheDocument()
+ })
+
+ it('prompts for a pattern rather than a path on grep', () => {
+ renderRunning('grep')
+ expect(
+ screen.getByText('tools:toolCall.patternPlaceholder')
+ ).toBeInTheDocument()
+ })
+})
diff --git a/web-app/src/locales/en/chat.json b/web-app/src/locales/en/chat.json
index e033c00b9..c9f69f518 100644
--- a/web-app/src/locales/en/chat.json
+++ b/web-app/src/locales/en/chat.json
@@ -22,7 +22,7 @@
"reasoning": {
"label": "Reasoning...",
"thinking": "Thinking",
- "usingTool": "{{tool}}...",
+ "working": "Working...",
"showFullTimeline": "Show full timeline",
"showCurrentStep": "Show current step only",
"thoughtForAWhile": "Thought for a few seconds",
diff --git a/web-app/src/locales/en/tools.json b/web-app/src/locales/en/tools.json
index 7db560584..b019921e9 100644
--- a/web-app/src/locales/en/tools.json
+++ b/web-app/src/locales/en/tools.json
@@ -56,6 +56,11 @@
"pollingJob": "waiting for background job {{id}}",
"pathPlaceholder": "path",
"reading": "Reading...",
+ "writing": "Writing...",
+ "editing": "Editing...",
+ "listing": "Listing...",
+ "patternPlaceholder": "pattern",
+ "namePlaceholder": "name",
"workspaceRoot": "workspace root"
}
}
diff --git a/web-app/src/routes/cowork.tsx b/web-app/src/routes/cowork.tsx
index d0e8e8aa3..012c0b2ea 100644
--- a/web-app/src/routes/cowork.tsx
+++ b/web-app/src/routes/cowork.tsx
@@ -843,8 +843,12 @@ function CoworkPage() {
/>
) : (
<Conversation className="absolute inset-0 text-start">
+ {/* pb-4: the scroll viewport ends where the composer begins,
+ so with no bottom padding the last row -- the live
+ "Working..." indicator -- rests flush against the input and
+ reads as tucked behind it. */}
<ConversationContent
- className={cn('mx-auto w-full md:w-4/5 xl:w-4/6')}
+ className={cn('mx-auto w-full pb-4 md:w-4/5 xl:w-4/6')}
>
{uiMessages.map((message, i) => (
<Fragment key={message.id}>
@@ -915,7 +919,7 @@ function CoworkPage() {
)}
</div>
- <div className="pb-4 shrink-0">
+ <div className="py-4 shrink-0">
<div className="mx-auto w-full md:w-4/5 xl:w-4/6">
{ask && typeof ask.request !== 'string' && (
<div className="px-1 pb-2">