Context hub and repository workflows
Nao's Context Hub gives context admins one place to browse the files that guide the agent and prepare safe repository updates. It connects a project to a context repository, keeps each user's work isolated in a worktree, and carries changes from inspection through branch review. For context editing and agent recommendations, see Context editing and recommendations. For the agent and chat flow, see Agent and chat.
Context Hub
The Context Hub is the main workspace for context files. It opens either a file-tree view or a document view, and it keeps the selected file in the page URL so users can move between views without losing their place. The route also guards access before the workspace loads. References: apps/…/_sidebar-layout.context-hub.tsx• L1-26, apps/…/context-hub.tsx• L1-14
File browsing
The file browser presents the project context as a tree and supports direct file lookup and text search. Tree and search views apply the same project and ignore rules, while context tests remain available to context admins without being exposed to the agent. It reads the connected repository when one exists. If no repository is connected, it shows the user's private draft context instead.
References: apps/…/context-explorer.routes.ts• L209-215 apps/…/context-explorer.routes.ts• L246-249 apps/…/context-explorer.routes.ts• L293-300 apps/…/context-explorer.service.ts• L469-497 apps/…/context-explorer.service.ts• L659-692
File reading
The document view reads context files and reports whether each file can be edited. This lets the UI explain why a file is read-only when Git is unavailable, the file is generated or rendered from a template, the path is supplied by a sync source, the branch belongs to another user, or the file is not tracked. Reads can include a user's worktree-only draft file when repository work is active.
References: apps/…/context-explorer.service.ts• L80-113 apps/…/context-explorer.service.ts• L183-236 apps/…/context-explorer.service.ts• L382-418 apps/…/context-explorer.service.ts• L443-467
Repository connection
The repository connection links a project to a Git provider and locates the Nao project inside that repository. A project may use a repository saved in project settings or a repository supplied by the deployment. The connection is valid only when Nao can identify one tracked nao_config.yaml and the live project does not point at a different repository. References: apps/…/context-repo.ts• L17-23, apps/…/context-repo.ts• L55-97, apps/…/context-repo.ts• L340-357, apps/…/worktree.service.ts• L55-97
Provider connection
An administrator can connect or disconnect a repository through the Context Hub workflow. Connection checks the user's provider account, links the selected repository to the project, and records its default branch for later work. References: apps/…/context-explorer.routes.ts• L171-207, apps/…/worktree.service.ts• L121-178
Worktree isolation
Each user gets an isolated Git worktree for context work. Nao creates or repairs that worktree from a matching local clone or from the connected repository, then resolves the project folder inside it. This keeps local edits separate between users while preserving the repository's history and review flow. References: apps/…/context-repo.ts• L99-121, apps/…/context-repo.ts• L160-170, apps/…/worktree.service.ts• L180-223
Worktree updates
The worktree tracks the live context commit and the selected branch. When the user asks to update it, Nao fetches missing history and moves the worktree to the target commit only when the worktree is clean. Unsaved changes therefore block a branch or commit switch instead of being overwritten. References: apps/…/worktree.service.ts• L225-272, apps/…/changes.service.ts• L397-409
Context change workflow
Repository-backed updates move through a controlled sequence: inspect files, review local changes, create or select an owned branch, commit selected files, and push the branch for review. The Context Hub exposes these steps as guarded actions rather than treating the default branch as an editing area. References: apps/…/context-explorer.routes.ts• L302-420, apps/…/branches.service.ts• L152-190
flowchart LR
A[Browse context] --> B[Inspect changes]
B --> C[Create or switch to owned branch]
C --> D[Commit selected files]
D --> E[Push branch]
E --> F[Open or update review request]
Change inspection
The change view shows modified, new, and deleted context files with line counts and file diffs. It can also compare a file between two historical commits, which lets users inspect past context pulls without changing the current worktree. References: apps/…/changes.service.ts• L38-70, apps/…/changes.service.ts• L105-127, apps/…/context-explorer.routes.ts• L302-328
Branch ownership
Branch ownership separates a user's unfinished context work from other users' branches. Users can inspect other branches, but they can commit and push only on a branch they own. Branch switching and creation require a clean worktree so the selected branch has a clear starting state. References: apps/…/branches.service.ts• L54-77, apps/…/branches.service.ts• L106-150, apps/…/branches.service.ts• L357-368
Commit preparation
Users commit only selected changed context files with an explicit message. Nao checks that the files still differ and that the current branch is an owned non-default branch before creating the commit. References: apps/…/branches.service.ts• L184-190, apps/…/branches.service.ts• L326-355
Review request
Pushing sends an owned non-default branch to the configured provider and opens a review request when one does not already exist. The review request uses the branch's commit messages and targets the repository's default branch. References: apps/…/context-explorer-pr.service.ts• L17-65
Live context synchronization
Live context synchronization keeps the deployed project aligned with a configured repository branch. Nao checks the live checkout, fetches the configured branch, and applies only a fast-forward update; the Context Hub records the result and the files that changed. References: apps/…/live-context.service.ts• L59-109, apps/…/live-context.service.ts• L124-172, apps/…/context-explorer.routes.ts• L112-169
Pull history
Each live context pull reports its old and new commits, changed file counts, and status. The history also tells the file explorer whether it can open an old diff directly or must update the worktree first. References: apps/…/context-explorer.routes.ts• L112-120, apps/…/context-explorer.routes.ts• L122-169, apps/…/worktree.service.ts• L274-315
Access and safety boundaries
Read operations degrade to a read-only view when repository access fails, while write operations require a valid repository, provider access, and an editable branch. File reads and writes stay inside the project context and reject unsafe paths, unsupported text, and stale file versions. Generated files, rendered templates, and paths replaced by sync are also read-only because direct edits would be lost.
Draft context
Without a connected repository, a user can still view and prepare private draft context files. Those drafts do not become shared repository changes until a repository-backed workflow is available. Saving content that matches the live file removes the private draft, while source-produced and production-only files remain read-only. References: apps/…/context-explorer.routes.ts• L209-215, apps/…/context-explorer.routes.ts• L293-307, apps/…/context-explorer.service.ts• L243-379
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the repository connection state, worktree state, branch list, and review-request state aligned across
getRepositoryStatusand the related branch and push actions. - Preserve the distinction between safe read access and strict write access when changing repository resolution or file access.
- Keep historical diff actions consistent with the commits available in the user's worktree.
- Keep private draft behavior aligned with repository-backed behavior for file trees, search, diffs, and discard actions.
- Keep editability guidance aligned with all source-produced paths, including generated files, rendered templates, and sync targets.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Live project origin differs from the connected repository | Repository actions stop because changes could target the wrong project | Repository resolution checks the live origin before using the worktree |
| Worktree has uncommitted changes during a branch or commit switch | The switch is refused and local edits remain intact | Branch and update actions require a clean worktree |
| User selects another user's branch for editing | Files are shown as read-only and commits or pushes are refused | Branch ownership is checked before edits, commits, and pushes |
| File hash no longer matches the version read by the user | The save fails instead of overwriting a newer change | Writes require the expected content hash |
| No tracked nao_config.yaml or more than one is found | The repository cannot be resolved as the project's context source | Project resolution returns a specific unavailable state |
| User edits a generated, rendered, or sync-owned file | The change is refused because another source would replace it | Editability checks identify source-produced paths before writes |
Key files
| File | Why to read it |
|---|---|
| apps/…/_sidebar-layout.context-hub.tsx | Defines the Context Hub route and its access boundary |
| apps/…/context-hub.tsx | Shows the top-level browser and document views |
| apps/…/context-explorer.routes.ts | Maps the Context Hub actions to protected API operations |
| apps/…/context-explorer.service.ts | Defines file browsing, search, reading, editing, source ownership, and draft behavior |
| apps/…/worktree.service.ts | Defines repository resolution, worktree setup, update, and cleanup |
| apps/…/branches.service.ts | Defines branch ownership, commits, switching, and push preparation |
| apps/…/changes.service.ts | Defines changed-file and diff views |
| apps/…/live-context.service.ts | Defines synchronization between repository content and the live project |
| apps/…/context-explorer-pr.service.ts | Defines branch push and review-request creation |
| apps/…/context-repo.ts | Defines repository connection and project-location rules |