Skip to content

Commit 12fe89a

Browse files
committed
mothership agent-cli: grep --in <world> narrows the scope; docs-search fallback names CLI commands
- universal grep: --in with a world name (tables, blocks, …) searches that world instead of filtering resources by a name that never matches; the no-match line lists only the worlds actually searched. - docs search: the shortfall notes point at blocks get / blocks tips instead of a glob() the agent surface does not have. Claude-Session: https://claude.ai/code/session_01HFVhPDtRZuCgupPco633w8
1 parent d6d8a64 commit 12fe89a

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,19 @@ export const universalGrepCommand: AgentCliEngine = {
241241
const ignoreCase = flags.i === true
242242
const countOnly = flags.count === true
243243
const within = typeof flags.in === 'string' ? flags.in.toLowerCase() : undefined
244+
// `--in tables` reads as "search the tables world", so a world name narrows the scope;
245+
// anything else is a resource id or name inside the searched worlds.
246+
const withinScope = SCOPES.find((scope) => scope === within)
247+
const searched: Scope[] = withinScope ? [withinScope] : scopes
248+
const nameFilter = withinScope ? undefined : within
244249
const matches = compilePattern(pattern, ignoreCase)
245250

246251
const materialized = (
247-
await Promise.all(scopes.map((scope) => MATERIALIZERS[scope](runtime)))
252+
await Promise.all(searched.map((scope) => MATERIALIZERS[scope](runtime)))
248253
).flat()
249-
const candidates = within
254+
const candidates = nameFilter
250255
? materialized.filter(
251-
(m) => m.id.toLowerCase() === within || m.label.toLowerCase().includes(within)
256+
(m) => m.id.toLowerCase() === nameFilter || m.label.toLowerCase().includes(nameFilter)
252257
)
253258
: materialized
254259

@@ -282,7 +287,7 @@ export const universalGrepCommand: AgentCliEngine = {
282287
}
283288
if (out.length === 0) {
284289
return agentCliOk(
285-
`No matches for ${JSON.stringify(pattern)} in ${scopes.join(', ')}${within ? ` within "${within}"` : ''}.`
290+
`No matches for ${JSON.stringify(pattern)} in ${searched.join(', ')}${nameFilter ? ` within "${nameFilter}"` : ''}.`
286291
)
287292
}
288293
const truncated =

apps/sim/lib/mothership/tools/server/docs/search-docs.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ describe('searchDocsServerTool', () => {
8080
const output = await searchDocsServerTool.execute({ query: 'brand new feature' }, CONTEXT)
8181

8282
expect(output.note).toContain('search index may lag')
83-
expect(output.note).toContain('read it directly')
84-
expect(output.note).toContain('glob("docs/**")')
83+
expect(output.note).toContain('blocks tips')
8584
})
8685

8786
it('explains an empty result set caused by filtering, so it does not read as missing docs', async () => {

apps/sim/lib/mothership/tools/server/docs/search-docs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface SearchDocsOutput {
3131
function shortfallNote(outcome: Awaited<ReturnType<typeof searchDocs>>): string | undefined {
3232
const { results, candidatesConsidered, droppedBelowThreshold, droppedStale } = outcome
3333
if (results.length === 0 && candidatesConsidered === 0) {
34-
return 'No indexed candidates were returned. The search index may lag the live docs. If you know the page, read it directly; otherwise use glob("docs/**") to find the current path.'
34+
return 'No indexed candidates were returned. The search index may lag the live docs. Rephrase the query, or read the block definition and tips directly (blocks get / blocks tips).'
3535
}
3636
if (droppedBelowThreshold === 0 && droppedStale === 0) return undefined
3737

@@ -46,7 +46,7 @@ function shortfallNote(outcome: Awaited<ReturnType<typeof searchDocs>>): string
4646
const dropped = reasons.join(' and ')
4747

4848
return results.length === 0
49-
? `No relevant matches. The search index returned ${candidatesConsidered} candidate(s), but ${dropped} — this does NOT mean the docs lack this topic. Rephrase the query, widen it by dropping the path scope, or browse with glob("docs/**").`
49+
? `No relevant matches. The search index returned ${candidatesConsidered} candidate(s), but ${dropped} — this does NOT mean the docs lack this topic. Rephrase the query, widen it by dropping the path scope, or read the block definition and tips directly (blocks get / blocks tips).`
5050
: `Returned ${results.length} of ${candidatesConsidered} candidate(s); ${dropped}. Rephrase or widen the query if these look off-topic.`
5151
}
5252

0 commit comments

Comments
 (0)