Thanks to visit codestin.com
Credit goes to github.com

Skip to content

11111000000/context-navigator

Repository files navigation

Emacs Context Navigator

Overview

Emacs Context Navigator is a lightweight, project‑aware context manager and sidebar for Emacs.

The idea: practice “context engineering”. Instead of keeping task state, open files, buffer selections, and notes in your head, externalize them into clear, reusable context groups per project (or globally). Switch context instantly, reduce cognitive load, and keep your focus on the work.

  • View to browse items and groups, with a compact header-line toolbar
  • Project‑aware, optional auto‑switch on buffer/project change
  • One‑way integration with GPTel (push current items → GPTel)
  • Per‑group Undo/Redo (history) with header‑line controls
  • Async, per‑group persistence with progress and spinner
  • Stats footer (counts, size, token estimates) — togglable
  • Dired‑aware “Universal Add”, globs, and “add from text”

Repository: https://github.com/11111000000/context-navigator

Screenshots

./context-navigator-items.png

./context-navigator-groups.png

./context-navigator-transient.png

Requirements

  • Emacs 29.1+ (recommended 30.1+)
  • transient 0.3.0+ (for the global menu)
  • Optional:
    • gptel (for one‑way push)
    • project.el or projectile (for project detection/auto‑switch)
    • all-the-icons (for icons in the sidebar; remember to install fonts)

Installation

Not on MELPA. Use a local checkout or straight.el from GitHub.

  • Local checkout + use-package (recommended)
(use-package context-navigator
  :load-path "~/Code/context-navigator/lisp"
  :custom
  ;; Optional, but handy: set a global key for the transient menu
  (context-navigator-global-key "C-c n")
  ;; Recommended defaults
  (context-navigator-autoload t)
  (context-navigator-autosave t)
  :config
  (context-navigator-mode 1))
  • straight.el (from GitHub)
(use-package context-navigator
  :straight (context-navigator
             :type git
             :host github
             :repo "11111000000/context-navigator")
  :custom
  (context-navigator-global-key "C-c n")
  (context-navigator-autoload t)
  (context-navigator-autosave t)
  :config
  (context-navigator-mode 1))

Notes:

  • If you don’t want a global binding, keep context-navigator-global-key as nil and use M-x context-navigator-transient.
  • If you enable icons, install fonts once: M-x all-the-icons-install-fonts.

Quick Start

  • Enable the mode: M-x context-navigator-mode (or add (context-navigator-mode 1) to your init)
  • Open the Navigator right away: M-x context-navigator-start (default display: buffer/magit-like; switch with M in transient)
  • Press your global key, e.g., C-c n, then:
    • n — toggle Navigator; M — Display Mode (buffer/sidebar)
    • a — Add (universal): region/file/buffer or Dired selection
    • f — Add files by glob (from minibuffer)
    • t — Add files from text (extracts paths from region/buffer)
    • g — show groups
    • G/A — toggle push→gptel / auto‑project
    • R — Occam filter (org-mode): minimize enabled items for the task
    • P/C — Push now / Clear gptel
  • Press ? in the sidebar for localized, column‑formatted help

Core workflows

  • Switch between task groups (project‑centric): “research”, “bug‑123”, “release”.
  • Auto‑project switching: follows your current file/gptel/Dired buffers across projects.
  • LLM sessions: push enabled items to GPTel on demand or automatically; return to saved groups anytime.
  • Adding context:
    • “Universal Add” (from Dired/region/file/buffer)
    • Add by mask (glob)
    • Add from text (extract file‑like tokens and resolve)

Practical scenarios (with GPTel/gptel-aibo)

  • Per-task groups with GPTel:
    • Create a group per task/issue; add files, buffers, and selections that matter.
    • Toggle auto-push ON and keep chatting in GPTel (or gptel-aibo minor mode in org).
    • The modeline in the Navigator shows the full path at point; indicators (●/○) reflect actual presence in GPTel.
  • Using gptel-aibo:
    • gptel-aibo buffers are treated as “interesting” for auto-project switching; Navigator will stick to the correct project while you chat.
    • Default-directory of gptel-aibo buffers is respected; switching windows updates Navigator’s project and groups list.
  • Trimming context and saving tokens:
    • Use the Occam filter (R in the transient, org-mode) to keep only essential items enabled for the current task.
    • The Stats footer (s) shows rough token estimates for enabled vs total; combine with Occam to control budget.
  • Selections and edits:
    • Add precise regions from files as “selection” items; Occam handles them safely.
    • Quickly enable/disable per item with SPC/t; Undo/Redo per group is available via header toolbar (↶/↷).
  • Multi-project work:
    • Navigator “sticks” to the last meaningful root and avoids flicker to global; throttle is configurable.
    • Use p in the transient to switch explicitly to the current buffer’s project when needed.

