@@ -915,44 +915,46 @@ export function deleteWorkspaceEntry(channelId: number, input: string): void {
915915
916916/** A safe folder tree for the Files and Cowork navigation rails. */
917917export function listWorkspaceDirectories ( channelId : number ) : WorkspaceFile [ ] {
918+ const maxDepth = 2 ;
918919 if ( windowsOciStorageRequired ( channelId ) ) {
919920 const result : WorkspaceFile [ ] = [ ] ;
920- const walk = ( path : string ) : void => {
921+ const walk = ( path : string , depth : number ) : void => {
921922 const listed = listWorkspaceDirectory ( channelId , path ) ;
922923 for ( const entry of listed . files ) {
923924 if ( entry . kind !== "directory" ) continue ;
924925 result . push ( entry ) ;
925- walk ( entry . path ) ;
926+ if ( depth + 1 < maxDepth ) walk ( entry . path , depth + 1 ) ;
926927 }
927928 } ;
928- walk ( "" ) ;
929+ walk ( "" , 0 ) ;
929930 return result . sort ( ( a , b ) => a . path . localeCompare ( b . path ) ) ;
930931 }
931932 const result : WorkspaceFile [ ] = [ ] ;
932- const walk = ( path : string ) : void => {
933+ const walk = ( path : string , depth : number ) : void => {
933934 const directory = existingWorkspaceDirectory ( channelId , path ) ;
934935 for ( const entry of readdirSync ( directory . host , { withFileTypes : true } ) ) {
935936 if ( ! entry . isDirectory ( ) || entry . isSymbolicLink ( ) ) continue ;
937+ if ( ! directory . path && entry . name === "files" ) continue ;
936938 const child = directory . path ? `${ directory . path } /${ entry . name } ` : entry . name ;
937939 const host = join ( directory . host , entry . name ) ;
938940 result . push ( workspaceFileView ( child , host ) ) ;
939- walk ( child ) ;
941+ if ( depth + 1 < maxDepth ) walk ( child , depth + 1 ) ;
940942 }
941943 } ;
942- walk ( "" ) ;
944+ walk ( "" , 0 ) ;
943945 ensureChannelWorkspace ( channelId ) ;
944946 const uploads = channelFiles ( channelId ) ;
945947 result . push ( workspaceFileView ( "files" , uploads ) ) ;
946- const walkUploads = ( path : string ) : void => {
948+ const walkUploads = ( path : string , depth : number ) : void => {
947949 const directory = existingWorkspaceDirectory ( channelId , path ) ;
948950 for ( const entry of readdirSync ( directory . host , { withFileTypes : true } ) ) {
949951 if ( ! entry . isDirectory ( ) || entry . isSymbolicLink ( ) ) continue ;
950952 const child = `${ directory . path } /${ entry . name } ` ;
951953 result . push ( workspaceFileView ( child , join ( directory . host , entry . name ) ) ) ;
952- walkUploads ( child ) ;
954+ if ( depth + 1 < maxDepth ) walkUploads ( child , depth + 1 ) ;
953955 }
954956 } ;
955- walkUploads ( "files" ) ;
957+ walkUploads ( "files" , 1 ) ;
956958 return result . sort ( ( a , b ) => a . path . localeCompare ( b . path ) ) ;
957959}
958960
@@ -1087,20 +1089,6 @@ export function resolveWorldFile(channelId: number, requested: string): string {
10871089 throw new Error ( "File not found." ) ;
10881090}
10891091
1090- export function syncWorkspaceArtifacts ( channelId : number , threadId : number | null , createdBy = "agent" ) : WorkspaceFile [ ] {
1091- const files = listWorkspaceFiles ( channelId ) ;
1092- const paths = new Set ( files . filter ( ( entry ) => entry . kind === "file" ) . map ( ( entry ) => entry . path ) ) ;
1093- for ( const artifact of q ( "SELECT id, path FROM artifacts WHERE channel_id=?" , channelId ) ) {
1094- if ( ! paths . has ( String ( artifact . path ) ) ) run ( "DELETE FROM artifacts WHERE id=?" , artifact . id ) ;
1095- }
1096- for ( const file of files . filter ( ( entry ) => entry . kind === "file" ) ) {
1097- run ( `INSERT INTO artifacts (channel_id, thread_id, path, kind, created_by, size, modified, created) VALUES (?,?,?,'file',?,?,?,?)
1098- ON CONFLICT(channel_id,path) DO UPDATE SET thread_id=COALESCE(excluded.thread_id,artifacts.thread_id),size=excluded.size,modified=excluded.modified` ,
1099- channelId , threadId , file . path , createdBy , file . size , file . modified , now ( ) ) ;
1100- }
1101- return files ;
1102- }
1103-
11041092export function importAttachment ( channelId : number , threadId : number | null , token : string , name : string , createdBy : string ) : string | null {
11051093 return importWorkspaceUpload ( channelId , threadId , token , name , createdBy , "files" ) ;
11061094}
@@ -1232,13 +1220,12 @@ export function attachWorkspaceFileToMessage(
12321220 ) . lastInsertRowid ;
12331221
12341222 const worldRel = worldRelSafe ( channelId , absolute ) ;
1235- const underChannelFiles = worldRel . startsWith ( "files/" ) ;
1236- if ( ! underChannelFiles && ( absolute . startsWith ( channelWsAbs + sep ) || absolute === channelWsAbs ) ) {
1237- // Ensure Files tab sees workspace-originated artifacts
1223+ if ( [ channelWsAbs , channelFilesAbs ] . some ( ( root ) => absolute . startsWith ( root + sep ) || absolute === root ) ) {
1224+ // Explicitly attached files are durable artifacts; dependency trees are not.
12381225 run (
12391226 `INSERT INTO artifacts (channel_id, thread_id, path, kind, created_by, size, modified, created) VALUES (?,?,?,'file',?,?,?,?)
12401227 ON CONFLICT(channel_id,path) DO UPDATE SET thread_id=COALESCE(excluded.thread_id,artifacts.thread_id),size=excluded.size,modified=excluded.modified` ,
1241- channelId , threadId , worldRel . startsWith ( "workspace/" ) ? worldRel : `workspace/ ${ basename ( absolute ) } ` , createdBy , stat . size , stat . mtimeMs , now ( ) ,
1228+ channelId , threadId , worldRel , createdBy , stat . size , stat . mtimeMs , now ( ) ,
12421229 ) ;
12431230 }
12441231
0 commit comments