feelcouchLagrange
RU
Install

Lagrange architecture

Product and target structure — docs/dev/product.md.

A workstation for Claude Code on a single Mac: terminal + panel + windows (Projects, History, Settings, Stats) + voice + session archive + local models. Only Claude Code talks to the cloud. How to use it — guide.md; the map of windows and keys — system-map.md.

Diagrams are PlantUML, sources in diagrams/ (render locally: plantuml -tsvg docs/diagrams/*.puml; the "Projects" window displays .puml files itself).

1. Context — who talks to whom

Outside: the engineer, Lagrange as a single block, and the only cloud call — diagrams/lagrange-context.puml (C4, context level).

lagrange-context

Inside the "Lagrange" block: the containers on one Mac — diagrams/lagrange-internals.puml (C4, container level).

lagrange-internals

2. Components

Layout of hammerspoon/ (plan 3.1 M6): the groups panel/, projects/, settings/, live/, stats/, wide/, timemachine/, chat/, brief/, assistant/, links/, macos/, nav/, sessions/, scheduler/, power/ (live_delivery.lua, macos_notify.lua, wake.lua are still in the root), and the core (util, core_*, i18n, boot, workspace, vendor/, web/) stays in the root. The installer links the files of subdirectories flat into ~/.hammerspoon, so require("settings_view") did not change and we do not touch package.path. The load order and the list of groups are in hammerspoon/load-order.txt (read by install/steps-hammerspoon.sh); bin/dev/cc-layers walks the subdirectories.

Component Role Code Port / link Test
Ghostty + Claude Code sessions, status line, pj shell/cowork.zsh, claude/statusline.sh — tests/terminal.sh
Hooks tab state, similar sessions, secret guard, hints bin/hooks/cc-tab, cc-recall, cc-secret-guard, cc-notify, cc-toolhint stdin JSON from Claude Code tests/terminal.sh
Hammerspoon: panel core menu, chat, sessions, dock, sizes hammerspoon/panel/panel.lua, dock.lua, wide.lua, chat.lua, sessgroup.lua hammerspoon://cc tests/panel.sh
Projects IDE-like viewer, tree, tabs, preview projects.lua, projects_fs.lua, web/projects.* hammerspoon://cc-projects?path= tests/panel.sh
History a time machine over sessions timemachine.lua hammerspoon://cc-history tests/panel.sh
Settings / Stats parameters, checks, limits, charts settings.lua, stats.lua, web/stats.* cc-settings, cc-stats tests/terminal.sh
Palette / switcher search everything (⌃⌥O), MRU windows (⌃⌥Tab) palette.lua, switcher.lua, openin.lua, overlay.lua cc-palette tests/panel.sh, tests/terminal.sh
Voice dictation, Live, trigger word voice/, live.lua, wake.lua whisper-server 127.0.0.1:8178 tests/voice.sh
Archive and search transcript copies, FTS5 + vectors, summaries history/cchist*, archive.nosync/index.sqlite llama-server :8179 (embed), :8180 (chat) tests/history-search.sh
MCP cowork-local history_*, local_* for Claude mcp/cowork_local.py stdio tests/install.sh
Scheduler daily / every Nh / once without launchd scheduler.lua, bin/cc-sched — tests/terminal.sh
Maintenance updates, tweaks, eco, bench, log bin/cc-update, cc-tweaks, cc-eco, cc-bench, cc-log — tests/terminal.sh
Installer packages, symlinks, hooks install.sh, deps.tsv — tests/install.sh

3. Data flows — one Claude Code turn

diagrams/lagrange-hooks.puml (sequence). Hook order — claude/settings.template.json:

lagrange-hooks

Event What runs
SessionStart cc-tab, cchist sync -q
UserPromptSubmit cc-tab, cc-recall (up to 3 similar sessions into the context)
PreToolUse Bash → cc-secret-guard; * → cc-tab (pulse)
PostToolUse Bash → cc-toolhint
Notification cc-tab, cc-notify (a macOS notification with buttons)
Stop / SubagentStop cc-tab
PreCompact cchist sync -q
SessionEnd cc-tab, cchist sync -q, cchist summarize --bg

The panel does not poll Claude: cc-tab writes a state file, and the panel updates only the rows that changed (≤ 4 redraws/s).

4. Where things live

Code and config (symlinks, hooks) — diagrams/lagrange-deploy.puml (deployment).

lagrange-deploy

State, cache and local models — diagrams/lagrange-deploy-data.puml (deployment).

lagrange-deploy-data

Path What Override
~/.hammerspoon/*.lua symlinks to hammerspoon/, init.lua loads modules through boot.load —
~/.claude/settings.json, skills/ hooks, status line, skill symlinks —
~/.config/claude-cowork/ config, deny-dirs, private-patterns —
~/.cache/claude-cowork/ models, bench/, doc sites —
~/.local/state/claude-cowork/audit/YYYY-MM.jsonl change log (365 days) CC_AUDIT_DIR
<repo>/archive.nosync/ session archive + index.sqlite, local only CCHIST_ARCHIVE
ports 127.0.0.1:8178/8179/8180 whisper / embed / chat CCHIST_EMBED_PORT, CCHIST_CHAT_PORT

Key variables: CC_LANG (ru/en), CC_STATUS_LINKS=0 (no links in the status line), CC_THEME.

5. Operations

Task Command
Install / refresh links ./install.sh (--dry-run, --check, --only=hammerspoon --no-brew)
Quick health check timeout 300 bin/dev/cc-bench --quick → one line + REGRESS
Tests tests/run.sh --quick; live panel — tests/panel.sh (in the background)
Change log bin/cc-log show
Reload Hammerspoon Hammerspoon menu → Reload (or hs.reload) — a module with an error does not take down the others
Restore the window layout ⌃⌥0
Roll back a change every action prints a plan and a rollback step; a snapshot before the change is kept by cc-update, cc-tweaks

The rule for any change — diagrams/lagrange-change.puml: script → plan → confirmation → snapshot → apply → check → cc-log (or rollback).

lagrange-change

6. Decisions

Date Decision Why Rejected
2026-09 UI is Hammerspoon WebKit windows, not Electron one process, ~70 MB, 0.8% CPU at idle Electron/Tauri (memory, a second runtime)
2026-09 Models run locally (whisper, llama-server) free, no keys or telemetry paid APIs
2026-09 The archive is SQLite FTS5 + vectors in a single file no DB daemon, backup is one file an external vector DB
2026-09 The History feed is parsed in the page, not in Lua a freeze of > 1 s → 46 ms, 3.5 GB → 150 MB a Lua parser
2026-09 Modules via boot.load with error isolation a broken module doesn't take down the panel a single require for everything
2026-09 Changes are scripts with a plan and a cc-log journal few tokens, reproducible, rollback in-place edits by the model
2026-09 The company lives only in a private overlay branch main stays open and clean flags in main
2026-09 util.lua is a thin facade over core_*.lua (paths, json, proc, html, ui, fmt, state), flat files install.sh links only hammerspoon/*.lua, a subdirectory would not be picked up; old require("util") calls work without edits a core/ directory (breaks linking)
2026-09 The "Tune for me" rules are the bin/cc-settings-svc --json service; Lua only draws and calls it via hs.task (plan 3.1 M4) the logic can be checked without Hammerspoon, the UI doesn't block rules in settings_general.lua
2026-09 Building argv for cwin and cchist ask (cwin-args, ask-args) goes into the same service; localfirst.lua and settings_general.lua call it through the shared U.svcJson (core_proc.lua) (plan 3.1 M4) model/project choice can be checked without Hammerspoon argv was built in Lua
2026-09 Docker is not used a VM holds memory, has no Metal, no access to Hammerspoon/Keychain containerization

7. Assessment: what is already good, what to improve

Already good

To improve (the current map of connections — system-map.md)

Problem Risk What to do Item
i18n.lua ~2200, timemachine.lua ~1600 merge conflicts, slow edits modules of ≤ 500 lines C.14
~~panel.lua ~4860 lines~~ — split into panel_sessions/run/actions/page/drag/submit/msg/boot.lua (panel.lua is now ~560 lines, only requires and the attach(M) glue); panel_page.lua (~2200) is an accepted exception: a single HTML/CSS/JS webview template — done C.14 ✅
Buttons and icons are unclear, every window has its own styles "nothing is clear" one component set, an audit 0.1–0.4, C.12
HTML in "Projects" is rough, highlighting is incomplete does not replace an IDE an HTML sandbox, highlighting for ~25 languages, a worker 0.5–0.7
Live tests share the panel window with the user a test shifted the layout (fixed 26.09) restore in trap; later — a separate test webview E.25
REGRESS in cc-bench (panel 1.9 → 9 ms) loss of smoothness sort out before release B.7
No window-open probes slow opening isn't visible *_open_ms in cc-bench, warm-up B.8–B.9
Three separate processes on PreToolUse/PostToolUse +10–20 ms per call a single process B.11
New windows are not registered in overlay.lua and don't use keys.js different keys in different windows hook up at the next edit of a window A.4, C.15
PlantUML is not installed by default diagrams aren't validated optional brew install plantuml (GPL, Java) —

7.1. Verdict on the structure (M14, 29.09)

Checked against docs/dev/product.md §5. The structure is not yet ideal: the layers and the core are done, the physical directory layout is not.

Item of §5 Status
Dependencies point down (cc-layers) Almost: 4 violations, all inside stats (stats_ai/recs/run, workspace) — closed by M12; outside stats 0, cycles between families 0
core_* + a thin util (M1) Done; the shared hash contentHash moved to core_fmt, projects_fs re-exports it
Python bin/history do not import the UI Yes (0 hammerspoon imports)
Logic in services, UI draws (M3/M4) Stats in cc-stats is done; localfirst, settings_general — partly (M4, remainder)
Modular installation (M11) Done; module boundaries checked: voice now owns wake, wake_intent; stats — stats_recs, stats_run; awake — awake.lua. live loads wake via boot.load; without the voice module it is a stub
Subdirectories hammerspoon/{panel,projects,settings,live,os} and a load manifest No: 102 files flat, order is init.lua from install/steps-hammerspoon.sh (M6, the last of the UI)
web/kit/ No: shared code is in common.css/js, duplicated icons (M5)
bin/dev/, bin/hooks/ No: bin/ is flat (M2)
Skills by plugin, ≤ 5 in the core No (M8)
A compact code-map.md, splitting docs/ No (M9)

Order of the remainder: M12 (stats violations) → M5 → M2 → M8 → M6 → M9. After M12, cc-merge-check switches from a note to a hard check (cc-layers --strict, already wired as report-only).

8. Diagrams in detail

Each diagram answers one question, with no more than 8–10 blocks (rules and code — claude/skills/sysdoc/SKILL.md, every block is a real file/function/port). Overloaded topics (context, panel, voice, search, local-first, placement) are split into a pair of smaller diagrams.

Diagram Question Source
Boot How Hammerspoon starts: init.lua → boot.load per module (error isolation, stub), the panel's first render, warm-up timers (palette) lagrange-boot.puml
Panel: structure Which modules panel.lua is assembled from (dock/wide/chat/sessgroup/suggest/localfirst/screenlayout/assistant/util+i18n), plus panel.lua itself, now a core + panel_sessions/run/actions/page/drag/submit/msg/boot.lua, each attached via require("panel_x").attach(M) (the diagram is waiting to be updated for the new split) lagrange-panel.puml
Panel: render pipeline How a state change becomes pixels: a coalescer ≤4/s, html() vs partial evaluateJavaScript(), deferral while a field has focus lagrange-panel-render.puml
Session state The lifecycle of a session row in bin/hooks/cc-tab (started/working/waiting/done/ended), which hook triggers a transition lagrange-session-state.puml
Search: recall on every prompt The cc-recall hook: FTS5 + local embeddings via llama-server :8179, hybrid ranking, up to 3 sessions into the context lagrange-search.puml
Search: explicit query / MCP history_search via the cowork-local MCP or "find ..." in chat — the same cchist, with no auto-run on every prompt lagrange-search-mcp.puml
Voice: dictation Hotkey → recording → whisper-server :8178 /inference → text into the panel/Ghostty lagrange-voice.puml
Voice: Live dialogue ⌃⌥V — listen, classify, Claude's answer aloud (piper-tts, barge-in) lagrange-voice-live.puml
Voice: standing mode ⌃⌥K — a trigger word at any moment, no key hold lagrange-voice-wake.puml
Projects projects.lua/projects_fs.lua/web/projects.*, deny-dirs, cc-projects?path=, pj, a link in the status line, preview (PlantUML, search) lagrange-projects.puml
Scheduler and updates cc-sched jobs (daily/every Nh/once) in scheduler.lua, cc-update check/plan/apply, cc-tweaks, cc-log lines lagrange-scheduler-update.puml
Local-first: triage Rule/evacuation/model — how cc-route/localfirst.lua decide whether to answer locally or hand off to Claude lagrange-local-first.puml
Local-first: after the decision A local answer with an escalation check, or sending to Claude (and the offline queue net.lua) lagrange-local-first-answer.puml

Boot

Boot

Panel: structure

Panel: structure

Panel: render pipeline

Panel: render pipeline

Session state

Session state

Search: recall on every prompt

Search: recall

Search: explicit query / MCP

Search: explicit query

Voice: dictation

Voice: dictation

Voice: Live dialogue

Voice: Live dialogue

Voice: standing mode

Voice: standing mode

Projects

Projects

Scheduler and updates

Scheduler and updates

Local-first: triage

Local-first: triage

Local-first: after the decision

Local-first: after the decision

9. Limitations