Skip to content
Merged
5 changes: 4 additions & 1 deletion src/cli/agent-session-search-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ function formatDebug(debug: SessionSearchResults['debug']): string[] {
}

function formatUnavailable(
reason: 'disabled' | 'not-ready' | 'no-service' | 'scope-unknown'
reason: 'disabled' | 'not-ready' | 'no-service' | 'scope-unknown' | 'unsupported-agent'
): string {
if (reason === 'disabled') {
return 'Session search is off on this host.'
}
if (reason === 'unsupported-agent') {
return 'This host does not support history search for the selected agent. Update Orca on that host or select another agent.'
}
// The CLI scopes with --path, never with an identity, so this only reaches a
// caller that built a request by hand.
if (reason === 'scope-unknown') {
Expand Down
11 changes: 9 additions & 2 deletions src/cli/handlers/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ describe('orca search over the runtime RPC', () => {
const { call } = await runSearch([['query', 'resize race']])

expect(call).toHaveBeenCalledTimes(1)
expect(call).toHaveBeenCalledWith('aiVault.searchSessions', { query: 'resize race', limit: 20 })
expect(call).toHaveBeenCalledWith('aiVault.searchSessions', {
query: 'resize race',
limit: 20,
supportsQoderHistory: true
})
})

const flagCases: [string, CliFlags, Record<string, unknown>][] = [
Expand Down Expand Up @@ -157,7 +161,10 @@ describe('orca search over the runtime RPC', () => {
it.each(flagCases)('sends %s', async (_name, flags, params) => {
const { call } = await runSearch(flags)

expect(call).toHaveBeenCalledWith('aiVault.searchSessions', params)
expect(call).toHaveBeenCalledWith('aiVault.searchSessions', {
...params,
supportsQoderHistory: true
})
})

it('calls the status RPC for --index-status', async () => {
Expand Down
8 changes: 7 additions & 1 deletion src/cli/search-command-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ describe('orca search argument parsing', () => {

it('rejects an unknown --agent and names the known ones', () => {
expect(() => parseSearch(['search', 'q', '--agent', 'claude', '--agent', 'bogus'])).toThrow(
/Unknown --agent "bogus"\. Known agents: claude, codebuddy, codex, /
/Unknown --agent "bogus"\. Known agents: claude, codebuddy, qoder, codex, /
)
})

it('accepts Qoder without changing another agent filter', () => {
expect(
request(['search', 'q', '--agent', 'qoder', '--agent', 'codex']).filters?.agents
).toEqual(['qoder', 'codex'])
})

it('rejects more --path values than the contract accepts', () => {
const paths = Array.from({ length: 65 }, (_, index) => ['--path', `/p${index}`]).flat()
expect(() => parseSearch(['search', 'q', ...paths])).toThrow('Too many --path values (65)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('every search entry point carries the scope identity through', () => {
const service = fakeSearchService()
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await relayHandler()({ query: 'needle', within: WITHIN })
await relayHandler()({ query: 'needle', supportsQoderHistory: true, within: WITHIN })
expect(service.search).toHaveBeenCalledWith(expect.anything(), {
kind: 'resolved',
paths: ['/work/app']
Expand All @@ -88,7 +88,7 @@ describe('every search entry point carries the scope identity through', () => {
it('hands the relay’s own verdict down, that host carrying no repo catalog', async () => {
const service = fakeSearchService()
setSessionSearchService(service)
await relayHandler()({ query: 'needle', within: WITHIN })
await relayHandler()({ query: 'needle', supportsQoderHistory: true, within: WITHIN })
expect(service.search).toHaveBeenCalledWith(
{ query: 'needle', limit: 20 },
{
Expand Down
37 changes: 30 additions & 7 deletions src/main/ai-vault-search/session-search-scope-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ describe('scope identity at the search choke point', () => {
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await searchSessionService(
{ query: 'needle', within: { kind: 'workspace', worktreeId: 'repo-1::/work/app' } },
{
query: 'needle',
supportsQoderHistory: true,
within: { kind: 'workspace', worktreeId: 'repo-1::/work/app' }
},
'ipc'
)
// Beside the request, not inside `filters.scopePaths`, which carries a wire cap.
Expand All @@ -41,7 +45,11 @@ describe('scope identity at the search choke point', () => {
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await searchSessionService(
{ query: 'needle', within: { kind: 'project', projectKey: 'repo:repo-1' } },
{
query: 'needle',
supportsQoderHistory: true,
within: { kind: 'project', projectKey: 'repo:repo-1' }
},
'ipc'
)
// An exact match, so a leaked `within` would fail here as an extra key.
Expand All @@ -56,7 +64,11 @@ describe('scope identity at the search choke point', () => {
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await searchSessionService(
{ query: 'needle', within: { kind: 'project', projectKey: 'repo:elsewhere' } },
{
query: 'needle',
supportsQoderHistory: true,
within: { kind: 'project', projectKey: 'repo:elsewhere' }
},
'ipc'
)
// The service owns the answer, because it owns the consent and readiness
Expand All @@ -74,7 +86,11 @@ describe('scope identity at the search choke point', () => {
const service = fakeSearchService()
setSessionSearchService(service)
await searchSessionService(
{ query: 'needle', within: { kind: 'workspace', worktreeId: 'repo-1::/work/app' } },
{
query: 'needle',
supportsQoderHistory: true,
within: { kind: 'workspace', worktreeId: 'repo-1::/work/app' }
},
'ipc'
)
expect(service.search).toHaveBeenCalledWith(
Expand All @@ -98,7 +114,11 @@ describe('scope identity at the search choke point', () => {
settings: { workspaceDir: '/home/me/ws', nestWorkspaces: false }
}))
await searchSessionService(
{ query: 'needle', within: { kind: 'project', projectKey: 'repo:repo-1' } },
{
query: 'needle',
supportsQoderHistory: true,
within: { kind: 'project', projectKey: 'repo:repo-1' }
},
'ipc'
)
const call = service.search.mock.lastCall
Expand All @@ -113,15 +133,18 @@ describe('scope identity at the search choke point', () => {
const service = fakeSearchService()
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await searchSessionService({ query: 'needle' }, 'ipc')
await searchSessionService({ query: 'needle', supportsQoderHistory: true }, 'ipc')
expect(service.search).toHaveBeenCalledWith({ query: 'needle', limit: 20 }, undefined)
})

it('still honours an explicit path filter, which is what the CLI’s --path sends', async () => {
const service = fakeSearchService()
setSessionSearchService(service)
installSessionSearchScopeCatalogSource(() => CATALOG)
await searchSessionService({ query: 'needle', filters: { scopePaths: ['/other'] } }, 'ipc')
await searchSessionService(
{ query: 'needle', supportsQoderHistory: true, filters: { scopePaths: ['/other'] } },
'ipc'
)
expect(service.search).toHaveBeenCalledWith(
{ query: 'needle', limit: 20, filters: { scopePaths: ['/other'] } },
undefined
Expand Down
45 changes: 43 additions & 2 deletions src/main/ai-vault-search/session-search-service-registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { fakeSearchService } from '../../shared/ai-vault-search-test-fixture'
import { unavailableSessionSearchStatus } from '../../shared/ai-vault-search-client'
import {
unavailableSessionSearchStatus,
createSessionSearchClient
} from '../../shared/ai-vault-search-client'
import { AI_VAULT_AGENTS } from '../../shared/ai-vault-types'
import {
setSessionSearchService,
searchSessionService,
Expand Down Expand Up @@ -51,12 +55,49 @@ describe('session search service registry', () => {
'ipc'
)
expect(service.reconcile).not.toHaveBeenCalled()
expect(service.search).toHaveBeenCalledWith({ query: 'needle', limit: 20 }, undefined)
expect(service.search).toHaveBeenCalledWith(
{
query: 'needle',
limit: 20,
filters: { agents: AI_VAULT_AGENTS.filter((a) => a !== 'qoder') }
},
undefined
)
expect(result).not.toHaveProperty('debug')
expect(await searchSessionService({ query: 'needle', debug: true }, 'ipc')).toHaveProperty(
'debug'
)
})
it.each(['ipc', 'runtime', 'relay'] as const)(
'negotiates Qoder hits before retrieval on %s, without widening explicit filters',
async (transport) => {
const service = fakeSearchService()
setSessionSearchService(service)
await searchSessionService(
{ query: 'proof', filters: { agents: ['claude', 'qoder'] } },
transport
)
expect(service.search).toHaveBeenLastCalledWith(
{ query: 'proof', limit: 20, filters: { agents: ['claude'] } },
undefined
)
expect(
await searchSessionService({ query: 'proof', filters: { agents: ['qoder'] } }, transport)
).toMatchObject({ kind: 'results', hits: [], page: { cursor: null, hasMore: false } })
const client = createSessionSearchClient(
(method, request) =>
method === 'aiVault.searchStatus'
? sessionSearchServiceStatus(request, transport)
: searchSessionService(request, transport),
transport
)
await client.searchSessions({ query: 'proof', filters: { agents: ['qoder'] } })
expect(service.search).toHaveBeenLastCalledWith(
{ query: 'proof', limit: 20, filters: { agents: ['qoder'] } },
undefined
)
}
)
it('waits for reconcile before search, and clears its timeout', async () => {
vi.useFakeTimers()
const service = fakeSearchService()
Expand Down
33 changes: 28 additions & 5 deletions src/main/ai-vault-search/session-search-service-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type SessionSearchTransport
} from '../../shared/ai-vault-search-transport'
import type { SessionSearchService } from './session-search-service'
import { AI_VAULT_AGENTS } from '../../shared/ai-vault-types'

let service: SessionSearchService | null = null

Expand All @@ -34,18 +35,39 @@ export async function searchSessionService(
// The choke point every entry point funnels through, so every host kind
// resolves alike; the verdict goes to the service, which answers off and
// not-ready first.
const { within, ...request } = parsed
const { within, supportsQoderHistory, ...request } = parsed
// Older clients reject the whole page when a hit has an unknown agent tag.
const requestedAgents = request.filters?.agents
const compatibleAgents = (requestedAgents?.length ? requestedAgents : AI_VAULT_AGENTS).filter(
(agent) => supportsQoderHistory || agent !== 'qoder'
)
const compatibleRequest = supportsQoderHistory
? request
: {
...request,
filters: {
...request.filters,
agents: compatibleAgents.length
? compatibleAgents
: AI_VAULT_AGENTS.filter((agent) => agent !== 'qoder')
}
}
const hostScope = within
? resolveSessionSearchScope(within, sessionSearchScopeCatalog())
: undefined
const freshness =
request.freshness === 'wait-until-current'
? await reconcileWithin(current, freshnessTimeoutMs)
: false
const result = AiVaultSearchResponseSchema.parse(await current.search(request, hostScope))
const result = AiVaultSearchResponseSchema.parse(
await current.search(compatibleRequest, hostScope)
)
if (result.kind !== 'results') {
return result
}
if (compatibleAgents.length === 0) {
return { ...result, hits: [], page: { cursor: null, hasMore: false } }
}
const { debug, ...fields } = result
return {
...fields,
Expand All @@ -61,9 +83,10 @@ export async function sessionSearchServiceStatus(
): Promise<AiVaultSearchStatus> {
AiVaultSearchStatusRequestSchema.parse(raw)
return redactStatusForTransport(
AiVaultSearchStatusSchema.parse(
service ? await service.status() : unavailableSessionSearchStatus()
),
AiVaultSearchStatusSchema.parse({
...(service ? await service.status() : unavailableSessionSearchStatus()),
supportsQoderHistory: true
}),
transport
)
}
Expand Down
Loading
Loading