Back to Fresh

Fresh — Internal Architecture Documentation

docs/internal/README.md

0.4.36.9 KB
Original Source

Fresh — Internal Architecture Documentation

AI-generated: describes Fresh's architecture and design rationale, not implementation details; where it disagrees with the source, the source is authoritative.

This directory documents how Fresh works and why: the architecture of each subsystem, the decisions and trade-offs behind it, the algorithms chosen (and the ones rejected), and the UX alternatives that were considered. It is written for contributors who need to understand or change the code, not for end users (see user docs for that).

Conventions

  • AI-generated. These docs are derived from the source and the commit history. The source is authoritative; where a doc and the code disagree, the code wins.
  • No volatile detail. Line numbers, exact constants, and source locations are omitted on purpose. Subsystems, types, and patterns are named conceptually rather than pinned to a file or line, because those drift.
  • IMPLEMENTED vs PLANNED. Each doc labels what ships today versus what is forward-looking design. Several subsystems (k8s storage, orchestrator multi-session, parts of the universal search and diff-parity work) are partly planned; the docs say so explicitly.
  • Consolidated history. This set replaces roughly 130 earlier design notes, plans, and evaluations that had accumulated here. Their rationale has been distilled into the docs below. The originals remain in git history for the full record.

Start with 00-overview.md for the runtime model and a map of everything else, and keep glossary.md open for the naming conventions (daemon / workspace / backend / Authority) and core vocabulary the other docs assume.

The documents

Foundations

DocWhat it covers
00-overview.mdThe keystone map: the crate workspace and why it's split, cargo feature gating, the entrypoint and event loop, the threading model, the client/server and daemon architecture, async message flow, the Editor central object, and the Action-vs-Event split.
glossary.mdNaming conventions (the retired "session" → daemon/workspace/backend scheme) plus a core architecture vocabulary table.

Text & editing core

DocWhat it covers
text-model.mdThe persistent path-copying piece tree (and why not a rope or gap buffer), lazy loading for multi-GB files, interval-tree markers with gravity, the Event/BulkEdit model with O(1) Arc-snapshot undo, composite buffers, and the encoding/save path.
buffers-splits-undo.mdApp-layer buffer lifecycle and identity, buffer groups, the split/window tree, per-buffer vs per-view state, undo/redo with marker displacement, and hot-exit / crash recovery.
input-keybindings-actions.mdA keystroke end-to-end: terminal key normalization, the modal dispatch priority stack, the command→action→event pipeline and why it's separated, the unified keybinding resolver, multi-cursor, and mouse hit-testing.

Rendering & language intelligence

DocWhat it covers
rendering-and-layout.mdThe per-frame render loop, the token→ViewLine pipeline, the line-wrap and visual-row caches that make huge files scroll cheaply, folding/conceal/virtual-text, split-pane layout, and the Scene projection shared with the web frontend.
syntax-highlighting.mdThe engine-selection rule (syntect TextMate grammars by default, tree-sitter for the gaps, and why), the checkpoint/convergence incremental-highlight algorithm, viewport-only scaling, category→theme mapping, and reference/bracket overlays.
lsp.mdThe multi-server LSP client: (language, feature) routing, the gate-and-retry concurrency model, async result flow, diagnostics-as-markers, completion-source merging, and feature concessions.

Extensibility & environment

DocWhat it covers
plugins.mdSandboxed TypeScript plugins on a QuickJS thread, the PluginCommand protocol and one-frame lag, the provider pattern, the declarative widget runtime, parallel package loading, the git-based marketplace, and the sandbox/security trade-offs.
remote-authority-trust.mdThe Authority backend slot (local / SSH / docker-exec / kubectl-exec), the remote agent and filesystem, heartbeat/reconnect, devcontainers, the k8s transport, Workspace Trust, and the live env provider — with a clear shipped-vs-planned line.
orchestrator-sessions.mdThe Orchestrator/Dock for many concurrent workspaces/agent sessions, session persistence and the Live/Dormant lifecycle, and the dock UX design versus what ships today.
terminal.mdThe integrated terminal: PTY spawning, the embedded fresh-winterm VT emulator (and why custom), live/scrollback per-buffer state, mouse/links/OSC52, and restore-on-reconnect.

Configuration, features & quality

DocWhat it covers
config-themes-settings.mdThe layered config overlay and resolution, JSONC with comment-preserving writes, schemars schema generation driving the Settings UI, the theme system and live preview, and the keybinding editor.
search-and-diff.mdIn-buffer search/replace, project-wide search and live grep, the diff/review (hunk) viewer and its Arc::ptr_eq piece-tree diff, git-log viewing, and the keyboard-macro system.
editor-ux-features.mdSmaller shipped features without their own doc: markdown compose/preview, code tour, the input calibration wizard, vi mode, i18n, the menu/command-palette/help/bookmarks cluster, and warning/notification UX.
testing.mdThe testing layers, the headless scenario framework (tests as data, replayed against EditorTestApi), the ANSI capture backend, the TimeSource determinism abstraction, and CI structure.

A note on history

This set replaces roughly 130 older design notes, plans, and evaluations that had accumulated here. Most documented intent (often aspirational, or already shipped and drifted) rather than the system as built. The rationale from them has been consolidated into the docs above. The originals remain in git history for the full record — for example:

git log --all --full-history -- 'docs/internal/orchestrator-sessions-design.md'
git show <commit>:docs/internal/<old-doc>.md

User-facing documentation

See the parent docs/ directory: