Skip to content

Commit dfa64bd

Browse files
committed
mothership agent cli: grep --in accepts the world/resource path a match line prints
1 parent dc455b0 commit dfa64bd

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎apps/sim/lib/mothership/agent-cli/engines/universal-grep.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ describe('universal grep', () => {
5858
expect(count.stdout).toMatch(/^\d+ \(blocks=\d+\)$/)
5959
})
6060

61+
it('accepts the world/resource path a match line prints as --in', async () => {
62+
const byPath = await runEngine('grep', ['id'], runtimeWith(CATALOG), { in: 'blocks/agent' })
63+
expect(byPath.exitCode).toBe(0)
64+
expect(byPath.stdout).toContain('blocks/agent:')
65+
expect(byPath.stdout).not.toContain('blocks/slack_v2:')
66+
const world = await runEngine('grep', ['id'], runtimeWith(CATALOG), { in: 'blocks' })
67+
expect(world.stdout).toContain('blocks/agent:')
68+
expect(world.stdout).toContain('blocks/slack_v2:')
69+
})
70+
6171
it('refuses an unknown scope with a did-you-mean and the scope list', async () => {
6272
const result = await runEngine('grep', ['x'], runtimeWith({}), { scope: 'block' })
6373
expect(result.exitCode).toBe(1)

‎apps/sim/lib/mothership/agent-cli/engines/universal-grep.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export const universalGrepCommand: AgentCliEngine = {
271271
const pattern = positionals[0]
272272
if (!pattern) {
273273
return agentCliFail(
274-
'Usage: sim grep <pattern> [--scope workflows,blocks,...] [--in <id|name>] [-i] [-C n] [--count] [--limit n]'
274+
'Usage: sim grep <pattern> [--scope workflows,blocks,...] [--in <world|id|name|world/id>] [-i] [-C n] [--count] [--limit n]'
275275
)
276276
}
277277
const scopes = parseScopes(flags)
@@ -282,12 +282,15 @@ export const universalGrepCommand: AgentCliEngine = {
282282
if (typeof context === 'string') return agentCliFail(context)
283283
const ignoreCase = flags.i === true
284284
const countOnly = flags.count === true
285-
const within = typeof flags.in === 'string' ? flags.in.toLowerCase() : undefined
286285
// `--in tables` reads as "search the tables world", so a world name narrows the scope;
287-
// anything else is a resource id or name inside the searched worlds.
288-
const withinScope = SCOPES.find((scope) => scope === within)
286+
// `--in blocks/table_v2` is the path a match line prints (world, then resource); a bare
287+
// value is a resource id or name inside the searched worlds.
288+
const within = typeof flags.in === 'string' ? flags.in.toLowerCase() : undefined
289+
const [withinHead, ...withinRest] = within ? within.split('/') : []
290+
const withinScope = SCOPES.find((scope) => scope === withinHead)
291+
const withinResource = withinScope ? withinRest.join('/') : within
289292
const searched: Scope[] = withinScope ? [withinScope] : scopes
290-
const nameFilter = withinScope ? undefined : within
293+
const nameFilter = withinResource || undefined
291294
const matches = compilePattern(pattern, ignoreCase)
292295

293296
const materialized = (

0 commit comments

Comments
 (0)