How h-ohsaki/chatgpt-el works
Main Components
• Emacs Client:
• chatgpt.el (and optionally llama.el) are the Emacs Lisp modules that manage user interaction.
• These modules define keybindings (e.g., C-c q for submitting queries and C-c Q for inserting responses) and handle the flow of query text/response within Emacs.
• Node.js Script Backend:
• The “chatgpt” script is built on Node.js and uses Puppeteer to control the browser.
• This component also harnesses helper modules like html-to-text to process HTML responses from the AI website.
• Browser Component:
• A CDP-enabled Chromium/Chrome browser instance running with remote debugging (typically on port 9000) that renders the ChatGPT/Gemini/Claude interface.
• External AI Services:
• The actual ChatGPT, Gemini, Claude, or DeepSeek pages that the browser visits to get responses.
• (Optional) Logging/Configuration:
• Although minimal in the file structure, there is a directory “screenshot” (and an “overview.dit” file) that may serve as additional documentation or debugging aids.
Relationships and Data Flow
• The Emacs client initiates a query (by capturing ergonomically defined key events) and forwards it to the Node.js script.
• The Node.js script (using Puppeteer) connects to the running browser instance via the CDP, navigates to the appropriate AI service page, and submits the query.
• The AI service provides a reply which is captured by the Node.js process.
• Processed data (possibly converting from HTML to text) is sent back to Emacs to be displayed or inserted in the current buffer.
Architectural Patterns and Design Principles
• Separation of Concerns: The Emacs Lisp and Node.js components are neatly divided. Emacs handles UI/interaction, while Node.js handles browser automation and data processing.
• Remote Control Pattern: The Node.js script remotely controls the browser using CDP to simulate user interactions.
• Modular Integration: External dependencies (Puppeteer, html-to-text) and configurable runtime parameters (e.g., remote debugging port) are clearly delineated.
• Lightweight and Extensible: The code structure allows flexibility (for example, alternative AI backends via command line options like “-e gemini” or “-e claude”).
Relevant Technologies and Frameworks
• Emacs Lisp for the client-side integration.
• Node.js, Puppeteer for remote browser control via CDP.
• Chromium/Chrome for hosting the AI service webpage.
• HTML-to-text for processing service responses.
• The file “overview.dit” and various screenshots provide auxiliary documentation for visual design elements.