refactor: split shared config from OS-specific config

Introduces the seam that makes adopting upstream changes safe: config.el
holds what every machine shares, and a pcase on `system-type` at the end of
it loads exactly one OS file.  Leaves are loaded last on purpose, so they
can override shared settings such as `gptel-backend'.

  config-mac.el    seeded from mac repo 0789326 and now owned locally
  config-linux.el  new; Linux paths and binaries only
  config-local.el  per-machine, gitignored (template: config-local.example.el)

Nothing changes for the current machine.  The one line that moved -- the
eglot entry pointing elixir-ts-mode at /Users/willem/.elixir-ls/... -- was
already dead on Linux; it now lives in config-mac.el, and config-linux.el
picks `expert', any elixir-ls on PATH, or nothing at all, in that order.

Rationale: upstream already ships this exact layout (236c0e1 "refactor
config for multi-machine support"), so adopting it costs nothing and every
later upstream hunk then has an obvious correct home -- shared, mac, linux,
or not-committed.

Verified: parens/strings parse in all five .el files; `load!' arity checked
against doom-lib.el (filename &optional path noerror).
This commit is contained in:
Willem van den Ende
2026-11-03 12:25:12 +00:00
parent a06bb22444
commit a3b0c3d6e2
3 changed files with 267 additions and 2 deletions
+219
View File
@@ -0,0 +1,219 @@
;;; config-mac.el --- Mac-specific configuration -*- lexical-binding: t; -*-
;; Seeded from mac repo 157ed9a, then edited locally. This file is loaded
;; only on darwin (see the dispatch at the end of config.el); it is the
;; home for anything with a macOS path, macOS binary, or macOS-hosted
;; backend. It is no longer a pristine vendor copy -- treat it as ours.
;; Enable tool use in gptel
(setq gptel-use-tools t)
;; Always redirect reasoning tokens to a separate buffer
(setq gptel-include-reasoning "*llm-thinking*")
;;; gptel backend configuration
;; Local llama.cpp server
(setq gptel-backend (gptel-make-openai "llama.cpp"
:host "localhost:8000"
:protocol "http"
:stream t
:models '(Qwen3.6-27B-Q4_K_M.gguf
Qwen3.6-35B-A3B-MXFP4_MOE.gguf
unsloth/Qwen3-Coder-Next-GGUF:UD-IQ3_XXS
unsloth/Qwen3.5-9B-GGUF:UD-Q4_K_XL
Qwen3-Coder-Next-UD-Q4_K_XL
;; GLM models (reasoning handled globally via gptel-include-reasoning)
(GLM-4.7-Flash-Q4_K_M
:description "GLM-4.7-Flash 30B MoE Q4 (17GB)"
:request-params (:max_tokens 8192))
(GLM-4.7-Flash-UD-Q6_K_XL
:description "GLM-4.7-Flash 30B MoE Q6 XL (26GB)"
:request-params (:max_tokens 8192))))
gptel-model 'Qwen3.6-35B-A3B-MXFP4_MOE.gguf)
;; Prevent ChatGPT from being used as default
(setq-default gptel-model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K)
(setq gptel-backend (gptel-make-openai "mlx-lm"
:host "localhost:8000"
:protocol "http"
:stream t
:models '(mlx-community/Qwen3.6-27B-4bit))
gptel-model 'mlx-community/Qwen3.6-27B-4bit)
(setq gptel-backend (gptel-make-openai "mlx-studio"
:host "localhost:8080"
:protocol "http"
:stream t
:models '(inferencerlabs/Qwen3.5-35B-A3B-MLX-5.5bit))
gptel-model 'inferencerlabs/Qwen3.5-35B-A3B-MLX-5.5bit)
;; Additional backend: Ollama for smaller models
(gptel-make-ollama "Ollama"
:host "localhost:11434"
:stream t
:models '(qwen2.5-coder:7b
qwen3:0.6B
(qwen2.5-coder:32b
:description "qwen2.5 coder 32b: large coding model"
:capabilities (tools media)
:mime-types ("image/jpeg" "image/png" "image/svg"))))
;; Presets (these reference the backends defined above)
(gptel-make-preset 'explain
:system "Explain what this code does to a novice programmer."
:model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K
:backend "llama.cpp")
(gptel-make-preset 'elixir
:system "You are an expert programmer, specialising in Elixir and TDD, you live in Emacs"
:model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K
:backend "llama.cpp")
(gptel-make-preset 'elisp
:system "You are an expert programmer, specialising in Emacs Lisp and testing with ERT, you live in Emacs"
:model 'qwen3-coder-80b
:backend "llama.cpp")
;; GLM-4.7-Flash presets
;; GLM requires explicit stop tokens to prevent infinite generation
;; Fast mode: thinking disabled for quick responses
(gptel-make-preset 'glm-fast
:description "GLM-4.7-Flash without thinking (fast)"
:system "You are a coding agent living in Emacs. Be concise. Code only, minimal explanation. No preamble."
:model 'GLM-4.7-Flash-Q4_K_M
:backend "llama.cpp"
:request-params '(:chat_template_kwargs (:enable_thinking :json-false)
:max_tokens 1024
:stop ["<|user|>" "<|observation|>" "<|endoftext|>"]))
;; Thinking mode: reasoning streamed to separate buffer
;; Uses GLM-think backend (DeepSeek parser) for reasoning_content extraction
(gptel-make-preset 'glm-think
:description "GLM-4.7-Flash with thinking (reasoning in side buffer)"
:system "Think briefly. Give a short, direct final answer. No verbose explanations."
:model 'GLM-4.7-Flash-UD-Q6_K_XL
:backend "GLM-think"
:request-params '(:max_tokens 2048
:stop ["<|user|>" "<|observation|>" "<|endoftext|>"]))
(gptel-make-tool
:name "projectile-search"
:function (lambda (pattern)
(require 'projectile)
(projectile-find-file (projectile-guess-project-root))
(let* ((root (projectile-project-root))
(default-directory root)
(grep-command (concat "grep -r --exclude-dir={.git,node_modules,vendor} -I '"
pattern
" --include={'*.el','*.py','*.js','*.java','*.c','*.cpp','*.h','*.hs','*.rb','*.go','*.jsx','*.ts','*.tsx','*.scala','*.php','*.sh','*.yaml','*.yml','*.json'}"
))
(output (shell-command-to-string grep-command)))
(if (string-empty-p output)
(format "No results found for pattern: %s in project %s" pattern (or (projectile-project-name) "current"))
(if (> (length output) 3000)
(concat (substring output 0 3000) "\n... (truncated)")
output))))
:description "Search the current project using projectile. Sets working directory to project root and searches for a pattern in common source files."
:args (list '(:name "pattern"
:type "string"
:description "Search pattern to find in project files"))
:category "project")
;; GLM search tool - searches org-roam notes via ripgrep
(gptel-make-tool
:name "search_notes"
:function (lambda (query)
(let* ((roam-dir (expand-file-name "~/MyDocuments/qwan/essays/willem"))
(cmd (format "rg --type org -i -C 1 --max-count 2 --max-filesize 100K %s %s 2>/dev/null | head -100"
(shell-quote-argument query)
(shell-quote-argument roam-dir)))
(output (shell-command-to-string cmd)))
(if (string-empty-p output)
(format "No results found for: %s" query)
(if (> (length output) 3000)
(concat (substring output 0 3000) "\n... (truncated)")
output))))
:description "Search org-roam notes using ripgrep. Returns matching lines with context from the user's personal knowledge base."
:args (list '(:name "query"
:type "string"
:description "Search term or pattern to find in notes"))
:category "org-roam")
;; GLM search preset - uses the search_notes tool
(gptel-make-preset 'glm-search
:description "GLM-4.7-Flash with org-roam search"
:system "You are a helpful assistant with access to the user's org-roam knowledge base. Use the search_notes tool to find relevant information before answering. Be concise."
:model 'GLM-4.7-Flash-UD-Q6_K_XL
:backend "llama.cpp"
:tools '("search_notes"))
(defun gptel-glm-search (query)
"Search org-roam notes using GLM-4.7-Flash with tool calling.
Returns answer with org-roam links to sources."
(interactive "sSearch query: ")
(let* ((script (expand-file-name "~/dev/spikes/llm/llama-metal-openwebui/glm_search.py"))
(buf (get-buffer-create "*glm-search*")))
(with-current-buffer buf
(erase-buffer)
(org-mode)
(yas-minor-mode -1) ; Disable yasnippet to prevent < triggers
(insert (format "* Query: %s\n\nSearching...\n" query)))
(display-buffer buf)
(redisplay)
;; Run synchronously to ensure all output captured
(let ((output (shell-command-to-string
(format "python3 %s %s 2>/dev/null"
(shell-quote-argument script)
(shell-quote-argument query)))))
(with-current-buffer buf
(erase-buffer)
(insert (format "* Query: %s\n\n" query))
;; Remove everything before ==== line
(let ((clean-output (if (string-match "====\n" output)
(substring output (match-end 0))
output)))
(insert clean-output))
(goto-char (point-min))))))
;; @glm-search directive - searches org-roam with tool calling
(defun my/gptel-glm-search-run (query)
"Run glm-search script and return results."
(message "Searching org-roam for: %s..." query)
(let* ((script (expand-file-name "~/dev/spikes/llm/llama-metal-openwebui/glm_search.py"))
(output (shell-command-to-string
(format "python3 %s %s 2>/dev/null"
(shell-quote-argument script)
(shell-quote-argument query)))))
(if (string-match "====\n" output)
(substring output (match-end 0))
output)))
(defun gptel-glm-search-send ()
"Search org-roam using @glm-search or @gptel-search query on current line."
(interactive)
(let ((line (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
;; Accept both @glm-search and @gptel-search patterns
(if (string-match "@\\(?:glm\\|gptel\\)-search\\s-+\\(.+\\)$" line)
(let* ((query (string-trim (match-string 1 line)))
(result (my/gptel-glm-search-run query))
(yas-was-active (bound-and-true-p yas-minor-mode)))
(when yas-was-active (yas-minor-mode -1))
(end-of-line)
(insert "\n\n" result)
(when yas-was-active (yas-minor-mode 1)))
(message "No @glm-search or @gptel-search query found on current line"))))
;; Elixir language server. Moved out of the shared config.el, where this
;; macOS path was hard-coded and therefore dead on any other machine.
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(elixir-ts-mode
. ("sh" "/Users/willem/.elixir-ls/release/language_server.sh"))))
;;; config-mac.el ends here