Usage — interface overview

  • Sidebar
    • Title inside the buffer shows “[project: group]” in Items view; Groups view shows “[project]”.
    • Toolbar in the header-line (clickable and TAB-reachable) contains all toggles and actions (shows graphical icons when all-the-icons is available; otherwise compact labels in brackets):
      • [→] push→gptel on/off
      • [A] auto-project on/off
      • [↶]/[↷] Undo/Redo history
      • [O] Open buffers (background; dynamic count; remote-aware)
      • [K] Close buffers (belonging to the current group)
      • [P] Push now
      • [T] Toggle all in gptel (“Enable all gptel” when everything is disabled; otherwise “Disable all in gptel”)
    • Per-point status is shown in the modeline; the buffer footer is minimal. In items view the modeline shows the full path of the item at point; in groups view it shows “Display — Description” when a description is set.
    • Indicators (green/gray) show whether an item is present in GPTel (when indicators are enabled).
  • Transient menu (C-c n by default)
    • Quick access to panel, groups, add, GPTel toggles, and logs.
  • Navigation
    • Items and groups are interactive. Use TAB/Shift‑TAB to move between toggles, actions, items, and groups.
    • Ret/Space: visit/preview. j/k or n/p: next/prev.

Examples:

  • Open all context buffers for a group, then Push now to ground a GPTel chat.
  • Dired: mark files and “a” (Universal Add) to collect them; if directories are included, confirm via preview.

Key bindings (summary)

  • Global (context-navigator-mode)
    • Your chosen key (e.g., C-c n) → context-navigator-transient
  • Transient (selected)
    • Panel/Project: n (toggle sidebar), p (switch to current buffer’s project)
    • Context/Groups: g (groups list), X (unload context)
    • Actions: a (Add universal), f (Add by mask), t (Add from text), o (Open buffers)
    • GPTel: G (toggle push), A (toggle auto‑project), P (push now), C (clear gptel)
    • Logs: D (toggle logs), L (open logs), K (clear logs), V (set level), F (toggle file logging)
  • Sidebar (context-navigator-view-mode)
    • RET / l: activate (visit item/open group)
    • v: preview (other window)
    • n/p/j/k: next/previous
    • SPC / t: toggle enabled for item at point
    • d: delete (item or group, depending on view)
    • g: refresh (items or groups)
    • h / u: go up (toggle items ↔ groups)
    • G: show groups list
    • a / r / e / c: add / rename / edit description / duplicate group (groups view)
    • x / A: toggle push→gptel / auto‑project
    • U: unload context (switch to global)
    • P / C: push now / clear gptel
    • O / o: open all context buffers (background)
    • K: close all context buffers
    • E: clear current group
    • s: toggle Stats footer
    • TAB / S-TAB: jump across toggles/actions/items/groups
    • q: quit, ?: menu/help

Quality‑of‑life:

  • delete-other-windows is remapped to close sidebar windows first (keeps layout).
  • Optional: protect window balancing while the sidebar is visible.

Configuration (reference tables)

Below are all public settings collected from the source, grouped by module. “Default” reflects the code defaults, not your current values.

