Skip to content

[v0.5] Add agent-safe file reload #48

Description

@owainlewis

Goal: Let Cortex safely notice and reload files changed on disk by an external tool or coding agent.

Context: The core agent workflow is intentionally file-system based: an agent edits files on disk and Cortex reflects those changes.
Before an embedded terminal pane matters, Cortex needs reload behavior that cannot silently destroy local edits.
This issue should be manual and explicit before any watcher is added.

Proposed approach:

  • Track enough file metadata at open/save time to detect a newer or changed on-disk file.
  • Add a command such as revert-buffer or reload-file for manual reload.
  • If the buffer is clean and the file changed on disk, reload it and preserve a sensible point location.
  • If the buffer is dirty, refuse automatic replacement and show a clear warning.
  • Show a restrained disk-changed indicator in the modeline when a clean or dirty open file differs from disk.
  • Keep missing file and save error behavior clear.

Acceptance criteria:

  • A clean buffer can be manually reloaded after the file changes on disk.
  • A dirty buffer is not overwritten by reload without an explicit forced path.
  • The modeline shows that the disk copy changed.
  • Saving updates the clean disk baseline and removes the changed indicator.
  • Missing files, deleted files, and permission errors report clear status messages.
  • Existing editing, undo, search, picker, save, and quit behavior still works.

Verification:

  • Run cargo test.
  • Manually open a file, edit it outside Cortex while clean, reload, and confirm the new content appears.
  • Manually edit both in Cortex and outside Cortex, try reload, and confirm local unsaved edits are protected.
  • Manually save after external change and confirm status/modeline behavior is clear.
  • Manually confirm terminal cleanup after exit.

Out of scope:

  • File watching.
  • Merge UI.
  • Inline diff display.
  • Project-wide refresh.
  • Agent process management.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions