mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: apply CodeRabbit auto-fixes
This commit is contained in:
1 parent
d99fcc268e
commit
df9200880e
15 files changed
+87
-89
No files matched your search
@@ -37,10 +37,6 @@ export type OpenCodeLocationInfo = Awaited<ReturnType<OpenCodeApi['location']['g
|
||||
|
||||
export type OpenCodeProject = Awaited<ReturnType<OpenCodeApi['project']['list']>>[number]
|
||||
|
||||
/**
|
||||
* The timestamp a project list sorts and labels on: the server's last-activity time, falling back
|
||||
* to the record's update time for a project that has never recorded activity.
|
||||
*/
|
||||
export function projectActivityTimestamp(project: OpenCodeProject): number {
|
||||
return project.time.active || project.time.updated
|
||||
}
|
||||
|
||||
@@ -87,10 +87,6 @@ interface ContextUsageStripProps {
|
||||
compactDisabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact context-window strip pinned above the picker header: the tone meter, then one line with the
|
||||
* used and limit token counts, the percentage, and the session compaction action.
|
||||
*/
|
||||
function ContextUsageStrip({ usage, onCompact, compactDisabled }: ContextUsageStripProps) {
|
||||
const percentage = usage.usagePercentage
|
||||
const toneClass = CONTEXT_USAGE_TEXT_CLASS[contextUsageTone(percentage)]
|
||||
|
||||
@@ -6,10 +6,6 @@ interface ContextUsageMeterProps {
|
||||
className?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Two-pixel context-window meter: a muted track with a tone-coloured fill sized to `min(percentage, 100)`.
|
||||
* Purely decorative, so the surrounding readout carries the accessible label.
|
||||
*/
|
||||
export function ContextUsageMeter({ percentage, className }: ContextUsageMeterProps) {
|
||||
const width = percentage === null ? 0 : Math.min(percentage, 100)
|
||||
|
||||
|
||||
@@ -4,14 +4,6 @@ export interface ReconnectingBannerProps {
|
||||
connected: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Full-width strip under the session header that reports a paused event
|
||||
* stream. It stays hidden until the stream has connected at least once, so a
|
||||
* first paint before the subscription settles does not read as a dropped
|
||||
* connection.
|
||||
*
|
||||
* @param connected Whether the session's event stream is currently connected.
|
||||
*/
|
||||
export function ReconnectingBanner({ connected }: ReconnectingBannerProps) {
|
||||
const [hasConnected, setHasConnected] = useState(false)
|
||||
|
||||
|
||||
@@ -154,6 +154,18 @@ describe('SessionDetailsSheet', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('ignores Enter while an IME composition is active', () => {
|
||||
const mutation = mockRename()
|
||||
renderSheet()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
const input = screen.getByLabelText('Session title')
|
||||
fireEvent.change(input, { target: { value: 'にほんご' } })
|
||||
fireEvent.keyDown(input, { key: 'Enter', isComposing: true })
|
||||
|
||||
expect(mutation.mutate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cancels editing and resets the rename error', () => {
|
||||
const mutation = mockRename({ error: new Error('nope') })
|
||||
renderSheet()
|
||||
|
||||
@@ -40,15 +40,6 @@ function InfoRow({ label, value, mono, leading }: InfoRowProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Session details shown from the session header title. It lists the title,
|
||||
* server, project, branch and directory untruncated, and renames the session
|
||||
* inline so the sheet stays open while the new title lands through the session
|
||||
* query. It renders as a bottom sheet on mobile and a dialog on desktop.
|
||||
*
|
||||
* Dismissal is blocked while a rename is pending, and the mutation error resets
|
||||
* when the sheet reopens so a failed rename cannot leak into the next open.
|
||||
*/
|
||||
export function SessionDetailsSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
@@ -120,6 +111,7 @@ export function SessionDetailsSheet({
|
||||
value={draft}
|
||||
onChange={(event) => setDraft(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.nativeEvent.isComposing) return
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
save()
|
||||
|
||||
@@ -394,6 +394,18 @@ describe('SessionPickerDialog', () => {
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBeNull()
|
||||
})
|
||||
|
||||
it('leaves the persisted scope preference unchanged on Ctrl+A without a current repo', () => {
|
||||
localStorage.setItem('oc:session-picker:all-projects', 'false')
|
||||
|
||||
renderPicker({ currentRepo: undefined })
|
||||
|
||||
fireEvent.keyDown(combobox(), { key: 'a', ctrlKey: true })
|
||||
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBe('false')
|
||||
expect(mocks.lastAllDirectories).toBe(true)
|
||||
expect(screen.getByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('starts a new session in the current repo from the sessions tab header action', () => {
|
||||
const onNavigate = vi.fn()
|
||||
renderPicker({ onNavigate })
|
||||
|
||||
@@ -86,7 +86,6 @@ interface SessionPickerDialogProps {
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
/** Navigates to a path the panel produced, such as a new session created from the header action. */
|
||||
onNavigate: (path: string) => void
|
||||
/** Set on a linked-server route to list that server's sessions instead of Manager repos. */
|
||||
remote?: RemotePickerScope
|
||||
@@ -569,7 +568,7 @@ interface SessionPickerContentProps {
|
||||
onDeleteActiveSession: () => void
|
||||
allProjects: boolean
|
||||
scopeEnabled: boolean
|
||||
onToggleAllProjects: () => void
|
||||
onToggleAllProjects?: () => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
searchTrailing?: React.ReactNode
|
||||
@@ -1212,19 +1211,13 @@ export interface SessionPickerPanelProps {
|
||||
onDeleteActiveSession: () => void
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
onNavigate: (path: string) => void
|
||||
/** Set on a linked-server route to list that server's sessions instead of Manager repos. */
|
||||
remote?: RemotePickerScope
|
||||
/** Lists the linked server's projects on a Projects tab; the desktop dialog leaves it off. */
|
||||
remoteProjects?: boolean
|
||||
/** Extra controls rendered at the trailing end of every tab's search bar. */
|
||||
searchTrailing?: React.ReactNode
|
||||
/** Hands the add-repository action to the host, which renders the dialog above its own surface. */
|
||||
onAddRepo?: () => void
|
||||
/** Renders the dialog title element, which only a Radix Dialog can host. */
|
||||
renderTitle?: (label: string) => React.ReactNode
|
||||
}
|
||||
|
||||
/** The tab strip, search bars, lists and header actions shared by the picker dialog and sheet. */
|
||||
export function SessionPickerPanel({
|
||||
open,
|
||||
currentRepo,
|
||||
@@ -1423,7 +1416,7 @@ export function SessionPickerPanel({
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
allProjects={allProjects}
|
||||
scopeEnabled={scopeEnabled}
|
||||
onToggleAllProjects={toggleAllProjects}
|
||||
onToggleAllProjects={scopeEnabled ? toggleAllProjects : undefined}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
searchTrailing={sessionsTrailing}
|
||||
|
||||
@@ -136,13 +136,19 @@ function repo(id: number, name: string, fullPath: string): Repo {
|
||||
}
|
||||
}
|
||||
|
||||
function activeWorkItem(id: string, directory: string): ActiveWorkItem {
|
||||
function activeWorkItem(
|
||||
id: string,
|
||||
directory: string,
|
||||
server?: { id: string; name: string },
|
||||
): ActiveWorkItem {
|
||||
const now = Date.now()
|
||||
return {
|
||||
key: `1:${id}`,
|
||||
key: `${server?.id ?? LOCAL_OPENCODE_SERVER_ID}:${id}`,
|
||||
state: 'recent',
|
||||
session: session(id, `Active ${id}`, directory, now),
|
||||
repo: repo(1, 'alpha', directory),
|
||||
repo: server ? null : repo(1, 'alpha', directory),
|
||||
serverId: server?.id ?? null,
|
||||
serverName: server?.name ?? null,
|
||||
updatedAt: now,
|
||||
path: `/repos/1/sessions/${id}`,
|
||||
}
|
||||
@@ -329,4 +335,39 @@ describe('SessionPickerSheet', () => {
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_active REPLACE')
|
||||
})
|
||||
|
||||
it('opens a remote activity row on its own server while the local server is selected', async () => {
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [],
|
||||
running: [],
|
||||
recent: [activeWorkItem('ses_kitchen', '/home/me/app', { id: 'srv_kitchen', name: 'Kitchen' })],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_kitchen/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/sessions/ses_kitchen REPLACE',
|
||||
)
|
||||
})
|
||||
|
||||
it('opens an activity row of another linked server than the selected one', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [],
|
||||
running: [],
|
||||
recent: [activeWorkItem('ses_hall', '/home/me/hall', { id: 'srv_hall', name: 'Hall' })],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_hall/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_hall/sessions/ses_hall REPLACE',
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -14,12 +14,10 @@ interface SessionPickerSheetProps {
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/** The session picker in a bottom sheet; every navigation replaces the sheet's history entry. */
|
||||
export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps) {
|
||||
const navigate = useNavigate()
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
const { currentRepo, activeSessionID, remote } = useSessionPickerRouteScope(isOpen)
|
||||
const remoteServerId = remote?.serverId
|
||||
|
||||
const navigateReplacing = useCallback(
|
||||
(path: string) => {
|
||||
@@ -40,15 +38,14 @@ export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps)
|
||||
)
|
||||
|
||||
const handleSelectRemoteSession = useCallback(
|
||||
(session: Session) => {
|
||||
if (!remoteServerId) return
|
||||
(session: Session, serverId: string) => {
|
||||
if (session.id === activeSessionID) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getServerSessionPath(remoteServerId, session.id))
|
||||
navigateReplacing(getServerSessionPath(serverId, session.id))
|
||||
},
|
||||
[activeSessionID, navigateReplacing, onClose, remoteServerId],
|
||||
[activeSessionID, navigateReplacing, onClose],
|
||||
)
|
||||
|
||||
const handleDeleteActiveSession = useCallback(() => {
|
||||
|
||||
@@ -13,10 +13,6 @@ export interface SessionPickerRouteScope {
|
||||
remote: { serverId: string; serverName?: string; projectDirectory?: string } | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves what a session picker opened on the current route should list: the Manager repo of a
|
||||
* repo route, or the selected linked server and its project directory.
|
||||
*/
|
||||
export function useSessionPickerRouteScope(enabled: boolean): SessionPickerRouteScope {
|
||||
const { pathname, search } = useLocation()
|
||||
const [selectedServerId] = useSidebarServerSelection()
|
||||
|
||||
@@ -6,16 +6,6 @@ export interface UseVcsInfoOptions {
|
||||
enabled?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the version-control info of a directory through the OpenCode server in
|
||||
* scope. The query is keyed by directory and server id, so the session header,
|
||||
* the project header and the source control panel share one cached read, and a
|
||||
* linked server reports its own checkout rather than the Manager's.
|
||||
*
|
||||
* @param directory Absolute checkout directory; the query stays disabled without one.
|
||||
* @param serverId Linked server to read from, or the local Manager when omitted.
|
||||
* @param options.enabled Whether to read the info; defaults to `true`.
|
||||
*/
|
||||
export function useVcsInfo(
|
||||
directory: string | undefined,
|
||||
serverId: string | undefined,
|
||||
@@ -28,6 +18,5 @@ export function useVcsInfo(
|
||||
queryFn: () => getVcsInfo(directory ?? '', serverId),
|
||||
enabled: enabled && Boolean(directory),
|
||||
retry: false,
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
@@ -18,20 +18,12 @@ export const CONTEXT_USAGE_BG_CLASS: Record<ContextUsageTone, string> = {
|
||||
destructive: 'bg-destructive',
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a context-window percentage to a semantic tone: under 50 is `success`, under 80 is `warning`,
|
||||
* and 80 or more is `destructive`. An unknown percentage falls back to `success`.
|
||||
*/
|
||||
export function contextUsageTone(percentage: number | null): ContextUsageTone {
|
||||
if (percentage === null || percentage < 50) return 'success'
|
||||
if (percentage < 80) return 'warning'
|
||||
return 'destructive'
|
||||
}
|
||||
|
||||
/**
|
||||
* Abbreviates a token count so it fits a one-line readout: exact below a thousand, whole thousands up
|
||||
* to a million (`41k`), and millions to at most one decimal (`1M`, `1.3M`).
|
||||
*/
|
||||
export function formatCompactTokens(tokens: number): string {
|
||||
if (tokens < 1000) return String(tokens)
|
||||
if (tokens < 1000000) {
|
||||
@@ -41,10 +33,6 @@ export function formatCompactTokens(tokens: number): string {
|
||||
return `${Number((tokens / 1000000).toFixed(1))}M`
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats context usage for a compact readout: the percentage of the model's context window when both
|
||||
* a limit and a percentage are known, otherwise a compact token count such as `41k`.
|
||||
*/
|
||||
export function formatContextUsage(usage: ContextUsage): string {
|
||||
if (usage.contextLimit !== null && usage.usagePercentage !== null) {
|
||||
return `${usage.usagePercentage}%`
|
||||
@@ -52,10 +40,6 @@ export function formatContextUsage(usage: ContextUsage): string {
|
||||
return formatCompactTokens(usage.totalTokens)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the screen-reader description of a context-window readout, e.g. `context 42% used` or, when
|
||||
* the limit is unknown, `context 12k tokens used`.
|
||||
*/
|
||||
export function contextUsageAccessibleLabel(usage: ContextUsage): string {
|
||||
if (usage.usagePercentage !== null) {
|
||||
return `context ${usage.usagePercentage}% used`
|
||||
|
||||
@@ -817,16 +817,18 @@ export function SessionDetail() {
|
||||
<div className="flex items-center gap-1.5 sm:gap-3 min-w-0 flex-1">
|
||||
<Header.BackButton to={sessionBackPath} className="text-xs sm:text-sm" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSessionDetailsOpen(true)}
|
||||
aria-label="Session details"
|
||||
className="block min-w-0 max-w-full cursor-pointer text-left"
|
||||
>
|
||||
<h1 className="text-xs sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate hover:opacity-80 transition-opacity">
|
||||
{session?.title || "Untitled Session"}
|
||||
</h1>
|
||||
</button>
|
||||
<h1 className="min-w-0 max-w-full text-xs sm:text-base font-semibold">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSessionDetailsOpen(true)}
|
||||
aria-label={`Session details: ${session?.title || "Untitled Session"}`}
|
||||
className="block min-w-0 max-w-full cursor-pointer text-left"
|
||||
>
|
||||
<span className="block truncate bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent transition-opacity hover:opacity-80">
|
||||
{session?.title || "Untitled Session"}
|
||||
</span>
|
||||
</button>
|
||||
</h1>
|
||||
{session?.parentID ? (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -499,7 +499,7 @@ describe('SessionDetail remote server mode', () => {
|
||||
it('opens the session details sheet from the header title', async () => {
|
||||
renderRemoteSession()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Session details' }))
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Session details: Remote chat' }))
|
||||
|
||||
expect(await screen.findByRole('dialog')).toHaveAccessibleName('Session details')
|
||||
expect(screen.getByText('/home/me/app')).toBeInTheDocument()
|
||||
|
||||
Reference in new issue
Block a user