refactor(goals): replace the Manager session-goal API with OpenCode built-in /goal

This commit is contained in:
Chris Scott committed 2026-10-29 12:38:39 -04:00
1 parent c8647c1eec
commit cbe92c92ad
84 files changed
+2099 -6321

No files matched your search

+39 -1
View File
@@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event'
import { useState, type ReactNode } from 'react'
import { MemoryRouter, useLocation } from 'react-router-dom'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { FormInfo, PermissionRequest } from '@opencode-manager/shared/opencode'
import type { FormInfo, PermissionRequest, GoalState } from '@opencode-manager/shared/opencode'
import { FetchError } from '@opencode-manager/shared'
import { showToast } from '@/lib/toast'
import { useSessionStatus, hasBackgroundActivity } from '@/stores/sessionStatusStore'
@@ -1248,6 +1248,44 @@ describe('EventProvider permissions and forms', () => {
})
})
it('applies a goal change event to the session goal cache', async () => {
const initialGoal: GoalState = {
id: 'goal-1',
objective: 'Ship the goal bar',
status: 'active',
rounds: 0,
maxRounds: 10,
boot: 'boot-1',
updatedAt: 1000,
}
const updatedGoal: GoalState = { ...initialGoal, rounds: 1, updatedAt: 2000 }
const queryClient = createTestQueryClient()
queryClient.setQueryData(['session-goal', 'session-1'], { supported: true, goal: initialGoal })
render(<Harness />, { wrapper: createWrapper(queryClient) })
await waitFor(() => expect(mocks.subscribeGlobalMonitor).toHaveBeenCalled())
const lastSubscribeCall = mocks.subscribeGlobalMonitor.mock.calls[mocks.subscribeGlobalMonitor.mock.calls.length - 1]
const onEvent = lastSubscribeCall[0].onEvent as (data: unknown) => void
act(() => {
onEvent({
type: 'rpc.opencode.goal.changed',
data: { sessionID: 'session-1', goal: updatedGoal },
directory: '/repo',
})
})
expect(queryClient.getQueryData(['session-goal', 'session-1'])).toEqual({ supported: true, goal: updatedGoal })
act(() => {
onEvent({ type: 'session.idle', data: { sessionID: 'other' }, directory: '/repo' })
})
expect(queryClient.getQueryData(['session-goal', 'session-1'])).toEqual({ supported: true, goal: updatedGoal })
})
it('invalidates the sibling caches when a branch changes outside a repo row', async () => {
mocks.listRepos.mockResolvedValue([])
+6
View File
@@ -28,6 +28,7 @@ import { getServerSessionPath, getSessionPath, parseRepoRoute, parseServerProjec
import { serverScopedKey } from '@/lib/serverScope'
import { repoMatchesDirectory } from '@/components/navigation/sidebar-session-tree'
import { changeWalkthroughQueryKey } from '@/hooks/useChangeWalkthrough'
import { applySessionGoalEvent, SESSION_GOAL_QUERY_ROOT } from '@/hooks/useSessionGoals'
import { busyStatusesFromActiveSessions, useSessionStatus } from '@/stores/sessionStatusStore'
import {
invalidateChildSessionCaches,
@@ -1051,6 +1052,9 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
const event = data as StreamEvent
const serverId = (event as { serverId?: string }).serverId ?? LOCAL_OPENCODE_SERVER_ID
const goalEvent = { type: event.type, data: 'data' in event ? event.data : null }
if (applySessionGoalEvent(queryClient, goalEvent, serverId)) return
switch (event.type) {
case 'permission.asked': {
const request = event.data
@@ -1233,6 +1237,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
void syncRunningShells(collectTrackedDirectories())
invalidateChildSessionCaches(queryClient)
invalidateQueryKeysDebounced(queryClient, LOCATION_CATALOG_QUERY_KEYS)
queryClient.invalidateQueries({ queryKey: [SESSION_GOAL_QUERY_ROOT] })
startStatusPoll()
} else {
streamConnectedRef.current = false
@@ -1244,6 +1249,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
}
const handleResync = (subscribedDirectories: string[], serverId?: string) => {
queryClient.invalidateQueries({ queryKey: [SESSION_GOAL_QUERY_ROOT] })
if (serverId && !isLocalOpenCodeServer(serverId)) {
void reconcileRemoteDirectoryActivity(serverId, subscribedDirectories)
invalidateSessionListCachesDebounced(queryClient, undefined, serverId)