Skip to content

Fix: omarchy plugin clone can generate a colliding plugin id - #13498

Closed
baron-hines wants to merge 1 commit into
omacom:quattrofrom
baron-hines:03-plugin-clone-id-collision
Closed

baron-hines wants to merge 1 commit into
omacom:quattrofrom
baron-hines:03-plugin-clone-id-collision

Conversation

@baron-hines

Copy link
Copy Markdown

Problem

omarchy plugin clone <builtin> derives the new clone's id from $USER as roughly <username>.<plugin>. When the username matches the namespace of a built-in plugin, the generated id collides with the built-in itself.

Concrete case — the stock Omarchy VM's default username is literally omarchy, so:

omarchy plugin clone omarchy.weather

generates the clone id omarchy.weather — the same id as the built-in weather plugin. The clone can't be distinguished from what it was cloned from. This is not hypothetical: any user cloning an omarchy.* built-in on a stock install hits it.

Fix

After computing the candidate id, check it against every id in omarchy-plugin-catalog (built-in or already-cloned) and against any existing plugin directory, and suffix a counter until the id is free. The directory-existence guard is folded into the same check so a clone never clobbers an existing one.

  • Normal usernames are unaffected (baron.weather, etc.).
  • The collision case now yields omarchy.weather2 instead of shadowing the built-in.

Testing

# as user "omarchy":
omarchy plugin clone omarchy.weather   # -> clone id omarchy.weather2 (was: omarchy.weather)
# as any other user:
omarchy plugin clone omarchy.weather   # -> <user>.weather, unchanged

🤖 Generated with Claude Code

`omarchy plugin clone <builtin>` derives the clone id from the username as
`<user>.<plugin>`. 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 <noreply@anthropic.com>
@llstrk

llstrk commented Sep 29, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: For a user named omarchy, the suffixed id omarchy.weather2 is still in the reserved omarchy.* namespace, so cloning fails.

Suffixed id is still reserved

PluginRegistry.qml rejects every non-built-in id starting with omarchy., not only duplicates. Impact: the clone exits 1 (cloned plugin 'omarchy.weather2' was not discovered) and deletes the copy.

Suggested change: move the id out of omarchy.* before the collision check, e.g. #7366's user. prefix (it merges cleanly).

Reproducer (fails at 4f91d36)

Drop this into test/shell.d/plugin-clone-reserved-user-test.sh and run bash test/shell.d/plugin-clone-reserved-user-test.sh. Its fake omarchy-shell has the same shape as the one in plugin-clone-test.sh, but listPlugins applies the rule from shell/services/PluginRegistry.qml parseScanOutput(): a user plugin whose id is a built-in id or starts with omarchy. is rejected.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
mkdir -p "$TMPDIR/bin"

# Same shape as the fake in plugin-clone-test.sh, except listPlugins applies
# the rule in shell/services/PluginRegistry.qml parseScanOutput(): a user
# plugin whose id is a built-in id or starts with "omarchy." is rejected.
cat >"$TMPDIR/bin/omarchy-shell" <<'SH'
#!/bin/bash
if [[ $* == *"listPlugins"* ]]; then
  {
    find "$OMARCHY_PATH/shell/plugins" -mindepth 2 -maxdepth 3 -type f \
      \( -name manifest.json -o -name '*.manifest.json' \) -print0 |
      xargs -0 jq -c '{id: .id, firstParty: true, enabled: true}'
    find "$HOME/.config/omarchy/plugins" -mindepth 2 -maxdepth 2 -name manifest.json -print0 |
      xargs -0 -r jq -c '{id: .id, firstParty: false, enabled: true}'
  } | jq -s '
    (map(select(.firstParty) | .id)) as $builtin
    | map(. as $p | select($p.firstParty
        or (($p.id | startswith("omarchy.") | not) and ($builtin | index($p.id)) == null)))'
fi
exit 0
SH
for command in omarchy-plugin-enable omarchy-notification-send; do
  cat >"$TMPDIR/bin/$command" <<'SH'
#!/bin/bash
printf '%s %s\n' "${0##*/}" "$*" >>"$FAKE_CALLS"
SH
done
chmod +x "$TMPDIR/bin/"*

clone_as() {
  local user="$1"
  shift
  HOME="$TMPDIR/home-$user" USER="$user" OMARCHY_PATH="$ROOT" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
    FAKE_CALLS="$TMPDIR/calls-$user" omarchy-plugin-clone "$@"
}

loaded_as_user_plugin() {
  local user="$1" id="$2"
  HOME="$TMPDIR/home-$user" OMARCHY_PATH="$ROOT" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
    omarchy-shell shell listPlugins | jq -e --arg id "$id" 'any(.[]; .id == $id and (.firstParty | not))' >/dev/null
}

# Control: an ordinary username clones into a loadable id.
clone_as tester omarchy.weather >"$TMPDIR/out-tester"
loaded_as_user_plugin tester tester.weather ||
  fail "control: tester.weather is loaded as a user plugin"
pass "control: an ordinary user's clone is loaded"

# A user named omarchy: the clone must land outside the reserved namespace,
# otherwise the registry drops it.
status=0
clone_as omarchy omarchy.weather >"$TMPDIR/out-omarchy" 2>"$TMPDIR/err-omarchy" || status=$?
[[ $status == 0 ]] ||
  fail "clone as user omarchy succeeds" "exit $status: $(cat "$TMPDIR/err-omarchy")"
clone_id=$(sed -n 's/^Cloned .* and switched to //p' "$TMPDIR/out-omarchy")
[[ $clone_id != omarchy.* ]] ||
  fail "clone as user omarchy avoids the reserved omarchy.* namespace" "clone id: $clone_id"
loaded_as_user_plugin omarchy "$clone_id" ||
  fail "clone as user omarchy is loaded as a user plugin" "clone id: $clone_id"
pass "clone as user omarchy is loaded as a user plugin"

Actual output at 4f91d36 (exit 1):

ok - control: an ordinary user's clone is loaded
exit 1: omarchy-plugin-clone: cloned plugin 'omarchy.weather2' was not discovered
not ok - clone as user omarchy succeeds

For comparison, the same test at the merge-base 3faafba (exit 1):

ok - control: an ordinary user's clone is loaded
clone id: omarchy.weather
not ok - clone as user omarchy avoids the reserved omarchy.* namespace

And on a local merge of this head with #7366 (exit 0):

ok - control: an ordinary user's clone is loaded
ok - clone as user omarchy is loaded as a user plugin

The repository's validator rejects the generated id as well. With the unmodified fake from plugin-clone-test.sh (which reports every user manifest as discovered), USER=omarchy omarchy-plugin-clone omarchy.weather exits 0 at 4f91d36 and creates plugins/omarchy.weather2; omarchy-plugin-validate on that folder then prints the following and exits 1:

omarchy-plugin-validate: plugin id 'omarchy.weather2' uses the reserved omarchy.* namespace

A repeat clone now adds a second copy

Cloning an already-cloned built-in used to fail with already exists; now it also enables <user>.<id>2. Impact: while the first clone is enabled, the registry code puts a bar widget in twice and still routes built-in-id calls to it.

Suggested change: refuse when a clone of the source (same omarchy.clonedFrom) exists, as the menu does.

Reproducer (fails at 4f91d36)

Drop this into test/shell.d/plugin-clone-repeat-test.sh and run bash test/shell.d/plugin-clone-repeat-test.sh. It uses the fake omarchy-shell from plugin-clone-test.sh and asserts the pre-PR behaviour (a second clone of the same built-in is refused).

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
mkdir -p "$TMPDIR/home/.config/omarchy" "$TMPDIR/bin"
CALLS="$TMPDIR/calls"

# The fake from plugin-clone-test.sh: every user manifest is discovered.
cat >"$TMPDIR/bin/omarchy-shell" <<'SH'
#!/bin/bash
if [[ $* == *"listPlugins"* ]]; then
  find "$HOME/.config/omarchy/plugins" -mindepth 2 -maxdepth 2 -name manifest.json -print0 |
    xargs -0 -r jq -s 'map({id: .id, enabled: true})'
fi
exit 0
SH
for command in omarchy-plugin-enable omarchy-notification-send; do
  cat >"$TMPDIR/bin/$command" <<'SH'
#!/bin/bash
printf '%s %s\n' "${0##*/}" "$*" >>"$FAKE_CALLS"
SH
done
chmod +x "$TMPDIR/bin/"*

clone_plugin() {
  HOME="$TMPDIR/home" USER=tester OMARCHY_PATH="$ROOT" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
    FAKE_CALLS="$CALLS" omarchy-plugin-clone "$@"
}

clone_plugin omarchy.weather >/dev/null
[[ -d $TMPDIR/home/.config/omarchy/plugins/tester.weather ]] || fail "first clone creates tester.weather"
pass "first clone creates tester.weather"

status=0
clone_plugin omarchy.weather >"$TMPDIR/out" 2>"$TMPDIR/err" || status=$?
printf '# second clone: exit %s\n' "$status"
sed 's/^/# stdout: /' "$TMPDIR/out"
sed 's/^/# stderr: /' "$TMPDIR/err"
printf '# plugin dirs: %s\n' "$(ls -1 "$TMPDIR/home/.config/omarchy/plugins" | tr '\n' ' ')"
printf '# enable calls: %s\n' "$(grep '^omarchy-plugin-enable' "$CALLS" | tr '\n' ';')"

(( status != 0 )) && [[ ! -e $TMPDIR/home/.config/omarchy/plugins/tester.weather2 ]] ||
  fail "cloning an already-cloned built-in again is refused instead of adding a second clone"
pass "cloning an already-cloned built-in again is refused"

Actual output at 4f91d36 (exit 1; the test's mktemp directory is shown as $TMPDIR):

ok - first clone creates tester.weather
# second clone: exit 0
# stdout: Cloned omarchy.weather to $TMPDIR/home/.config/omarchy/plugins/tester.weather2 and switched to tester.weather2
# plugin dirs: tester.weather tester.weather2 
# enable calls: omarchy-plugin-enable tester.weather;omarchy-plugin-enable tester.weather2;
not ok - cloning an already-cloned built-in again is refused instead of adding a second clone

Same test at the merge-base 3faafba (exit 0):

ok - first clone creates tester.weather
# second clone: exit 1
# stderr: omarchy-plugin-clone: $TMPDIR/home/.config/omarchy/plugins/tester.weather already exists
# plugin dirs: tester.weather 
# enable calls: omarchy-plugin-enable tester.weather;
ok - cloning an already-cloned built-in again is refused
Details

Verified:

Duplicate-clone effects: the bar and routing outcomes above come from running PluginRegistry.qml's own scan and enable functions under Node, not from a live shell. For a bar widget, setEnabled no longer finds the built-in in the bar and inserts the second clone beside the first. For a panel such as omarchy.osd, both clones are enabled and resolveEnabledId("omarchy.osd") returns the first.

Optional test improvement: the existing test's fake listPlugins reports every user manifest as loaded, so it cannot catch the namespace problem (the same 20 tests pass at the merge-base). A fake that applies the registry's rule, as in the first reproducer, fails at this head.

Optional note: the usage text, manual/32-shell-plugins.md, docs/omarchy-shell.md and default/agents/skills/omarchy/plugins.md still give the clone path as <username>.<id>; with suffixing it can end in 2 or higher, so these would point users at the wrong folder.


Review information

Test scope: Source review and sandboxed runs at 4f91d36f against a fake shell; no live omarchy-shell.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 4f91d36f by reading the source; nothing was run on a worker, because another open pull request already fixes this bug and has been verified.

This does not fix the bug for a user named omarchy. The suffix moves the id from omarchy.weather to omarchy.weather2, and that is still in the reserved namespace: shell/services/PluginRegistry.qml:630 rejects every user plugin id starting with omarchy., not only exact matches with a built-in, and bin/omarchy-plugin-validate:53 does the same. The clone is never discovered, so the command fails with cloned plugin 'omarchy.weather2' was not discovered and removes the copy. That confirms the first finding in the community review above.

It also changes a second clone of the same built-in. On quattro that clone is refused with already exists. With this change it becomes <user>.weather2 and gets enabled next to the first clone, and because the first clone has already taken the built-in's place in the bar, the second widget is inserted alongside it (PluginRegistry.qml:527-538).

#7366 fixes the same issue (#7118) at the cause: an id that would start with omarchy. becomes user.omarchy.<id>, which the registry and the validator both accept, and it keeps the existing already exists guard. It is older, has a regression test, has been verified, and is waiting on the maintainer. I'm leaving this one open for the maintainer to decide on, and I'd suggest closing it in favour of #7366.

Checked by Claude Opus 5.5 and Codex Medium. Codex was asked which of the two fixes was better, without being told my conclusion. It reached the same result and cited the same lines. It could read the review already posted here, so its agreement is not guaranteed to be independent.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @baron-hines. #7366 got there first with a fix for the same problem, so this is closed in favour of it, and the credit stays with the first fix. If it does not cover your case, please say so there.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

@omarchybot omarchybot closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants