Engineering/AI documentation
Document Library
Documents centralizes project documents and makes source material available for preview, chat, and analysis workflows.
Concepts: rag
Implementation Summary
Documents centralizes project documents and makes source material available for preview, chat, and analysis workflows.
Library payloads expose each document's Research Spine state. Documents remain raw sources: their source evidence units can feed governed coding, but the library must not label a document or its text as accepted research, report evidence, or a trusted Atomic artifact.
Frontend Surface
frontend/src/components/documents/DocumentsView.tsxfrontend/src/stores/documentStore.tsbackend/app/api/routes/documents.py
State, API, And Backend Contracts
Stores
frontend/src/stores/documentStore.ts- The document store is keyed by the active project id. Project changes clear documents, tags, stats, pagination, and the selected preview id before loading the next project's material.
API And Backend
backend/app/api/routes/documents.py- Document listing requires an explicit
project_id; project-facing document library views do not fall back to a global document list. - ID-based document operations require the same active
project_idused by the UI and load records by(document_id, project_id)so stale IDs from another authorized project resolve as not found. - List, get, create, and update responses include
research_spinewithartifact_state=raw_source, source evidence-unit counts, and a report-blocking policy. - Text document creation and content updates register versioned raw source evidence units. Content updates create a new document evidence source version instead of treating old source spans as silently current.
Architecture Notes
- The feature is mounted through
frontend/src/components/documents/DocumentsView.tsxand the UI navigation path recorded in the inventory. - Folder sync and file-watch registration must create
source_spanevidence units from raw file text before any later skill, agent, or report can use the material as accepted research. - There is one folder-sync implementation,
register_untracked_project_filesinbackend/app/api/routes/documents.py. The Documents view's sync route calls it, and the agent'ssync_project_documentstool reaches it throughapp/core/project_folder_sync.py(the routes register it there when they load; a tool importing a route module would close an import cycle through the Pi runtime, and without the registration the tool registers nothing). Files are matched by resolved path (by name only for path-less legacy rows), so an upload stored as<uuid>.<ext>is never registered twice, and a new file always gets its text, evidence units and index rows. The tool used to keep its own copy that matched by file name and registered bare rows (found on the live lane, 2026-09-25). - The frontmatter and manifest entries are the durable contract for agents updating this page after code changes.
- When the referenced component, store, route, agent, skill, or test behavior changes, regenerate and validate the feature documentation.
Agents, Skills, LLM, MCP, And Permissions
- RAG-related behavior depends on project context, documents, memory, or retrieval material referenced by the cited stores and routes.
Tests And Verification
tests/test_documents.pytests/test_documents.py::test_document_create_registers_raw_source_evidence_unitstests/test_documents.py::test_documents_sync_registers_raw_source_evidence_unitstests/test_project_rbac.pytests/test_spine_single_ingestion.py::test_the_agent_sync_tool_does_not_register_an_upload_againtests/test_spine_single_ingestion.py::test_the_agent_sync_tool_ingests_a_folder_file_through_the_research_spine
Related Features
Related Concepts
Compass Evidence
- Spec/task: CF-SPEC-53 / CF-657; CF-SPEC-131
- Inventory source:
docs/features/inventory.json
When To Update
- Update this page whenever the listed UI components, stores, routes, model behavior, permissions, or tests change.
- Regenerate the site and machine manifests with
python scripts/feature_docs.py --seed-missing --generate-site --check.