Core (context-navigator-core.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-auto-refreshbooleantAuto refresh model/sidebar after external changescore/context-navigator-core.el
context-navigator-global-keystring or nilnilGlobal key for transient (e.g., “C-c n”); nil = no bindingcore/context-navigator-core.el
context-navigator-view-widthinteger42Sidebar width in columnscore/context-navigator-core.el
context-navigator-max-filename-lengthinteger64Max display length for file namescore/context-navigator-core.el
context-navigator-context-switch-intervalnumber0.7Throttle interval (s) for project auto‑switchcore/context-navigator-core.el
context-navigator-context-load-batch-sizeinteger64Batch size for async context loadcore/context-navigator-core.el
context-navigator-gptel-apply-batch-sizeinteger20Items per tick when pushing to GPTel in backgroundcore/context-navigator-core.el
context-navigator-gptel-apply-batch-intervalnumber0.05Delay (s) between GPTel apply batchescore/context-navigator-core.el
context-navigator-gptel-require-visible-windowbooleannilDefer GPTel apply until a GPTel window is visiblecore/context-navigator-core.el
context-navigator-gptel-visible-poll-intervalnumber0.5Poll interval (s) for GPTel visibility when deferredcore/context-navigator-core.el
context-navigator-autosavebooleantAutosave group file on model refreshcore/context-navigator-core.el
context-navigator-autosave-debouncenumber0.5Debounce (s) for autosavecore/context-navigator-core.el
context-navigator-autoloadbooleantAutoload context on project switchcore/context-navigator-core.el
context-navigator-default-push-to-gptelbooleannilInitial session state: push to GPTelcore/context-navigator-core.el
context-navigator-default-auto-project-switchbooleantInitial session state: auto‑project switchcore/context-navigator-core.el
context-navigator-dir-namestring“.context”Project subdir for context filescore/context-navigator-core.el
context-navigator-context-file-namestring“context.el”Legacy single‑file name (still used for compatibility paths)core/context-navigator-core.el
context-navigator-global-dirdirectory~/.contextGlobal context directorycore/context-navigator-core.el
context-navigator-create-default-group-filebooleantEnsure default group file exists on first usecore/context-navigator-core.el
context-navigator-protect-sidebar-windowsbooleantProtect sidebar from window‑balancing (skip balance while visible)core/context-navigator-core.el

Constants:

VariableTypeDefaultDescriptionModule/File
context-navigator-persist-versionconstant3Persist format version used across modulescore/context-navigator-core.el

Sidebar (context-navigator-view.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-auto-open-groups-on-errorbooleantAuto‑open groups list when a group fails to loadsidebar/context-navigator-view.el
context-navigator-highlight-active-groupbooleantHighlight active group in groups listsidebar/context-navigator-view.el
context-navigator-controls-stylechoice (autoiconstext)iconsLabels style for toggles/actionssidebar/context-navigator-view.el
context-navigator-openable-count-ttlnumber1.0Cache TTL (s) for openable countersidebar/context-navigator-view.el
context-navigator-openable-soft-capinteger100Soft cap for counting openable bufferssidebar/context-navigator-view.el
context-navigator-openable-remote-modechoice (lazystrictoff)lazyHow to treat remote files in “Open buffers”sidebar/context-navigator-view.el
context-navigator-gptel-indicator-poll-intervalnumber0Polling interval (s) for GPTel indicators (0 to disable)sidebar/context-navigator-view.el
context-navigator-view-spinner-frameslist of strings⠋…⠏Frames for the loading spinnersidebar/context-navigator-view.el
context-navigator-view-spinner-intervalnumber0.1Spinner animation interval (s)sidebar/context-navigator-view.el
context-navigator-view-spinner-degrade-thresholdnumber0.25Degrade to static indicator if timer slips beyond this (s)sidebar/context-navigator-view.el

Render (context-navigator-render.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-render-show-pathbooleannilShow item path in right columnrender/context-navigator-render.el
context-navigator-render-truncate-nameinteger64Max display length for item namesrender/context-navigator-render.el
context-navigator-render-indicator-stylechoice (autoiconstextoff)textGPTel presence indicators stylerender/context-navigator-render.el

Icons (context-navigator-icons.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-enable-iconsbooleantEnable icons in the sidebaricons/context-navigator-icons.el
context-navigator-icons-disable-on-remotebooleantDisable icons on remote/TRAMPicons/context-navigator-icons.el

Project detection (context-navigator-project.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-project-nonfile-modeslist of modes(gptel-mode comint-mode … dired-mode …)Non‑file modes that can represent real project contextproject/context-navigator-project.el
context-navigator-project-stick-to-last-rootbooleantStick to last known root instead of transient switches to globalproject/context-navigator-project.el

Path add / masks (context-navigator-add-paths.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-add-paths-limitinteger50Max files to add in a single operationadd-paths/context-navigator-add-paths.el
context-navigator-add-paths-index-cache-ttlnumber30.0TTL (s) for project file index cacheadd-paths/context-navigator-add-paths.el
context-navigator-add-paths-case-sensitivechoice (autoonoff)onCase sensitivity policy for basename matchingadd-paths/context-navigator-add-paths.el
context-navigator-add-paths-ignore-gitignoredbooleantPrefer sources that respect .gitignoreadd-paths/context-navigator-add-paths.el
context-navigator-add-paths-exclude-dotdirsbooleantExclude dot-directories in fallback recursionadd-paths/context-navigator-add-paths.el
context-navigator-add-paths-fallback-excludelist of strings(node_modules dist build target)Directory names excluded in fallback recursionadd-paths/context-navigator-add-paths.el
context-navigator-mask-include-dotfilesbooleannilInclude dotfiles without explicit dot componentadd-paths/context-navigator-add-paths.el
context-navigator-mask-enable-remotebooleannilAllow TRAMP mask expansionadd-paths/context-navigator-add-paths.el
context-navigator-mask-globstarbooleantEnable ** (globstar)add-paths/context-navigator-add-paths.el

Transient add (max file size) (context-navigator-transient.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-max-file-sizeinteger(* 1 1024 1024)Max file size (bytes) for recursive adds/filterstransient/context-navigator-transient.el

Logging (context-navigator-log.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-log-enabledbooleannilEnable logginglog/context-navigator-log.el
context-navigator-log-levelchoice (:error :warn :info :debug :trace):infoMinimal level to log when enabledlog/context-navigator-log.el
context-navigator-log-auto-open-on-errorbooleantOpen log buffer automatically on errorslog/context-navigator-log.el
context-navigator-log-buffer-namestringContext Navigator LogLog buffer namelog/context-navigator-log.el
context-navigator-log-max-linesinteger5000Trim log to at most N lineslog/context-navigator-log.el
context-navigator-log-truncate-lengthinteger800Truncate long messages (0/nil = no truncation)log/context-navigator-log.el
context-navigator-log-file-enablebooleannilAlso append each line to a persistent filelog/context-navigator-log.el
context-navigator-log-filefile or nilnilPath to persistent log filelog/context-navigator-log.el

I18n (context-navigator-i18n.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-languagechoice (auto en ru fr de es)autoUI language; auto detects from localei18n/context-navigator-i18n.el

Header-line controls (context-navigator-headerline.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-view-headerline-enablebooleantShow Navigator controls in the buffer header-lineheaderline/context-navigator-headerline.el

Modeline (context-navigator-view-modeline.el)

VariableTypeDefaultDescriptionModule/File
context-navigator-view-modeline-enablebooleantShow minimal per-point status in the modelinemodeline/context-navigator-view-modeline.el
context-navigator-view-modeline-facefaceshadowFace used for the modeline status textmodeline/context-navigator-view-modeline.el

Configuration examples

  • Minimal setup
(use-package context-navigator
  :custom
  (context-navigator-global-key "C-c n")   ;; or nil if you prefer M-x
  (context-navigator-autoload t)
  (context-navigator-autosave t)
  :config
  (context-navigator-mode 1))
  • Advanced setup (icons, indicators, widths, counters, auto‑project, language)
(use-package context-navigator
  ;; :straight (context-navigator :type git :host github :repo "11111000000/context-navigator")
  :custom
  ;; Basics
  (context-navigator-global-key "C-c n")
  (context-navigator-autoload t)
  (context-navigator-autosave t)
  (context-navigator-view-width 36)

  ;; Sidebar & render
  (context-navigator-controls-style 'icons)
  (context-navigator-highlight-active-group t)
  (context-navigator-openable-count-ttl 0.3)
  (context-navigator-openable-soft-cap 120)
  (context-navigator-openable-remote-mode 'lazy)
  (context-navigator-render-indicator-style 'icons)
  (context-navigator-render-show-path t)

  ;; Icons
  (context-navigator-enable-icons t)
  (context-navigator-icons-disable-on-remote t)

  ;; Project switching & persistence
  (context-navigator-context-switch-interval 0.7)
  (context-navigator-create-default-group-file t)

  ;; GPTel apply (optional deferred mode)
  ;; (context-navigator-gptel-require-visible-window t)

  ;; Language
  (context-navigator-language 'auto)

  ;; Stability with sidebar
  (context-navigator-protect-sidebar-windows t)

  :config
  (context-navigator-mode 1))

GPTel integration (one‑way)

  • Navigator never imports from GPTel. It only pushes when you ask (Push now) or when auto‑push is ON.
  • On push, Navigator resets GPTel context and adds all enabled items (files, buffers, selections).
  • Indicators (green/gray) show binary membership in GPTel next to items (when enabled).
  • Selections may require a reset under certain GPTel APIs; Navigator handles this automatically.
  • Background apply is batched, and can be deferred until a GPTel buffer is visible (see context-navigator-gptel-require-visible-window).
  • Remote files: adds warn/confirm where appropriate; GPTel add functions require readable files/buffers.

How to use:

  • Toggle auto‑push in the header ([→]) or via transient (G).
  • Press [⇪] Push now in the footer, or P in transient, for a manual reset + add.
  • Clear GPTel via footer [⌦] or transient (C).

Occam filter (AI)

Minimize enabled context for the current task described in your org buffer:

  • Where: org-mode only (appears as R “Occam filter (org)” in the transient).
  • Source: active region if any; otherwise the whole org buffer.
  • Payload: content of currently enabled items (files/buffers/selections) is included for the model to reason about.
  • Safety:
    • Warns and confirms when remote (TRAMP) content is present (configurable).
    • Warns on large payloads before sending (rough token budget is shown in Stats).
  • Parsing modes:
    • flex (default): tries strict JSON first; if absent, accepts plain identifiers (keys/paths/names). Optional cautious fuzzy matching.
    • json-only: require strict JSON; offers an automatic retry with stricter instruction on parse error.
  • Apply flow:
    • Preview counts before applying (enabled vs total); confirm or cancel.
    • Applies by enabling only the returned items; auto-push to GPTel is respected when ON.
    • Per-group Undo/Redo available via the header toolbar (↶/↷) if the result doesn’t look right.

Key options (defaults):

  • context-navigator-razor-model: “deepseek-chat”
  • context-navigator-razor-parse-mode: flex
  • context-navigator-razor-flex-allow-fuzzy: nil
  • context-navigator-razor-max-output-tokens: 256
  • context-navigator-razor-timeout: 45
  • context-navigator-razor-remote-include: t
  • context-navigator-razor-large-bytes-threshold: 600000
  • context-navigator-razor-budget-tokens-limit: 100000
  • context-navigator-razor-preview: t
  • context-navigator-undo-depth: 10

Persistence

  • Format v3, one file per group:
    • Project: <project>/.context/<group>.el
    • Global: ~/.context/<group>.el
  • state.el tracks the current group and display names.
  • Async load with batching, spinner, and progress events.
  • On unreadable/broken group file, the sidebar can auto‑open the groups list (configurable via context-navigator-auto-open-groups-on-error).

Tips:

  • The first time you open a project/global context, a default group file can be auto‑created (see context-navigator-create-default-group-file).
  • Switching groups saves the previous group automatically and loads the new one asynchronously.

Project detection

  • Roots from project.el or projectile (if available).
  • “Interesting” buffers:
    • File‑backed buffers
    • gptel/gptel-aibo buffers (derived modes and gptel-aibo minor mode)
    • Dired (and wdired) buffers
  • Auto‑switch is throttled (see context-navigator-context-switch-interval) and sticky (keep last root instead of flickering to global).
  • Child frames (posframe/popups) and certain internal buffers (e.g., corfu) are ignored.

Manual project switch at any time: M-x context-navigator-switch-to-current-buffer-project (also bound to transient “p”).

Performance and remote paths

  • “Open buffers” counter is remote‑aware:
    • off — ignore remote files
    • lazy — do not stat TRAMP paths; consider openable if no live buffer exists
    • strict — verify existence with file-exists-p even over TRAMP (may be slow)
  • Soft cap and TTL keep the counter responsive (see context-navigator-openable-soft-cap and context-navigator-openable-count-ttl).
  • Mask/glob expansion skips TRAMP by default (enable via context-navigator-mask-enable-remote only if you need it).

Troubleshooting and FAQ

  • The menu/keys don’t work?
    • Ensure context-navigator-mode is enabled and set context-navigator-global-key (or call M-x context-navigator-transient).
  • Navigator doesn’t open?
    • Try M-x context-navigator-start or M-x context-navigator-open.
  • Icons are missing?
    • Install all-the-icons and run M-x all-the-icons-install-fonts, then restart Emacs.
  • GPTel is not installed?
    • Navigator works fine without it. Push operations will no‑op with an informative message.
  • Group load failed?
    • The sidebar can auto‑open the groups list; from there you can delete or fix the group file.
  • How do I save/load/unload?
    • Save: M-x context-navigator-context-save. Load: M-x context-navigator-context-load. Unload (switch to global): M-x context-navigator-context-unload (also transient “X”).
  • How to manage groups?
    • From the sidebar groups view: a (add), r (rename), c (duplicate), d (delete).
  • How to clear GPTel or the group?
    • Press C in the sidebar (or use transient “C”) to clear GPTel. Use “E” to clear the current group.
  • Open/close all context buffers?
    • Header [O]/[K], sidebar keys O/o and K.

Contributing

Issues and pull requests are welcome. Please:

  • Include clear reproduction steps and Emacs/version info in bug reports.
  • Keep patches small and focused; prefer functional, side‑effect‑local changes.
  • Update docstrings and this README when behavior or user‑facing options change.

License

MIT — see LICENSE.

About

Emacs Context Manager

Resources

License

Stars

Watchers

Forks

Packages

No packages published