From 4f91d36fe5a4a865cdbe3e72ae8f109a72240316 Mon Sep 17 00:00:00 2001 From: Baron Hines Date: Sun, 27 Sep 2026 21:25:14 -0500 Subject: [PATCH] Fix: prevent omarchy-plugin-clone from generating a colliding plugin id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `omarchy plugin clone ` derives the clone id from the username as `.`. When the username matches a built-in namespace this can equal a built-in's own id. The stock Omarchy VM user is literally `omarchy`, so `omarchy plugin clone omarchy.weather` generated the id `omarchy.weather` — identical to the built-in weather plugin — leaving the clone indistinguishable from what it was cloned from. Check the candidate id against every catalog id (built-in or already-cloned) and against any existing plugin directory, and suffix a counter until the id is unique. Normal usernames are unaffected; the collision case now yields `omarchy.weather2` instead of shadowing the built-in. Co-Authored-By: Claude Opus 4.8 --- bin/omarchy-plugin-clone | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bin/omarchy-plugin-clone b/bin/omarchy-plugin-clone index 59ca16172ed4..aae8250d4b22 100755 --- a/bin/omarchy-plugin-clone +++ b/bin/omarchy-plugin-clone @@ -130,6 +130,32 @@ IFS=$'\t' read -r source_dir source_manifest source_name <<<"$source_info" new_id="${USER:-$(id -un)}.${source_id#omarchy.}" display_name="My $source_name" + +# Guarantee the clone id can't shadow an existing plugin. The naive +# "." id collides with a built-in when the username matches a +# built-in namespace: the stock Omarchy VM user is literally "omarchy", so +# `omarchy plugin clone omarchy.weather` would otherwise generate the id +# "omarchy.weather" -- the same id as the built-in it was cloned from, leaving +# the two indistinguishable. Suffix a counter until the id collides with no +# catalog id (built-in or already-cloned) and no directory is in the way. +existing_ids=$(omarchy-plugin-catalog | jq -r '.[].id') +id_is_taken() { + local candidate="$1" id + [[ -e $PLUGINS_DIR/$candidate || -L $PLUGINS_DIR/$candidate ]] && return 0 + while IFS= read -r id; do + [[ -n $id && $id == "$candidate" ]] && return 0 + done <<<"$existing_ids" + return 1 +} + +if id_is_taken "$new_id"; then + suffix=2 + while id_is_taken "${new_id}${suffix}"; do + ((suffix++)) + done + new_id="${new_id}${suffix}" +fi + target_dir="$PLUGINS_DIR/$new_id" [[ ! -e $target_dir && ! -L $target_dir ]] || fail "$target_dir already exists"