Skip to content

Commit 7c08719

Browse files
committed
feat(copilot): folder-aware file context in WORKSPACE.md
1 parent ad68624 commit 7c08719

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

apps/sim/lib/copilot/chat/workspace-context.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export interface WorkspaceMdData {
5757
connectorTypes?: string[]
5858
}>
5959
tables: Array<{ id: string; name: string; description?: string | null; rowCount: number }>
60-
files: Array<{ id: string; name: string; type: string; size: number }>
60+
files: Array<{ id: string; name: string; type: string; size: number; folderPath?: string | null }>
6161
oauthIntegrations: Array<{ providerId: string }>
6262
envVariables: string[]
6363
tasks?: Array<{ id: string; title: string; updatedAt: Date }>
@@ -189,9 +189,28 @@ export function buildWorkspaceMd(data: WorkspaceMdData): string {
189189
}
190190

191191
if (data.files.length > 0) {
192-
const lines = data.files.map(
193-
(f) => `- **${f.name}** (${f.id}) — ${f.type}, ${formatSize(f.size)}`
194-
)
192+
const rootFiles: typeof data.files = []
193+
const folderFiles = new Map<string, typeof data.files>()
194+
for (const f of data.files) {
195+
if (f.folderPath) {
196+
const existing = folderFiles.get(f.folderPath) ?? []
197+
existing.push(f)
198+
folderFiles.set(f.folderPath, existing)
199+
} else {
200+
rootFiles.push(f)
201+
}
202+
}
203+
const lines: string[] = []
204+
for (const f of rootFiles) {
205+
lines.push(`- **${f.name}** (${f.id}) — ${f.type}, ${formatSize(f.size)}`)
206+
}
207+
const sortedFolders = [...folderFiles.entries()].sort((a, b) => a[0].localeCompare(b[0]))
208+
for (const [folder, folderFileList] of sortedFolders) {
209+
lines.push(`- 📁 **${folder}/**`)
210+
for (const f of folderFileList) {
211+
lines.push(` - **${f.name}** (${f.id}) — ${f.type}, ${formatSize(f.size)}`)
212+
}
213+
}
195214
sections.push(`## Files (${data.files.length})\n${lines.join('\n')}`)
196215
} else {
197216
sections.push('## Files (0)\n(none)')
@@ -426,7 +445,13 @@ export async function generateWorkspaceContext(
426445
connectorTypes: connectorTypesByKb.get(kb.id),
427446
})),
428447
tables: tables.map((t, i) => ({ ...t, rowCount: rowCounts[i] ?? 0 })),
429-
files: files.map((f) => ({ id: f.id, name: f.name, type: f.type, size: f.size })),
448+
files: files.map((f) => ({
449+
id: f.id,
450+
name: f.name,
451+
type: f.type,
452+
size: f.size,
453+
folderPath: f.folderPath ?? null,
454+
})),
430455
oauthIntegrations: credentials.map((c) => ({ providerId: c.providerId })),
431456
envVariables: [],
432457
customTools: customTools.map((t) => ({ id: t.id, name: t.title })),

0 commit comments

Comments
 (0)