From bf464f6e3467b2e2411943a3da717b13391c1ff8 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:00:03 +0200 Subject: [PATCH 01/15] `dump1090` NixOS module --- hosts/sisko/default.nix | 2 ++ modules/dump1090/default.nix | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 modules/dump1090/default.nix diff --git a/hosts/sisko/default.nix b/hosts/sisko/default.nix index 9daa84c..13a9b0d 100644 --- a/hosts/sisko/default.nix +++ b/hosts/sisko/default.nix @@ -36,6 +36,8 @@ "amule" "adguard-home" "garmin-grafana" + # "dump1090" + "arbi" ] ++ [ ./disko.nix diff --git a/modules/dump1090/default.nix b/modules/dump1090/default.nix new file mode 100644 index 0000000..cf74a4e --- /dev/null +++ b/modules/dump1090/default.nix @@ -0,0 +1,31 @@ +{ + pkgs, + ... +}: +let + dump1090-flake = builtins.getFlake "github:NixOS/nixpkgs/541f05042033467730fb8cedb08355dc91b94c74"; + inherit (dump1090-flake.legacyPackages.${pkgs.system}) dump1090-fa; +in +{ + imports = [ "${dump1090-flake}/nixos/modules/services/misc/dump1090-fa.nix" ]; + + hardware.rtl-sdr.enable = true; + + disabledModules = [ "services/misc/dump10190-fa.nix" ]; + documentation.nixos.enable = false; + + services.dump1090-fa = { + enable = true; + package = dump1090-fa; + }; + + services.nginx.virtualHosts."dump1090.sisko.wg.aciceri.dev" = { + forceSSL = true; + useACMEHost = "aciceri.dev"; + locations = { + "/".alias = "${dump1090-fa}/share/dump1090/"; + "/data/".alias = "/run/dump1090-fa/"; + }; + serverAliases = [ "dump1090.sisko.zt.aciceri.dev" ]; + }; +} From 40b8028383e1c0b0a24a74f946d6fc214e168586 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:00:30 +0200 Subject: [PATCH 02/15] Add `tidal` package to emacs --- packages/emacs/packages.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/emacs/packages.nix b/packages/emacs/packages.nix index 73c6e96..5123818 100644 --- a/packages/emacs/packages.nix +++ b/packages/emacs/packages.nix @@ -206,6 +206,7 @@ let mixed-pitch visual-replace org-super-agenda + tidal # org-re-reveal # FIXME very not nice hash mismatch when building ] ) From f2da144a9271e07b50b963192e4641c4fa15deb5 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:00:37 +0200 Subject: [PATCH 03/15] Add `typst-ts-mode` to emacs --- packages/emacs/packages.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/emacs/packages.nix b/packages/emacs/packages.nix index 5123818..9ab2c44 100644 --- a/packages/emacs/packages.nix +++ b/packages/emacs/packages.nix @@ -223,6 +223,9 @@ let eat corfu-terminal haskell-ts-mode + ]) + ++ (with epkgs; [ + typst-ts-mode # why this doesn't seem to be in elpaPackages? ]); in mainPackages ++ (builtins.attrValues extraPackages) From 8fcc7106c3a6930d63c72f6955c729336a5cd1fa Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:00:57 +0200 Subject: [PATCH 04/15] Update `garmin-grafana` --- modules/garmin-grafana/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/garmin-grafana/default.nix b/modules/garmin-grafana/default.nix index 90795e6..e75b15b 100644 --- a/modules/garmin-grafana/default.nix +++ b/modules/garmin-grafana/default.nix @@ -5,7 +5,8 @@ ... }: let - garmin-grafana-flake = builtins.getFlake "github:NixOS/nixpkgs/1f03fefb44665cd2377912033de22ffaba2be48d"; + rev = "f24579d13ee035af96d4a68b765af2aa4b1018b6"; + garmin-grafana-flake = builtins.getFlake "github:NixOS/nixpkgs/${rev}"; inherit (garmin-grafana-flake.legacyPackages.${pkgs.system}) garmin-grafana; in { From 58cfa8ee1fa0505fa2dc36abfe62940ba29c64bf Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:02:18 +0200 Subject: [PATCH 05/15] Use amule module from my PR --- modules/amule/default.nix | 56 ++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/modules/amule/default.nix b/modules/amule/default.nix index 9752f8f..6416e9f 100644 --- a/modules/amule/default.nix +++ b/modules/amule/default.nix @@ -1,34 +1,46 @@ -{ config, lib, ... }: +{ config, pkgs, ... }: +let + rev = "966199fe1dccc9c6c7016bdb1d9582f27797bc02"; + amule-flake = builtins.getFlake "github:NixOS/nixpkgs/${rev}"; + inherit (amule-flake.legacyPackages.${pkgs.system}) amule-daemon amule-web; +in { - users.users.amule = { - isSystemUser = true; - group = "amule"; - extraGroups = [ "amule" ]; - home = config.services.amule.dataDir; - }; + disabledModules = [ "services/networking/amuled.nix" ]; + documentation.nixos.enable = false; + + imports = [ "${amule-flake}/nixos/modules/services/networking/amuled.nix" ]; - users.groups.amule = { }; services.amule = { - dataDir = "/mnt/hd/amule"; enable = true; - user = "amule"; + package = amule-daemon; + amuleWebPackage = amule-web; + openPeerPorts = true; + openWebServerPort = true; + # TODO the service is accessible only from the VPN + # however better using agenix + ExternalConnectPasswordFile = pkgs.writeText "password" "pippo"; + WebServerPasswordFile = pkgs.writeText "password" "pippo"; + settings = { + eMule = { + IncomingDir = "/mnt/hd/amule"; + TempDir = "/mnt/hd/amule/Temp"; + }; + WebServer = { + Enabled = 1; + }; + }; }; - # sometimes the service crashes with a segfeault without any reason... - systemd.services.amuled.serviceConfig.Restart = lib.mkForce "always"; - environment.persistence."/persist".directories = [ config.services.amule.dataDir ]; - networking.firewall = { - allowedTCPPorts = [ 4662 ]; - allowedUDPPortRanges = [ - { - from = 4665; - to = 4672; - } - ]; + services.nginx.virtualHosts."amule.sisko.wg.aciceri.dev" = { + forceSSL = true; + useACMEHost = "aciceri.dev"; + locations."/" = { + proxyPass = "http://localhost:${builtins.toString config.services.amule.settings.WebServer.Port}"; + }; + serverAliases = [ "amule.sisko.zt.aciceri.dev" ]; }; - } From 995af1451562f006b2045af4f419433707d99cb0 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:02:32 +0200 Subject: [PATCH 06/15] Disable spotify at startup --- hmModules/spotify/default.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/hmModules/spotify/default.nix b/hmModules/spotify/default.nix index 59b2edd..5bc0a6d 100644 --- a/hmModules/spotify/default.nix +++ b/hmModules/spotify/default.nix @@ -9,18 +9,18 @@ in { home.packages = [ spotify-adblocked ]; - systemd.user.services.spotify-adblocked = { - Install.WantedBy = [ "graphical-session.target" ]; + # systemd.user.services.spotify-adblocked = { + # Install.WantedBy = [ "graphical-session.target" ]; - Unit = { - Description = "Spotify"; - PartOf = [ "graphical-session.target" ]; - }; + # Unit = { + # Description = "Spotify"; + # PartOf = [ "graphical-session.target" ]; + # }; - Service = { - ExecStart = lib.getExe spotify-adblocked; - Restart = "on-failure"; - RestartSec = 3; - }; - }; + # Service = { + # ExecStart = lib.getExe spotify-adblocked; + # Restart = "on-failure"; + # RestartSec = 3; + # }; + # }; } From cc3a0012b595cd991bb91abe1ce9c0b34c11cbb0 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:02:43 +0200 Subject: [PATCH 07/15] `services.gpg-agent.pinentryPackage` option renamed --- hmModules/gpg/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hmModules/gpg/default.nix b/hmModules/gpg/default.nix index f245f26..abef97c 100644 --- a/hmModules/gpg/default.nix +++ b/hmModules/gpg/default.nix @@ -2,7 +2,7 @@ { services.gpg-agent = { enable = true; - pinentryPackage = pkgs.pinentry-rofi.override { + pinentry.package = pkgs.pinentry-rofi.override { rofi = pkgs.rofi-wayland; }; extraConfig = '' From 39b276d691c3c327b90020c016a58c0429162c7a Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:03:13 +0200 Subject: [PATCH 08/15] Remove OS icon from prompt --- hmModules/shell/catppuccin_mocha.omp.json | 61 +++++++++++++++++++++++ hmModules/shell/default.nix | 7 ++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 hmModules/shell/catppuccin_mocha.omp.json diff --git a/hmModules/shell/catppuccin_mocha.omp.json b/hmModules/shell/catppuccin_mocha.omp.json new file mode 100644 index 0000000..c5c74c8 --- /dev/null +++ b/hmModules/shell/catppuccin_mocha.omp.json @@ -0,0 +1,61 @@ +{ + "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", + "palette": { + "os": "#ACB0BE", + "closer": "p:os", + "pink": "#F5C2E7", + "lavender": "#B4BEFE", + "blue": "#89B4FA" + }, + "blocks": [ + { + "alignment": "left", + "segments": [ + { + "foreground": "p:blue", + "style": "plain", + "template": "{{ .UserName }}@{{ .HostName }} ", + "type": "session" + }, + { + "foreground": "p:pink", + "properties": { + "folder_icon": "..\ue5fe..", + "home_icon": "~", + "style": "agnoster_short" + }, + "style": "plain", + "template": "{{ .Path }} ", + "type": "path" + }, + { + "foreground": "p:lavender", + "properties": { + "branch_icon": "\ue725 ", + "cherry_pick_icon": "\ue29b ", + "commit_icon": "\uf417 ", + "fetch_status": false, + "fetch_upstream_icon": false, + "merge_icon": "\ue727 ", + "no_commits_icon": "\uf0c3 ", + "rebase_icon": "\ue728 ", + "revert_icon": "\uf0e2 ", + "tag_icon": "\uf412 " + }, + "template": "{{ .HEAD }} ", + "style": "plain", + "type": "git" + }, + { + "style": "plain", + "foreground": "p:closer", + "template": "\uf105", + "type": "text" + } + ], + "type": "prompt" + } + ], + "final_space": true, + "version": 3 +} diff --git a/hmModules/shell/default.nix b/hmModules/shell/default.nix index c654977..6c7e5c1 100644 --- a/hmModules/shell/default.nix +++ b/hmModules/shell/default.nix @@ -84,7 +84,12 @@ programs.thefuck.enable = true; programs.oh-my-posh = { enable = true; - useTheme = "catppuccin_mocha"; + # same as "captuccin_mocha" but without the OS logo + settings = lib.mkForce ( + builtins.fromJSON ( + builtins.unsafeDiscardStringContext (builtins.readFile ./catppuccin_mocha.omp.json) + ) + ); }; programs.zellij.enableBashIntegration = false; From cdfa60ad5e4a93e4e61dd1d8e8df6dfc515744b6 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:05:12 +0200 Subject: [PATCH 09/15] Add `arbi` NixOS module --- modules/arbi/default.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 modules/arbi/default.nix diff --git a/modules/arbi/default.nix b/modules/arbi/default.nix new file mode 100644 index 0000000..02ab9e5 --- /dev/null +++ b/modules/arbi/default.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: +let + rev = "d531730d9640160f0519ef4b3640f8da49dd96f8"; + arbi-flake = builtins.getFlake "git+ssh://git@github.com/aciceri/arbi.git?rev=${rev}"; +in +{ + imports = [ arbi-flake.nixosModules.arbi ]; + + services.arbi = { + enable = true; + log_level = "debug"; + configFile = pkgs.writeText "arbi-config.kdl" '' + endpoint "wss://eth-mainnet.g.alchemy.com/v2/" + pairs_file "pairs.json" + concurrency 4 + ''; + }; + + environment.persistence."/persist".directories = [ + config.services.arbi.dataDir + ]; +} From a7c19c03dfd8bef0f7d4f39c29b63f78d077ea3f Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:05:49 +0200 Subject: [PATCH 10/15] `haskell-language-server-wrapper` -> `haskell-language-server` --- hmModules/emacs/init.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index b142b0f..92eff50 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -566,7 +566,7 @@ :mode "\\.hs\\'" :config (add-to-list 'eglot-server-programs - '(haskell-ts-mode . ("haskell-language-server-wrapper" "--lsp")))) + '(haskell-ts-mode . ("haskell-language-server" "--lsp")))) (use-package purescript-mode :custom ((project-vc-extra-root-markers '("spago.dhall"))) From f55a6b64239d6219326ac94ff94be637c8abba2c Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:06:20 +0200 Subject: [PATCH 11/15] Play with `tidal` (tidal cycles) --- hmModules/emacs/init.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index 92eff50..b772192 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -568,6 +568,8 @@ (add-to-list 'eglot-server-programs '(haskell-ts-mode . ("haskell-language-server" "--lsp")))) +(use-package tidal + :custom ((tidal-interpreter "tidal"))) (use-package purescript-mode :custom ((project-vc-extra-root-markers '("spago.dhall"))) :hook ((purescript-mode . eglot-ensure) From 1ed4ed0da514970ca62568ec3f620ea3f992c6fa Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:07:12 +0200 Subject: [PATCH 12/15] Indentation --- hmModules/emacs/init.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index b772192..a176986 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -573,8 +573,8 @@ (use-package purescript-mode :custom ((project-vc-extra-root-markers '("spago.dhall"))) :hook ((purescript-mode . eglot-ensure) - (purescript-mode . turn-on-purescript-indentation) - (purescript-mode . (lambda () (setq project-vc-extra-root-markers '("spago.dhall")))))) + (purescript-mode . turn-on-purescript-indentation) + (purescript-mode . (lambda () (setq project-vc-extra-root-markers '("spago.dhall")))))) (use-package terraform-mode :after eglot From fffef9090515b77c3d0dfae54423773d72904720 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:07:27 +0200 Subject: [PATCH 13/15] Enable `typst-ts-mode` --- hmModules/emacs/init.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index a176986..ff50b5d 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -598,6 +598,15 @@ (use-package gptscript-mode :mode "\\.gpt\\'") +(use-package gptscript-mode + :mode "\\.gpt\\'") + +(use-package typst-ts-mode + :config + (add-to-list 'eglot-server-programs + '(typst-ts-mode . ("tinymist" "lsp"))) + :mode "\\.typ\\'") + ;; FIXME ;; (use-package mmm-mode ;; :config @@ -615,7 +624,7 @@ (use-package paredit :delight :hook ((lisp-mode . enable-paredit-mode) - (emacs-lisp-mode . enable-paredit-mode))) + (emacs-lisp-mode . enable-paredit-mode))) (use-package aggressive-indent :hook ((lisp-mode . aggressive-indent-mode) From 36ad3ced81978a1b655701818a2bcfc93aecb073 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:07:48 +0200 Subject: [PATCH 14/15] Indentation --- hmModules/emacs/init.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index ff50b5d..79a198e 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -1030,12 +1030,12 @@ This is meant to be an helper to be called from the window manager." :custom (gptel-model 'google/gemini-2.5-flash-preview) (gptel-backend (gptel-make-openai "OpenRouter" - :host "openrouter.ai" - :endpoint "/api/v1/chat/completions" - :key (lambda () (require 'f) (f-read-text (getenv "OPENAI_API_KEY_PATH"))) - :stream t - :models '(google/gemini-2.5-flash-preview)) - ) + :host "openrouter.ai" + :endpoint "/api/v1/chat/completions" + :key (lambda () (require 'f) (f-read-text (getenv "OPENAI_API_KEY_PATH"))) + :stream t + :models '(google/gemini-2.5-flash-preview)) + ) (gptel-default-mode 'org-mode) (gptel-org-branching-context nil) ;; this is cool but I don't feel comfortable with it (gptel-use-tools nil) From 79c98d1e5da10da32bf5119d78d4abcd64b509ca Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Fri, 16 May 2025 16:08:15 +0200 Subject: [PATCH 15/15] Add many gptel tools --- hmModules/emacs/init.el | 222 +++++++++++++++++++++++++++------------- 1 file changed, 153 insertions(+), 69 deletions(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index 79a198e..7959261 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -570,6 +570,7 @@ (use-package tidal :custom ((tidal-interpreter "tidal"))) + (use-package purescript-mode :custom ((project-vc-extra-root-markers '("spago.dhall"))) :hook ((purescript-mode . eglot-ensure) @@ -1038,7 +1039,7 @@ This is meant to be an helper to be called from the window manager." ) (gptel-default-mode 'org-mode) (gptel-org-branching-context nil) ;; this is cool but I don't feel comfortable with it - (gptel-use-tools nil) + (gptel-use-tools 't) :bind ("C-c a a" . gptel-add) @@ -1053,80 +1054,163 @@ This is meant to be an helper to be called from the window manager." ;; (add-hook 'gptel-post-response-functions 'gptel-end-of-response) ;; (add-hook 'gptel-post-stream-hook 'gptel-auto-scroll) - (setq gptel-tools (mapcar (lambda (tool) (apply #'gptel-make-tool tool)) - '(( - :name "create_file" - :function (lambda (path filename content) - (let ((full-path (expand-file-name filename path))) - (with-temp-buffer - (insert content) - (write-file full-path)) - (format-read "Created file %s in %s" filename path))) - :description "Create a new file with the specified content" - :args (list '(:name "path" - :type string - :description "The directory where to create the file") - '(:name "filename" - :type string - :description "The name of the file to create") - '(:name "content" - :type string - :description "The content to write to the file")) - :category "filesystem" - ) - ;; ( - ;; :name "run_command" - ;; :confirm 't - ;; :function (lambda (command) - ;; (shell-command-to-string command)) - ;; :description "Run arbitrary commands" - ;; :args (list '(:name "command" - ;; :type string - ;; :description "The content to run e.g. 'ls *' or 'fd '")) - ;; ) - ( - :name "get_weather" - :function (lambda (location) - (url-retrieve-synchronously "api.weather.com/..." - location unit)) - :description "Get the current weather in a given location" - :args (list '(:name "location" - :type string - :description "The city and state, e.g. San Francisco, CA") - '(:name "unit" - :type string - :enum ["celsius" "farenheit"] - :description - "The unit of temperature, either 'celsius' or 'fahrenheit" - :optional t - )) - ) - )) - ) + (defun ccr/edit-buffer (buffer-name old-string new-string) + "In BUFFER-NAME, replace OLD-STRING with NEW-STRING." + (with-current-buffer buffer-name + (let ((case-fold-search nil)) ;; Case-sensitive search + (save-excursion + (goto-char (point-min)) + (let ((count 0)) + (while (search-forward old-string nil t) + (setq count (1+ count))) + (if (= count 0) + (format "Error: Could not find text to replace in buffer %s" buffer-name) + (if (> count 1) + (format "Error: Found %d matches for the text to replace in buffer %s" count buffer-name) + (goto-char (point-min)) + (search-forward old-string) + (replace-match new-string t t) + (format "Successfully edited buffer %s" buffer-name)))))))) + + (defun ccr/replace-buffer (buffer-name content) + "Completely replace contents of BUFFER-NAME with CONTENT." + (with-current-buffer buffer-name + (erase-buffer) + (insert content) + (format "Buffer replaced: %s" buffer-name))) + + (setq gptel-tools `( + ,(gptel-make-tool + :function (lambda (url) + (with-current-buffer (url-retrieve-synchronously url) + (goto-char (point-min)) + (forward-paragraph) + (let ((dom (libxml-parse-html-region (point) (point-max)))) + (run-at-time 0 nil #'kill-buffer (current-buffer)) + (with-temp-buffer + (shr-insert-document dom) + (buffer-substring-no-properties (point-min) (point-max)))))) + :name "read_url" + :description "Fetch and read the contents of a URL" + :args (list '(:name "url" + :type string + :description "The URL to read")) + :category "web") + ,(gptel-make-tool + :function (lambda (filepath) + (with-temp-buffer + (insert-file-contents (expand-file-name filepath)) + (buffer-string))) + :name "read_file" + :description "Read and display the contents of a file" + :args (list '(:name "filepath" + :type string + :description "Path to the file to read. Supports relative paths and ~.")) + :category "filesystem") + ,(gptel-make-tool + :function (lambda (directory) + (mapconcat #'identity + (directory-files directory) + "\n")) + :name "list_directory" + :description "List the contents of a given directory" + :args (list '(:name "directory" + :type string + :description "The path to the directory to list")) + :category "filesystem") + ,(gptel-make-tool + :function (lambda () (mapcar 'buffer-name (buffer-list))) + :name "list_buffers" + :description "Return a list containing all the Emacs buffers" + :category "emacs") + ,(gptel-make-tool + :function (lambda (buffer) + (unless (buffer-live-p (get-buffer buffer)) + (error "Error: buffer %s is not live." buffer)) + (with-current-buffer buffer + (buffer-substring-no-properties (point-min) (point-max)))) + :name "read_buffer" + :description "Return the contents of an Emacs buffer" + :args (list '(:name "buffer" + :type string + :description "The name of the buffer whose contents are to be retrieved")) + :category "emacs") + ,(gptel-make-tool + :function (lambda (buffer text) + (with-current-buffer (get-buffer-create buffer) + (save-excursion + (goto-char (point-max)) + (insert text))) + (format "Appended text to buffer %s" buffer)) + :name "append_to_buffer" + :description "Append text to an Emacs buffer. If the buffer does not exist, it will be created." + :confirm t + :args (list '(:name "buffer" + :type string + :description "The name of the buffer to append text to.") + '(:name "text" + :type string + :description "The text to append to the buffer.")) + :category "emacs") + ,(gptel-make-tool + :name "EditBuffer" + :function #'ccr/edit-buffer + :description "Edits Emacs buffers" + :confirm t + :args '((:name "buffer_name" + :type string + :description "Name of the buffer to modify" + :required t) + (:name "old_string" + :type string + :description "Text to replace (must match exactly)" + :required t) + (:name "new_string" + :type string + :description "Text to replace old_string with" + :required t)) + :category "edit") + , + (gptel-make-tool + :name "ReplaceBuffer" + :function #'ccr/replace-buffer + :description "Completely overwrites buffer contents" + :confirm t + :args '((:name "buffer_name" + :type string + :description "Name of the buffer to overwrite" + :required t) + (:name "content" + :type string + :description "Content to write to the buffer" + :required t)) + :category "edit") + )) + (defun ccr/suggest-eshell-command () (interactive) (save-excursion (eshell-bol) (let ((start-pos (point)) - (end-pos (line-end-position))) - (gptel-request - (buffer-substring-no-properties start-pos end-pos) ;the prompt - :system "You are proficient with emacs shell (eshell), translate the following to something I could directly prompt to the shell. Your responses should only be code, without explanation or formatting or quoting." - :buffer (current-buffer) - :context (cons (set-marker (make-marker) start-pos) - (set-marker (make-marker) end-pos)) - :callback - (lambda (response info) - (if (not response) - (message "ChatGPT response failed with: %s" (plist-get info :status)) - (kill-region start-pos end-pos) - (insert response))))))) + (end-pos (line-end-position))) + (gptel-request + (buffer-substring-no-properties start-pos end-pos) ;the prompt + :system "You are proficient with emacs shell (eshell), translate the following to something I could directly prompt to the shell. Your responses should only be code, without explanation or formatting or quoting." + :buffer (current-buffer) + :context (cons (set-marker (make-marker) start-pos) + (set-marker (make-marker) end-pos)) + :callback + (lambda (response info) + (if (not response) + (message "ChatGPT response failed with: %s" (plist-get info :status)) + (kill-region start-pos end-pos) + (insert response))))))) (add-to-list 'display-buffer-alist '("^\\*ChatGPT\\*" - (display-buffer-full-frame) - (name . "floating"))) + (display-buffer-full-frame) + (name . "floating"))) (defun ccr/start-chatgpt () ;; Used from outside Emacs by emacsclient --eval (display-buffer (gptel "*ChatGPT*")) @@ -1142,9 +1226,9 @@ This is meant to be an helper to be called from the window manager." (require 'password-store-otp) ;; FIXME use `use-pacakge' idiomatic way :bind (("C-c p p" . password-store-copy) - ("C-c p o" . password-store-otp-token-copy) - ("C-c p e" . password-store-edit) - ("C-c p i" . password-store-insert))) + ("C-c p o" . password-store-otp-token-copy) + ("C-c p e" . password-store-edit) + ("C-c p i" . password-store-insert))) (use-package with-editor :init (shell-command-with-editor-mode +1))