From f13e54de6ed01ce7a9a93a9e42a85d302859c414 Mon Sep 17 00:00:00 2001 From: Astarte <93458816+eyeofastarte@users.noreply.github.com> Date: Sun, 12 Jul 2026 02:06:19 +1000 Subject: [PATCH] fix(cleanup): update MODULE_SUMMARY and remove dead MEMORY_DOC paths (#4411) (#5160) * docs: update static/js/MODULE_SUMMARY.md to reflect current ES6 frontend Rewrite the stale module summary to match the current no-build, ES6-module frontend architecture. Adds coverage of app.js orchestration, the chat/SSE pipeline (chat.js, chatStream.js, chatRenderer.js, streamingRenderer.js), new subsystems (research/, compare/, document streaming, cookbook*, skills.js), and removes the obsolete - - - - - - - - - - - +## 3. Chat Pipeline + +The largest and most central subsystem. Chat submission → backend SSE → progressive rendering of text, tools, research, documents, and UI events. + +| Module | Responsibility | +|---|---| +| **`chat.js`** | Main chat controller. Handles `handleChatSubmit`, stops/continues, builds `FormData`, posts to `/api/chat_stream`, reads the SSE stream, and dispatches each JSON event to the appropriate renderer. Tracks background streams, stalls, auto-recovery, and multi-round agent state. | +| **`chatStream.js`** | Helpers shared between streaming consumers: browser notifications, background-stream completion toasts, and `ui_control` event handling. | +| **`chatRenderer.js`** | Message DOM construction: `addMessage`, role labels, model route labels, color coding, footers, metrics, code blocks, sources boxes (`web`/`research`/`RAG`), findings box, images, report links, ask-user cards, welcome screen, and transcript utilities. | +| **`streamingRenderer.js`** | Incremental streaming renderer used by `chat.js`. Freezes finalized DOM blocks and only re-renders the growing tail to avoid flicker and O(N²) re-parsing. | +| **`streamingSegmenter.js`** | Splits a token stream into display units (text vs code fences) for `streamingRenderer.js`. | +| **`slashCommands.js`** | Slash-command registry (`/help`, `/setup`, etc.), parsing, and dispatch handlers. Exported functions are consumed by `chat.js` and `slashAutocomplete.js`. | +| **`slashAutocomplete.js`** | Composer autocomplete popup for `/` commands. | +| **`composerArrowUpRecall.js`** | Recall last user message with `↑` on an empty composer. | +| **`assistant.js`** | Assistant/persona behaviors and message styling helpers. | +| **`tts-ai.js`** | AI text-to-speech manager, enqueueing, streaming TTS, and playback button injection. | +| **`voiceRecorder.js`** | Voice recording from the composer microphone. | +| **`fileHandler.js`** | Attachment picker, paste/drop handling, upload, attachment strip rendering, pending-file management. | +| **`codeRunner.js`** | Client-side execution affordances for code blocks returned by the model. | + +--- + +## 4. Model, Endpoint, and Configuration Modules + +| Module | Responsibility | +|---|---| +| **`models.js`** | Model discovery / scanning, local model port probing, provider management, model selection UI state. | +| **`modelPicker.js`** | Composer model-picker dropdown and endpoint selection. | +| **`modelSort.js`** | Sorting helpers for model lists. | +| **`model/matchKey.js`** | Model-to-key matching helper. | +| **`providers.js`** | Provider metadata and account-management helpers. | +| **`providerDeviceFlow.js`** | OAuth device-flow support for providers. | +| **`presets.js`** | Character/preset selection, custom preset saving, inject prefix/suffix handling. | +| **`search.js`** | Web-search settings, provider selection, API key management. | +| **`settings.js`** | Settings panel (models, search, appearance, users, MCP, RAG, embedding, tokens). | +| **`admin.js`** | Admin panel and privileged user/endpoint configuration. | +| **`theme.js`** | Theme presets, custom colors, fonts, backgrounds, live theme switching. | + +--- + +## 5. Session, Sidebar, and Workspace + +| Module | Responsibility | +|---|---| +| **`sessions.js`** | Chat session list loading, creation, switching, renaming, archiving, library modal, and direct-chat creation. Tracks current session, streaming/research indicators in the sidebar. | +| **`workspace.js`** | Workspace folder path management for shell/file tool confinement. | +| **`search-chat.js`** | In-chat history search. | +| **`skills.js`** | Client-side skill library UI (load, edit, delete, test, and audit status display). | + +--- + +## 6. Knowledge, Memory, and RAG + +| Module | Responsibility | +|---|---| +| **`memory.js`** | AI memory CRUD, search/filter UI, memory extraction, count badge. | +| **`rag.js`** | Personal document RAG: load documents, add directories/files, show included paths. | +| **`group.js`** | Group-chat UI and model orchestration. | + +--- + +## 7. Document and Editor Subsystems + +| Module | Responsibility | +|---|---| +| **`document.js`** | Tabbed document editor, AI edit suggestions, Markdown/HTML/CSV editing, document streaming (`streamDocOpen`/`streamDocDelta`), and panel state. | +| **`documentLibrary.js`** | Document library modal. | +| **`editor/`** | Gallery image editor canvas modules: layers, brush, inpaint, crop, filters, state, history panel, top-bar wiring, canvas coordinate helpers, and AI model runners for inpainting/background-removal. | + +--- + +## 8. Research UI + +| Module | Responsibility | +|---|---| +| **`research/panel.js`** | Research panel UI, job list, and controls. | +| **`research/jobs.js`** | Research job polling and status rendering. | +| **`researchSynapse.js`** | Animated research-progress visualization shown inside the chat bubble during a research run. | + +--- + +## 9. Gallery, Email, Calendar, Tasks, and Notes + +| Module | Responsibility | +|---|---| +| **`gallery.js`** / **`galleryEditor.js`** | Gallery/image library and canvas editor entry points. | +| **`emailInbox.js`** / **`emailLibrary.js`** | Email inbox reader and library modal. Sub-modules handle signatures, reply recipients, state, and signature folding. | +| **`calendar.js`** / **`calendar/utils.js`** / **`calendar/reminders.js`** | Calendar views, event forms, reminders. | +| **`tasks.js`** | Scheduled task/recurring LLM job UI. | +| **`notes.js`** | Notes and todo panel, reminders, pinboard. | + +--- + +## 10. Cookbook (Model Serving) + +| Module | Responsibility | +|---|---| +| **`cookbook.js`** | Cookbook main UI: hardware fitting, presets, action panels. | +| **`cookbook-hwfit.js`** / **`cookbook-diagnosis.js`** / **`cookbook-deps-recipes.js`** | Hardware-fit scoring, dependency diagnosis, recipe handling. | +| **`cookbookDownload.js`** / **`cookbookServe.js`** / **`cookbookRunning.js`** / **`cookbookSchedule.js`** / **`cookbookPorts.js`** / **`cookbookProgressSignal.js`** | Model download/serve flow, running job cards, scheduling, port detection, and progress computation. | + +--- + +## 11. Compare and Utility Modules + +| Module | Responsibility | +|---|---| +| **`compare/index.js`** (with `compare/state.js`, `compare/stream.js`, `compare/panes.js`, `compare/selector.js`, `compare/scoreboard.js`, `compare/probe.js`, `compare/vote.js`, `compare/icons.js`) | Model compare mode: parallel streams, panes, scoring, vote UI. | +| **`censor.js`** | Text/image censor overlay toggles. | +| **`a11y.js`** | Accessibility helpers. | +| **`platform.js`** | Platform detection (macOS/Windows/Linux) and keyboard-modifier helpers. | +| **`escMenuStack.js`** | Stack manager for dismissible popups. | +| **`dragSort.js`** | Drag-to-sort shared behavior. | +| **`tourHints.js`** / **`tourAutoplay.js`** | Onboarding tour helpers. | +| **`color/hex.js`**, **`colorPicker.js`**, **`langIcons.js`**, **`util/ordinal.js`** | Small utility modules for color, language icons, and formatting. | + +--- + +## 12. Frontend Event Streaming Flow + +``` +User submits composer + └── chat.js::handleChatSubmit() builds FormData + ├── fileHandler.uploadPending() for attachments + ├── document.js saved (if a document panel is open) + └── POST /api/chat_stream + +Server responds with SSE stream + └── chat.js reads chunks via res.body.getReader() + TextDecoder + ├── Lines starting with "event:" set next-error state + └── Lines starting with "data:" carry JSON payloads + +JSON events are dispatched by "type": + delta → streamingRenderer → markdown → live reply text + agent_prep → update spinner label + tool_start → finalize text bubble; create agent-thread node with wave animation + tool_progress → append/update live stdout/stderr tail + tool_output → mark node done/failed, render output, diffs, screenshots + agent_step → finalize tool thread; create new msg-continuation bubble + doc_stream_open → document.js opens a live document + doc_stream_delta → document.js appends content to that document + research_progress → researchSynapse visualization + spinner timer + research_sources → build sources box for research + research_done → reload session history to show the report + web_sources → build web-search sources box + model_info → update role header with requested/actual model + fallback → show fallback model toast + update role label + metrics → collect/display token/cost metrics + message_saved → store database id on the message element + budget_exceeded → show budget banner + rounds_exhausted → show Continue button for step-limit hits + teacher_takeover → insert escalation banner, reset round state + skill_saved → show skill-learned banner +``` + +Foreground vs background streams: +- If the user switches sessions while a stream is running, `chat.js` pauses DOM + updates and stores the state in `_backgroundStreams`. Completion is signaled + with a sidebar dot/notifications, and the history is reloaded when the user + returns. + +--- + +## 13. What Changed from the Previous Summary + +- The frontend is now exclusively ES6-module based; the old `