1+ import type { AgentType } from '../agent/index.ts'
12import type { SearchFilter } from '../retriv/index.ts'
23import * as p from '@clack/prompts'
34import { defineCommand } from 'citty'
45import { detectCurrentAgent } from 'unagent/env'
6+ import { agents } from '../agent/index.ts'
57import { isInteractive } from '../cli/env.ts'
68import { formatSnippet , normalizeScores , sanitizeMarkdown } from '../core/index.ts'
79import { resolveSkilldCommand } from '../core/skilld-command.ts'
@@ -54,19 +56,20 @@ function mergeFilters(prefix?: SearchFilter, json?: SearchFilter): SearchFilter
5456}
5557
5658export interface SearchCommandOptions {
59+ agents ?: AgentType [ ]
5760 packageFilter ?: string
5861 filter ?: SearchFilter
5962 limit ?: number
6063}
6164
6265export async function searchCommand ( rawQuery : string , opts : SearchCommandOptions = { } ) : Promise < void > {
6366 const { packageFilter, limit : userLimit } = opts
64- const dbs = findPackageDbs ( packageFilter )
65- const versions = getPackageVersions ( )
67+ const dbs = findPackageDbs ( packageFilter , opts . agents )
68+ const versions = getPackageVersions ( process . cwd ( ) , opts . agents )
6669
6770 if ( dbs . length === 0 ) {
6871 if ( packageFilter ) {
69- const available = listLockPackages ( )
72+ const available = listLockPackages ( process . cwd ( ) , opts . agents )
7073 if ( available . length > 0 )
7174 p . log . warn ( `No docs indexed for "${ packageFilter } ". Available: ${ available . join ( ', ' ) } ` )
7275 else
@@ -180,6 +183,21 @@ Without -p, searches all installed packages.
180183Omit the query for interactive mode with live results.`
181184}
182185
186+ export type AgentFilterParseResult
187+ = | { _tag : 'All' }
188+ | { _tag : 'Selected' , agents : AgentType [ ] }
189+ | { _tag : 'Invalid' , values : string [ ] }
190+
191+ export function parseAgentFilter ( raw ?: string ) : AgentFilterParseResult {
192+ if ( raw === undefined )
193+ return { _tag : 'All' }
194+ const ids = raw . split ( ',' ) . map ( s => s . trim ( ) ) . filter ( Boolean )
195+ const unknown = ids . filter ( id => ! Object . hasOwn ( agents , id ) )
196+ if ( ids . length === 0 || unknown . length > 0 )
197+ return { _tag : 'Invalid' , values : unknown }
198+ return { _tag : 'Selected' , agents : ids as AgentType [ ] }
199+ }
200+
183201export const searchCommandDef = defineCommand ( {
184202 meta : { name : 'search' , description : 'Search indexed docs' } ,
185203 args : {
@@ -194,6 +212,11 @@ export const searchCommandDef = defineCommand({
194212 description : 'Filter by package name' ,
195213 valueHint : 'name' ,
196214 } ,
215+ agents : {
216+ type : 'string' ,
217+ description : 'Only search skills installed for these agents (comma-separated)' ,
218+ valueHint : 'names' ,
219+ } ,
197220 filter : {
198221 type : 'string' ,
199222 alias : 'f' ,
@@ -229,6 +252,16 @@ export const searchCommandDef = defineCommand({
229252 filter = parsed
230253 }
231254
255+ const agentFilter = parseAgentFilter ( args . agents as string | undefined )
256+ if ( agentFilter . _tag === 'Invalid' ) {
257+ const reason = agentFilter . values . length > 0
258+ ? `Unknown agent: ${ agentFilter . values . join ( ', ' ) } `
259+ : 'Agent filter is empty'
260+ p . log . error ( `${ reason } . Available: ${ Object . keys ( agents ) . join ( ', ' ) } ` )
261+ return
262+ }
263+ const agentTypes = agentFilter . _tag === 'Selected' ? agentFilter . agents : undefined
264+
232265 let limit : number | undefined
233266 if ( args . limit !== undefined ) {
234267 const parsed = Number ( args . limit )
@@ -240,7 +273,7 @@ export const searchCommandDef = defineCommand({
240273 }
241274
242275 if ( args . query )
243- return searchCommand ( args . query , { packageFilter, filter, limit } )
276+ return searchCommand ( args . query , { packageFilter, filter, limit, agents : agentTypes } )
244277
245278 if ( filter || limit )
246279 p . log . warn ( '--filter and --limit are ignored in interactive mode. Provide a query to use them.' )
@@ -250,6 +283,6 @@ export const searchCommandDef = defineCommand({
250283 process . exit ( 1 )
251284 }
252285 const { interactiveSearch } = await import ( './search-interactive.ts' )
253- return interactiveSearch ( packageFilter )
286+ return interactiveSearch ( packageFilter , agentTypes )
254287 } ,
255288} )
0 commit comments