11import { createLogger } from '@sim/logger'
22import type { ExecutionContext , ToolCallResult } from '@/lib/copilot/orchestrator/types'
3- import type { MothershipResource } from '@/lib/copilot/resource-types'
4- import { VFS_DIR_TO_RESOURCE } from '@/lib/copilot/resource-types'
5- import type { WorkspaceVFS } from '@/lib/copilot/vfs'
63import { getOrMaterializeVFS } from '@/lib/copilot/vfs'
74
85const logger = createLogger ( 'VfsTools' )
96
10- /**
11- * Resolves a VFS resource path to its resource descriptor by reading the
12- * sibling meta.json (already in memory) for the resource ID and name.
13- */
14- function resolveVfsResource ( vfs : WorkspaceVFS , path : string ) : MothershipResource | null {
15- const segments = path . split ( '/' )
16- const resourceType = VFS_DIR_TO_RESOURCE [ segments [ 0 ] ]
17- if ( ! resourceType || ! segments [ 1 ] ) return null
18-
19- const metaPath = `${ segments [ 0 ] } /${ segments [ 1 ] } /meta.json`
20- const meta = vfs . read ( metaPath )
21- if ( ! meta ) return null
22-
23- try {
24- const parsed = JSON . parse ( meta . content )
25- const id = parsed ?. id as string | undefined
26- if ( ! id ) return null
27- return { type : resourceType , id, title : ( parsed . name as string ) || segments [ 1 ] }
28- } catch {
29- return null
30- }
31- }
32-
337export async function executeVfsGrep (
348 params : Record < string , unknown > ,
359 context : ExecutionContext
@@ -129,12 +103,9 @@ export async function executeVfsRead(
129103 path,
130104 totalLines : fileContent . totalLines ,
131105 } )
132- // Appends metadata of resource to tool response
133- const resource = resolveVfsResource ( vfs , path )
134106 return {
135107 success : true ,
136108 output : fileContent ,
137- ...( resource && { resources : [ resource ] } ) ,
138109 }
139110 }
140111
@@ -147,12 +118,9 @@ export async function executeVfsRead(
147118 return { success : false , error : `File not found: ${ path } .${ hint } ` }
148119 }
149120 logger . debug ( 'vfs_read result' , { path, totalLines : result . totalLines } )
150- // Appends metadata of resource to tool response
151- const resource = resolveVfsResource ( vfs , path )
152121 return {
153122 success : true ,
154123 output : result ,
155- ...( resource && { resources : [ resource ] } ) ,
156124 }
157125 } catch ( err ) {
158126 logger . error ( 'vfs_read failed' , {
0 commit comments