Skip to content

Commit c9878a8

Browse files
committed
agent cli grep: the searchable text leads with the resource's name and description
1 parent b2c8fca commit c9878a8

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ describe('universal grep', () => {
133133
expect(result.stdout).not.toContain('sk-should-never-appear')
134134
})
135135

136+
it('matches a resource by its own name, not only its body', async () => {
137+
// `grep fx-` in an fx-* workspace found nothing: a workflow's state carries no name.
138+
const result = await runEngine(
139+
'grep',
140+
['fx-etl'],
141+
runtimeWith({
142+
'/api/v2/workflows': { data: [{ id: 'wf-1', name: 'fx-etl' }], nextCursor: null },
143+
'/api/v2/workflows/wf-1/state': { data: { blocks: {}, edges: [] } },
144+
}),
145+
{ scope: 'workflows' }
146+
)
147+
expect(result.exitCode).toBe(0)
148+
expect(result.stdout).toContain('workflows/fx-etl (wf-1):')
149+
expect(result.stdout).toContain('name: fx-etl')
150+
})
151+
136152
it('reports no matches honestly', async () => {
137153
const result = await runEngine('grep', ['zzz-nope'], runtimeWith(CATALOG), { scope: 'blocks' })
138154
expect(result.exitCode).toBe(0)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
import { LRUCache } from 'lru-cache'
23
import type { ReadFileTextResponse } from 'sim/embed'
34
import {
@@ -95,8 +96,17 @@ async function mapConcurrent<T, R>(
9596
return results
9697
}
9798

99+
/**
100+
* The searchable text leads with the resource's own name and description: a workflow's
101+
* state carries neither, so `grep fx-` in an `fx-*` workspace found nothing.
102+
*/
98103
function render(scope: Scope, id: string, label: string, value: unknown): Materialized {
99-
return { scope, id, label, text: JSON.stringify(value, null, 2) }
104+
const description =
105+
isRecordLike(value) && typeof (value as Record<string, unknown>).description === 'string'
106+
? (value as Record<string, unknown>).description
107+
: ''
108+
const header = `name: ${label}${description ? `\ndescription: ${description}` : ''}\n`
109+
return { scope, id, label, text: `${header}${JSON.stringify(value, null, 2)}` }
100110
}
101111

102112
/** One materializer per scope: the list, then each resource as its `get` returns it. */

0 commit comments

Comments
 (0)