Repository navigation
Studio: support source code files in workspace folders and project knowledge bases - #10395
danielhanchen merged 14 commits into
Conversation
…ject knowledge bases
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Expands Studio’s RAG/Project Knowledge Base ingestion and UI to accept and index common source-code/config files, aligning drop/upload behavior with backend parsing and folder sync.
Changes:
- Broadened backend allowed extensions, text parsing, and folder sync scanning/ignores for source/config files.
- Updated frontend accept filters and supported-name checks for Project Sources uploads/drops.
- Added backend + frontend tests covering source-file acceptance, parsing safety checks, and folder scanning behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| studio/frontend/tests/rag-source-drop-filter.test.ts | Adds regression test ensuring drops accept common code/config extensions. |
| studio/frontend/src/features/rag/types/rag.ts | Introduces a large source extension list, new accept string, and updated isSupportedSourceName. |
| studio/frontend/src/features/rag/components/use-source-drop.ts | Updates unsupported-file toast copy to mention source code. |
| studio/frontend/src/features/rag/components/project-sources-panel.tsx | Switches file picker/drop accept filters to source-capable accept list. |
| studio/frontend/src/features/rag/components/project-source-dropzone.tsx | Switches accept filter + updates toast copy for unsupported drops. |
| studio/backend/tests/test_rag_source_files_indexing.py | Adds unit tests for source parsing, BOM stripping, binary rejection, ignore dirs, and extension validation. |
| studio/backend/routes/rag.py | Expands upload validation extensions; serves text previews as text/plain fallback for text extensions. |
| studio/backend/core/rag/parsers.py | Routes all TEXT_EXTS through UTF-8-SIG decode; rejects null-byte “binary” masquerading as text. |
| studio/backend/core/rag/ingestion.py | Validates ingestion extensions against expanded allowlist. |
| studio/backend/core/rag/folder_sync.py | Skips common dependency/build dirs; scans files using expanded allowlist. |
| studio/backend/core/rag/config.py | Introduces richer extension taxonomy (BASE_TEXT_EXTS, SOURCE_TEXT_EXTS, TEXT_EXTS, ALL_UPLOAD_EXTS). |
Suppressed comments (1)
studio/frontend/src/features/rag/types/rag.ts:3
- Frontend now accepts many extensions that the backend allowlist does not appear to include (e.g.
.ipynb,.csproj,.jsonc,.json5,.geojson, etc.). This will cause confusing UX where the picker/drop accepts a file but the backend rejects it (HTTP 400 / ingestion ValueError). Align the frontend list to the backend’sALL_UPLOAD_EXTScontract (or expand backend support to match), ideally from a single shared source-of-truth or an endpoint-provided allowlist.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The direction is right, but the frontend list in studio/frontend/src/features/rag/types/rag.ts accepts extensions the backend ALL_UPLOAD_EXTS does not (.ipynb, .csproj, .jsonc, .csv, .svg), so the picker will take files the upload route answers 400 on; could you drive both from one list? Also _IGNORE_SCAN_DIRS skips bin, build, dist, obj and target, which would drop already-indexed documents for anyone whose linked folder uses those names, so I would like to understand that before reviewing. |
…d unblock build directories
hey, @danielhanchen! I've pushed a commit (latest) addressing both points:
finally. all unit tests ( |
|
Checked the updated branch: ALL_UPLOAD_EXTS now covers the frontend list and the build/dist names are gone from _IGNORE_SCAN_DIRS, thanks for both. One thing before I review: folder_sync now accepts around 290 extensions, so an already linked folder will re-scan and index files it never did before, including .env and lock files; could you confirm what that does to an existing linked repo on the next sync? |
On the next sync cycle, existing indexed files won't be touched or re-embedded unless they were modified. any newly recognized source files will be picked up as new and ingested in the background. and about So, I went ahead and added an ignore filter in resolved the conflict! |
…into fix/studio-source-files-indexing # Conflicts: # studio/backend/core/rag/folder_sync.py
Resolve conflicts with RAG_UPLOAD_EXTS (unslothai#11499) and rework the change: - backend: one SOURCE_TEXT_EXTS set folded into UPLOAD_EXTS, so every caller and the RAG_UPLOAD_EXTS narrowing keep working; parity test against the chat's TEXT_ATTACHMENT_EXTENSIONS instead of a second hand-kept list - NUL rejection only for source extensions, so .txt behaviour is unchanged - folder sync: skip venvs by pyvenv.cfg instead of the name 'env' (Terraform env/ dirs) - frontend: reuse TEXT_ATTACHMENT_EXTENSIONS from source-drop-policy (no barrel cycle), knowledge base picker accepts the same types as its drop zone, drop the extensionless names the backend would 400 on
|
Review record for #10395, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#431. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
Summary
Fixes #10300 (continuation of #8843).
Earlier, PR #9495 added support for dropping source code files (
.py,.js,.cs,.php, etc.) into the chat box. However, the backend RAG pipeline and the Project Knowledge Base still had a hardcoded list restricted to 7 document extensions (.pdf,.txt,.md,.markdown,.docx,.html,.htm).Because of this:
unsupported file type).This pull request opens up source code and configuration files for reading, parsing, indexing, and knowledge-base search across Studio.
What changes in this PR?
RAG Extensions Expansion:
.py,.js,.ts,.cs,.php,.c,.cpp,.rs,.go,.json,.yaml,.toml, etc.) to the backend's allowed extensions list incore/rag/config.py.UPLOAD_EXTSintact so existing desktop/Tauri contract tests remain completely untouched.Universal Plain-Text Parsing:
parsers.pyto route all text and source code extensions to standard UTF-8 text decoding (utf-8-sig) with BOM stripping.\x00) to safely reject corrupt or binary files masquerading as code without crashing the ingestion worker.Workspace Folder Sync Safety:
_IGNORE_SCAN_DIRS) infolder_sync.pyso scanning a project folder skips dependency and build folders (node_modules,.git,.venv,__pycache__,dist,build).Frontend Project Dropzone & File Pickers:
rag.tsas a self-contained leaf constant to prevent circular imports between the chat and rag features.Safe Document Previews:
routes/rag.pyto serve source code previews astext/plain; charset=utf-8so browsers can display them safely without script execution risks.Verification & Tests
Backend Unit Tests:
Added
studio/backend/tests/test_rag_source_files_indexing.pywith 7 tests covering:.php,.cs,.js,.py,.json,.yaml)node_modulesand.gitwhile scanning project files7 / 7 passed (100%).Frontend Tests & Checks:
tests/chat-barrel-module-scope-reads.test.ts: 16 / 16 passed (no module-scope cycle regressions).tests/project-source-save.test.ts: 10 / 10 passed.tests/rag-source-drop-filter.test.ts: 9 / 9 passed.node --test): 6,920+ tests passed cleanly.npm run typecheck): 0 errors.npm run build): completed with exit code 0.End-to-End Live Testing:
service.ts,Program.cs,main.py,index.php,deploy.yaml,config.json,app.js) to a Project Knowledge Base.[1],[2],[3]).Before:

Snapshots after the fix:





Update (maintainer rework, 915fffe)
Merged latest main (resolves the conflict with
RAG_UPLOAD_EXTSfrom #11499) and slimmed the change:SOURCE_TEXT_EXTSset incore/rag/config.pyis folded intoUPLOAD_EXTS, so routes, ingestion, folder sync and theRAG_UPLOAD_EXTSnarrowing all keep using the same name. A test pins it to the chat'sTEXT_ATTACHMENT_EXTENSIONS, so the two lists cannot drift..txt/.mdingestion is unchanged.node_modules, cache dirs and virtualenvs (bypyvenv.cfg, so a Terraformenv/folder is still indexed), plus.env*and lock files.TEXT_ATTACHMENT_EXTENSIONS(viasource-drop-policy.ts, outside the chat barrel cycle); extensionless names the backend would reject are no longer accepted.Before / after on the project Sources tab, uploading
notes.mdandindex.phpthrough the picker (Program.cs via the API: 400 before, 200 after):