Context editing and recommendations
Context Hub gives authorized project users one place to find context files, edit Markdown content, review changes, and prepare those changes for publication. It also shows agent-generated recommendations beside the affected files, so a user can inspect each proposed change before it enters the user's changes. See Context hub and repository workflows for the wider repository and review flow.
Context file workspace
The Context Hub presents the same context in two related views. The document view lists the tables and documents known to the hub, while the file view exposes the full file tree, search, changes, and tests where available. Both views open a selected file in the same editing area.
File navigation
The navigator selects files by path and keeps the selected path in the page state. Table pages appear as tabs, and a document or diff replaces the main viewer. A link to a file that is not listed in the document view moves the user to the file view instead.
The explorer tree and content search use the same context boundaries. Search applies the same exclusion rules as the tree and searches designated test folders separately, so context-admin test files remain available without entering normal agent context. Search can return a limited result set or stop when it reaches its time limit, so a truncated result is not a complete statement that no other file matches.
The workspace protects edits during navigation. If the open file has unsaved content, a file switch, browser history change, or page exit asks the user to keep editing or discard the draft.
References: apps/…/context-hub.tsx• L6-14 apps/…/context-doc-view.tsx• L43-122 apps/…/context-hub-viewer.tsx• L22-59 apps/…/context-explorer.service.ts• L78-80 apps/…/context-explorer.service.ts• L469-497 apps/…/context-explorer.service.ts• L659-700
File editing
An editable file is loaded with its current content and a content hash. The user edits a local draft first, then saves it to the user's changes. The live context is not changed by the save. A file can be read-only when it is generated, rendered from a template, synced from another source, not tracked in the connected repository, or on another user's branch; the viewer explains the safe source or action when one exists.
The editor also supports new context files. These files enter the same changes area as normal edits, so they must pass through review before they become part of the live context. When no context repository is connected, edits use a project draft instead of a Git worktree. Saving content that matches the live file removes that draft.
The explorer does not allow edits to files that a sync or deployment source will replace. Generated files can point the user to a sibling annotations.md file for human notes, while rendered templates point to their source template. Production-only connection or credential files remain read-only in the draft path. This prevents a local context change from changing a managed source or test setup by accident.
References: apps/…/context-file.tsx• L13-49 apps/…/file-viewer.tsx• L213-348 apps/…/context-explorer.service.ts• L82-115 apps/…/context-explorer.service.ts• L139-237 apps/…/context-explorer.service.ts• L239-379
Markdown documents and headers
Context files use Markdown for readable agent guidance and document content. A file may start with YAML frontmatter, called a file header here, which gives the hub structured information about the document without changing its Markdown body.
Markdown content
The viewer presents Markdown as a rendered document and, when suitable, as source or split views. The source and body editors preserve the frontmatter while the user changes the Markdown body. Root RULES.md files receive a rules preview because they control how the agent works and which context it reads.
The editor shows an estimated token count for the content that the agent will read. This helps the user understand the size of the context without changing the file's meaning.
References: apps/…/file-viewer.tsx• L229-256 apps/…/file-viewer.tsx• L378-463 apps/…/context-file-header.ts• L124-132
File headers
A file header is YAML between opening and closing --- lines. Its shared fields are title, description, owner, and tags; skills can also use name. The hub can add a missing header and edit these fields as document properties. The file body stays separate from these properties.
Header checks report broken YAML, invalid fields, unknown properties, and owners who are not project users. A broken header must be fixed in Source before the property editor can change it. Generated and synced files have different ownership rules because their headers describe an external source.
References: apps/…/context-file-header.ts• L6-38 apps/…/context-file-header.ts• L74-109 apps/…/context-file-header.ts• L151-193 apps/…/file-header-editor.tsx• L22-83 apps/…/file-header-problems.tsx• L11-60
Context access boundaries
Context access rules limit which warehouse-backed context paths a user can read or edit. The rule set is resolved from the project catalog, then matched against normalized database, schema, and table identities before the path is used.
Database context access
Database access is either unenforced or enforced. In enforced mode, a missing catalog produces an empty allowed set, while known tables are deduplicated and sorted before use. Paths outside the database namespace are not treated as warehouse paths; malformed database paths are denied.
Partial database paths can match a permitted parent identity, but a full path must match its database type, database, schema, and table. Column security can then report whether a fully qualified table is full, restricted, or blocked.
References: apps/…/context-access.ts• L10-35 apps/…/context-access.ts• L37-80 apps/…/context-access.ts• L82-117 apps/…/context-access.ts• L142-169
Change review and publication
Every edit moves through a reviewable changes state before it reaches the live context. The user can inspect file diffs, select which files to include, discard unwanted changes, and then commit or publish the result through the repository workflow.
Change review
The Changes area groups local edits separately from the open file. A diff shows what the selected file will add, remove, or create. The user can discard one file or all local changes, but unsaved editor content must be saved or discarded first.
When a context repository is connected, changes belong to a branch. The user can create or switch branches, commit selected files, push the branch, and open a pull request or merge request for review. The hub also reports the current branch, last commit, live-context source, and any open review request. When no repository is connected, the changes remain a draft until the project is set up for repository use.
When the live context comes from a managed source, the repository state and live-context update state are shown separately. This distinction tells the user whether a reviewed repository change has reached the context used at runtime.
This diagram shows how an edit moves from a local draft through repository review and then into live context.
flowchart LR
A[Edit or create file] --> B[User changes]
B --> C[Review diff]
C -->|discard| D[Live context]
C -->|commit and publish| E[Branch review]
E -->|approved and merged| F[Repository update]
F --> D
References: apps/…/context-git-panel.tsx• L57-71 apps/…/context-git-panel.tsx• L299-344 apps/…/context-git-panel.tsx• L345-485 apps/…/context-explorer-git.service.ts• L18-93 apps/…/context-explorer.routes.ts• L302-420
Commit messages
The Changes area can ask the agent to write a commit message from the selected diff. The result is one short imperative line that states what changed for the analytics agent. The user can edit the message before committing it.
Message generation needs a configured project model and a non-empty change set. It describes only the selected patch, so selecting the right files is part of making the message useful.
References: apps/…/context-commit-message.service.ts• L11-40 apps/…/context-commit-message.service.ts• L43-67 apps/…/context-git-panel.tsx• L184-188 apps/…/context-git-panel.tsx• L410-425
Agent-generated recommendations
Recommendations are proposed improvements to project context derived from real agent use. They connect observed problems in chats to a suggested fix, and some carry exact file edits that the user can review or apply.
Recommendation lifecycle
Recommendations can remain open, become applied when their edits land in the user's changes, or become dismissed when the user does not want the suggestion. Open recommendations are grouped by the context files they affect and appear beside the open file when the feature is enabled.
Some recommendations contain no file patch. These require a hand edit or a change at the source. Recommendations that target a linked repository are handled through a pull request rather than a direct Context Hub edit.
References: apps/…/context-editor-recommendation-tools.ts• L83-135 apps/…/context-recommendation.routes.ts• L67-103 apps/…/context-recommendation.routes.ts• L196-221 apps/…/use-context-recommendations.ts• L11-41
Recommendation review
The file viewer shows a recommendation title and summary before the user acts. Expanding it shows a line diff for each affected context file and links back to the chats that produced the recommendation. A long list is folded so it does not hide the open file.
The Apply action is disabled while the file has unsaved edits. Dismiss changes the recommendation status and removes it from the open suggestions after the recommendation data refreshes.
References: apps/…/context-file-recommendations.tsx• L24-60 apps/…/context-file-recommendations.tsx• L129-188 apps/…/context-file-recommendations.tsx• L222-245 apps/…/context-file-recommendations.tsx• L267-296
Recommendation application
Applying a patch writes it into the user's changes, not into the live context. The apply flow accepts an unchanged file, a file that still matches the proposed old content, or a file where the changed snippet can be found safely. It reports changed files, already-correct files, and conflicts separately.
If the current file no longer contains a unique match, the system does not guess. It leaves that part as a conflict for the user or the Context Hub chat to resolve by hand. A recommendation is marked applied only when all proposed edits land; linked-repository edits remain a pull-request task.
This sequence shows how review results return to the file and recommendation views without publishing the change.
sequenceDiagram
participant U as User
participant H as Context Hub
participant S as Context change service
U->>H: Review recommendation diff
H->>S: Apply recommendation
S-->>H: Changed, unchanged, or conflict paths
H-->>U: Refresh file and recommendation state
U->>H: Resolve conflicts or review changes
References: apps/…/context-recommendation-apply.service.ts• L34-79 apps/…/context-recommendation-apply.service.ts• L124-192 apps/…/context-editor.ts• L17-31 apps/…/context-file-recommendations.tsx• L192-220
Context Hub editing chat
The Context Hub can open a separate edit chat beside the file viewer. The chat is reserved for context work and keeps its history separate from normal chat history. Only admins and context admins can edit context files through this path. See Agent and chat experience for the broader conversational lifecycle.
Agent file changes
The chat agent reads a file before editing it, then replaces one exact snippet or creates a new file. These actions save to the user's changes and become visible in the Context Hub immediately. They do not publish the change to the live context.
The same chat can list recommendations, inspect their cause and proposed edits, apply a recommendation, or change its status. This lets the user ask the agent to explain or repair a conflict while keeping the final change inside the normal review flow.
References: apps/…/context-editor.service.ts• L6-41 apps/…/context-editor-tools.ts• L43-88 apps/…/context-editor-recommendation-tools.ts• L83-135
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the shared recommendation result fields aligned with the backend apply result and the frontend conflict message. The UI uses separate changed, unchanged, and conflict paths.
- Keep file paths normalized consistently between recommendation data and Context Hub paths. Recommendations start at the project root while explorer paths start with
/. - Preserve the unsaved-edit guard when adding navigation, recommendation actions, or changes-panel actions. Applying a recommendation must not overwrite a local editor draft.
- Keep header validation and header editing aligned. Invalid YAML blocks property editing, while Source remains the repair path.
- Keep commit-message limits and the selected-file patch contract aligned between message generation and the commit composer.
- Keep the explorer tree and search aligned with
.naoignoreand exempt-folder rules, so a file is not searchable but absent from navigation or the reverse. - Keep database context path parsing aligned with warehouse access matching. A malformed path must not become an unintended allowed path.
- Keep repository status and live-context update status separate when changing branch, publish, or managed-source flows.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The open file has unsaved edits | Navigation or recommendation application could discard the draft | Block the action and ask the user to save or discard first |
| The file changed after it was read | A save could overwrite another change | Compare the expected content hash and require a reload |
| A recommendation no longer matches a unique file snippet | The full recommendation cannot be applied safely | Return a conflict and leave the edit for hand repair |
| A recommendation targets a linked repository | Direct local editing would bypass repository review | Require a pull request from the recommendations workflow |
| A file is generated, rendered, or synced | A local edit would be replaced by the next source update | Show the source guidance and keep the file read-only |
| The connected branch belongs to another user | The user could create edits that cannot be committed to that branch | Show the branch as read-only and require a user-owned branch |
| A database context path is malformed | A request could address a path outside the intended table identity | Reject the path before access is checked |
| No project model is configured for commit-message generation | No message can be generated | Ask the user to configure a model or write the message manually |
| Search reaches its file or time limit | Results do not represent the full context | Mark the response as truncated and let the user narrow the search |
Key files
| File | Why to read it |
|---|---|
| apps/…/context-doc-view.tsx | Shows document navigation, unsaved-edit protection, and the relationship between the viewer and Changes area. |
| apps/…/context-hub-file.tsx | Connects an open Context Hub file to file loading and editability guidance. |
| apps/…/file-viewer.tsx | Explains the local draft, Markdown views, header editing, save, and hash-conflict behavior. |
| apps/…/context-file-header.ts | Defines Markdown header fields, defaults, validation, and updates. |
| apps/…/context-git-panel.tsx | Shows diff review, discard, commit, branch, push, and review-request actions. |
| apps/…/context-explorer.service.ts | Defines file discovery, search, safe reads and writes, drafts, and the rules that make files editable or read-only. |
| apps/…/context-access.ts | Defines access checks for warehouse-backed context paths. |
| apps/…/context-explorer-git.service.ts | Defines repository status, branch state, review requests, and live-context update status exposed to the editing flow. |
| apps/…/context-editor-tools.ts | Defines the chat actions for reading, editing, and creating context files. |
| apps/…/context-recommendation-apply.service.ts | Defines safe application and conflict reporting for recommendation patches. |
| apps/…/context-file-recommendations.tsx | Shows how users review, apply, dismiss, and resolve recommendation results. |
| apps/…/context-commit-message.service.ts | Defines how a selected context diff becomes a short commit message. |