diff --git a/CLAUDE.md b/CLAUDE.md index 90efc6e..ccc2d1d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -29,10 +29,13 @@ The entire implementation is a single Babashka script (`iamwaiting`) with these Configuration is stored in `~/.iamwaiting/config.edn` with the following structure: ```clojure -{:webhook-url "https://discord.com/api/webhooks/..."} +{:webhook-url "https://discord.com/api/webhooks/..." + :user-id "123456789012345678"} ; Optional: Discord user ID for @mentions ``` -Alternatively, the webhook URL can be set via the `IAMWAITING_WEBHOOK_URL` environment variable. +Alternatively, configuration can be set via environment variables: +- `IAMWAITING_WEBHOOK_URL` - Discord webhook URL (required) +- `IAMWAITING_USER_ID` - Discord user ID for @mentions (optional) ## Installation @@ -114,14 +117,23 @@ Notifications include: - ā³ Waiting indicator - šŸ“ Current working directory / project name - šŸ• Timestamp (HH:mm:ss format) +- @mention (if user ID is configured and it's a permission prompt) -Example message: +Example message (normal prompt): ``` ā³ **Claude is waiting** in `ajet-industries` šŸ“ Path: `/home/user/repos/ajet-industries` šŸ• Time: 14:23:45 ``` +Example message (permission prompt with user ID configured): +``` +<@123456789012345678> ā³ **Claude is waiting** in `ajet-industries` +šŸ“ Path: `/home/user/repos/ajet-industries` +šŸ• Time: 14:23:45 +šŸ“¢ Type: `permission_prompt` +``` + ### Error Handling - Missing configuration prompts user to run `./iamwaiting setup` diff --git a/iamwaiting b/iamwaiting index 659bdae..e29c2b6 100755 --- a/iamwaiting +++ b/iamwaiting @@ -13,8 +13,11 @@ (let [config (when (fs/exists? config-file) (read-string (slurp config-file))) webhook-url (or (:webhook-url config) - (System/getenv "IAMWAITING_WEBHOOK_URL"))] - {:webhook-url webhook-url})) + (System/getenv "IAMWAITING_WEBHOOK_URL")) + user-id (or (:user-id config) + (System/getenv "IAMWAITING_USER_ID"))] + {:webhook-url webhook-url + :user-id user-id})) (defn send-discord-webhook [webhook-url message] "Send a message to Discord via webhook" @@ -31,7 +34,7 @@ (catch Exception e {:success false :error (.getMessage e)}))) -(defn format-waiting-message [event-data] +(defn format-waiting-message [event-data user-id] "Format a message for Claude waiting event" (let [cwd (or (:cwd event-data) (System/getProperty "user.dir")) project-name (fs/file-name cwd) @@ -43,8 +46,15 @@ permission-mode (:permission_mode event-data) hook-message (:message event-data) transcript-path (:transcript_path event-data) - transcript-file (when transcript-path (fs/file-name transcript-path))] - (str "ā³ **Claude is waiting** in `" project-name "`\n" + transcript-file (when transcript-path (fs/file-name transcript-path)) + ;; Check if this is a permission prompt + is-permission-prompt? (or (= notification-type "permission_prompt") + (some? permission-mode)) + ;; Ping user if configured and it's a permission prompt + user-ping (when (and user-id is-permission-prompt?) + (str "<@" user-id "> "))] + (str user-ping + "ā³ **Claude is waiting** in `" project-name "`\n" "šŸ“ Path: `" cwd "`\n" "šŸ• Time: " formatted-time "\n" (when session-id (str "šŸ”‘ Session: `" session-id "`\n")) @@ -66,13 +76,25 @@ (println "Error: webhook URL cannot be empty") (System/exit 1)) - ;; Create config directory - (fs/create-dirs (fs/parent config-file)) + (println "\nEnter your Discord user ID (optional, for @mentions on permission prompts):") + (println "(Get this from Discord: User Settings > Advanced > Developer Mode, then right-click your name)\n") + (print "> ") + (flush) + (let [user-id-input (str/trim (read-line)) + user-id (when-not (str/blank? user-id-input) user-id-input) + config (if user-id + {:webhook-url webhook-url :user-id user-id} + {:webhook-url webhook-url})] - ;; Write config - (spit config-file (pr-str {:webhook-url webhook-url})) - (println "\nāœ“ Configuration saved to" config-file) - (println "\nTest the webhook with: ./iamwaiting test"))) + ;; Create config directory + (fs/create-dirs (fs/parent config-file)) + + ;; Write config + (spit config-file (pr-str config)) + (println "\nāœ“ Configuration saved to" config-file) + (when user-id + (println "āœ“ User ID configured - you will be @mentioned on permission prompts")) + (println "\nTest the webhook with: ./iamwaiting test")))) (defn test-webhook [] "Test the webhook configuration" @@ -119,7 +141,7 @@ (json/parse-string (first event-data-args) true) (catch Exception _ {}))) {}) - message (format-waiting-message event-data) + message (format-waiting-message event-data (:user-id config)) result (send-discord-webhook (:webhook-url config) message)] (if (:success result) (println "āœ“ Notification sent")