Feat/assistant session list (#198)

* feat: add assistant mode integration and fix test environment

- Add assistant-mode service for managing assistant workspace files (AGENTS.md, opencode.json)
- Add backend GET/POST routes for assistant-mode status and initialization
- Add AssistantRedirect page and useAssistantSessionLauncher hook
- Update mobile navigation to include Assistant tab (replaces Alerts)
- Fix React.act compatibility by setting NODE_ENV=test in vitest config
- Add shared Zod schemas for AssistantMode types and requests

* feat: enhance assistant mode with session list view and legacy config migration

- Add session list view for assistant mode with full workspace management
- Migrate legacy opencode.json permission format to granular permissions
- Enable assistant navigation from mobile tab bar and repo switcher
- Preserve assistant context in session routes via query params
- Auto-restart OpenCode server after assistant mode initialization
- Add comprehensive tests for legacy config detection and navigation
This commit is contained in:
Chris Scott authored and GitHub committed 2026-04-24 18:35:47 -04:00
1 parent 0a2e337efc
commit c894ff5756
22 files changed
+1347 -154

No files matched your search

@@ -0,0 +1,73 @@
import { renderHook, act } from '@testing-library/react'
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { useAssistantSessionLauncher } from './useAssistantSessionLauncher'
import { OpenCodeClient } from '@/api/opencode'
import { initializeAssistantMode } from '@/api/repos'
const mocks = vi.hoisted(() => ({
listSessions: vi.fn(),
createSession: vi.fn(),
initializeAssistantMode: vi.fn(),
}))
vi.mock('@/api/repos', () => ({
initializeAssistantMode: mocks.initializeAssistantMode,
}))
vi.mock('@/api/opencode', () => ({
OpenCodeClient: vi.fn(() => ({
listSessions: mocks.listSessions,
createSession: mocks.createSession,
})),
}))
describe('useAssistantSessionLauncher', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.initializeAssistantMode.mockResolvedValue({ directory: '/assistant' })
})
it('opens the latest root session in the assistant directory', async () => {
mocks.listSessions.mockResolvedValue([
{ id: 'older', directory: '/assistant', time: { updated: 10 } },
{ id: 'newest-child', parentID: 'newest', directory: '/assistant', time: { updated: 40 } },
{ id: 'different-directory', directory: '/other', time: { updated: 50 } },
{ id: 'newest', directory: '/assistant', time: { updated: 30 } },
])
const onNavigate = vi.fn()
const { result } = renderHook(() => useAssistantSessionLauncher({
repoId: 123,
opcodeUrl: 'http://localhost:5551',
onNavigate,
}))
await act(async () => {
await result.current.openAssistant()
})
expect(initializeAssistantMode).toHaveBeenCalledWith(123)
expect(OpenCodeClient).toHaveBeenCalledWith('http://localhost:5551', '/assistant')
expect(onNavigate).toHaveBeenCalledWith('newest')
expect(mocks.createSession).not.toHaveBeenCalled()
})
it('creates a session when the assistant directory has no root sessions', async () => {
mocks.listSessions.mockResolvedValue([
{ id: 'other', directory: '/other', time: { updated: 50 } },
])
mocks.createSession.mockResolvedValue({ id: 'created' })
const onNavigate = vi.fn()
const { result } = renderHook(() => useAssistantSessionLauncher({
repoId: 123,
opcodeUrl: 'http://localhost:5551',
onNavigate,
}))
await act(async () => {
await result.current.openAssistant()
})
expect(mocks.createSession).toHaveBeenCalledWith({ title: 'Assistant' })
expect(onNavigate).toHaveBeenCalledWith('created')
})
})