Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/sim/lib/mothership/agent-cli/file-provenance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ describe('file provenance at the actual CLI and model-result boundary', () => {
)
})

it('answers files search as a search, refused until its results report provenance', async () => {
const result = await runCli({ kind: 'cli', argv: ['files', 'search', '--query', 'CANARY'] })
expect(result.success).toBe(false)
expect(JSON.stringify(result)).toContain('grep <pattern> --scope files')
expect(mocks.reference).not.toHaveBeenCalled()
expect(mocks.file).not.toHaveBeenCalled()
expect(mocks.stream).not.toHaveBeenCalled()
})

it('refuses an unknown file through the actual CLI text read without loading its bytes', async () => {
classify('unknown')
const result = await runCli(readFile)
Expand Down
15 changes: 15 additions & 0 deletions apps/sim/lib/mothership/agent-cli/file-read-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
v2DownloadFileContract,
v2ListFileFoldersContract,
v2ReadFileTextContract,
v2SearchFileContentContract,
} from '@/lib/api/contracts/v2/files'
import {
authenticateV2ApiKey,
Expand Down Expand Up @@ -54,6 +55,8 @@ export function createFileReadTransport(context: {
`${basePath}${v2ListFileFoldersContract.path}`,
`${basePath}${v2BulkDownloadFilesContract.path}`,
])
/** Search results quote file text but name no file provenance, so Chat cannot admit them. */
const searchPath = `${basePath}${v2SearchFileContentContract.path}`
/**
* Admits one delivery's classification into the invocation registry. A delivery it refuses is
* either withheld (text and forwarded responses reach only the model, so refusing them is enough)
Expand Down Expand Up @@ -135,6 +138,18 @@ export function createFileReadTransport(context: {
) {
return forward(input, init)
}
if (url.pathname === searchPath) {
return Response.json(
{
error: {
code: 'FORBIDDEN',
message:
'files search is unavailable in Chat. Search file contents with grep <pattern> --scope files.',
},
},
{ status: 403 }
)
}
const match = /^([^/]+)(\/text)?$/.exec(url.pathname.slice(prefix.length))
if (!match) return forward(input, init)
const request = new NextRequest(new Request(input, init))
Expand Down
Loading