Skip to content

Commit d2ecf65

Browse files
mbachorikiamaeroplaneclaude
authored
feat(extensions,presets): add priority-based resolution ordering (#1855)
* feat(extensions,presets): add priority-based resolution ordering Add priority field to extension and preset registries for deterministic template resolution when multiple sources provide the same template. Extensions: - Add `list_by_priority()` method to ExtensionRegistry - Add `--priority` option to `extension add` command - Add `extension set-priority` command - Show priority in `extension list` and `extension info` - Preserve priority during `extension update` - Update RFC documentation Presets: - Add `preset set-priority` command - Show priority in `preset info` output - Use priority ordering in PresetResolver for extensions Both systems: - Lower priority number = higher precedence (default: 10) - Backwards compatible with legacy entries (missing priority defaults to 10) - Comprehensive test coverage including backwards compatibility Closes #1845 Closes #1854 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address code review feedback - list_by_priority(): add secondary sort by ID for deterministic ordering, return deep copies to prevent mutation - install_from_directory/zip: validate priority >= 1 early - extension add CLI: validate --priority >= 1 before install - PresetRegistry.update(): preserve installed_at timestamp - Test assertions: use exact source string instead of substring match Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address additional review feedback - PresetResolver: add fallback to directory scanning when registry is empty/corrupted for robustness and backwards compatibility - PresetRegistry.update(): add guard to prevent injecting installed_at when absent in existing entry (mirrors ExtensionRegistry behavior) - RFC: update extension list example to match actual CLI output format Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: restore defensive code and RFC descriptions lost in rebase - Restore defensive code in list_by_priority() with .get() and isinstance check - Restore detailed --from URL and --dev option descriptions in RFC Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: add defensive code to presets list_by_priority() - Add .get() and isinstance check for corrupted/empty registry - Move copy import to module level (remove local import) - Matches defensive pattern used in extensions.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address reviewer feedback on priority resolution - Rename _normalize_priority to normalize_priority (public API) - Add comprehensive tests for normalize_priority function (9 tests) - Filter non-dict metadata entries in list_by_priority() methods - Fix extension priority resolution to merge registered and unregistered extensions into unified sorted list (unregistered get implicit priority 10) - Add tests for extension priority resolution ordering (4 tests) The key fix ensures unregistered extensions with implicit priority 10 correctly beat registered extensions with priority > 10, and vice versa. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: DRY refactor and strengthen test assertions - Extract _get_all_extensions_by_priority() helper in PresetResolver to eliminate duplicated extension list construction - Add priority=10 assertion to test_legacy_extension_without_priority_field - Add priority=10 assertion to test_legacy_preset_without_priority_field Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: add isinstance(dict) checks for corrupted registry entries Add defensive checks throughout CLI commands and manager methods to handle cases where registry entries may be corrupted (non-dict values). This prevents AttributeError when calling .get() on non-dict metadata. Locations fixed: - __init__.py: preset/extension info, set-priority, enable/disable, upgrade commands - extensions.py: list_installed() - presets.py: list_installed() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: normalize priority display to match resolution behavior Use normalize_priority() for all priority display in CLI commands to ensure displayed values match actual resolution behavior when registry data is corrupted/hand-edited. Locations fixed: - extensions.py: list_installed() - presets.py: list_installed(), PresetResolver - __init__.py: preset info, extension info, set-priority commands Also added GraphQL query for unresolved PR comments to CLAUDE.md. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: repair corrupted priority values in set-priority commands Changed set-priority commands to check if the raw stored value is already a valid int equal to the requested priority before skipping. This ensures corrupted values (e.g., "high") get repaired even when setting to the default priority (10). Also removed CLAUDE.md that was accidentally added to the repo. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: harden registry update methods against corrupted entries - Normalize priority when restoring during extension update to prevent propagating corrupted values (e.g., "high", 0, negative) - Add isinstance(dict) checks in ExtensionRegistry.update() and PresetRegistry.update() to handle corrupted entries (string/list) that would cause TypeError on merge Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: use safe fallback for version in list_installed() When registry entry is corrupted (non-dict), metadata becomes {} after the isinstance check. Use metadata.get("version", manifest.version) instead of metadata["version"] to avoid KeyError. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: iamaeroplane <michal.bachorik@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7a5762f commit d2ecf65

File tree

6 files changed

+1114
-62
lines changed

6 files changed

+1114
-62
lines changed

extensions/RFC-EXTENSION-SYSTEM.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,15 @@ specify extension add jira
359359
"installed_at": "2026-01-28T14:30:00Z",
360360
"source": "catalog",
361361
"manifest_hash": "sha256:abc123...",
362-
"enabled": true
362+
"enabled": true,
363+
"priority": 10
363364
}
364365
}
365366
}
366367
```
367368

369+
**Priority Field**: Extensions are ordered by `priority` (lower = higher precedence). Default is 10. Used for template resolution when multiple extensions provide the same template.
370+
368371
### 3. Configuration
369372

370373
```bash
@@ -1084,11 +1087,15 @@ List installed extensions in current project.
10841087
$ specify extension list
10851088
10861089
Installed Extensions:
1087-
✓ jira (v1.0.0) - Jira Integration
1088-
Commands: 3 | Hooks: 2 | Status: Enabled
1089-
1090-
✓ linear (v0.9.0) - Linear Integration
1091-
Commands: 1 | Hooks: 1 | Status: Enabled
1090+
✓ Jira Integration (v1.0.0)
1091+
jira
1092+
Create Jira issues from spec-kit artifacts
1093+
Commands: 3 | Hooks: 2 | Priority: 10 | Status: Enabled
1094+
1095+
✓ Linear Integration (v0.9.0)
1096+
linear
1097+
Create Linear issues from spec-kit artifacts
1098+
Commands: 1 | Hooks: 1 | Priority: 10 | Status: Enabled
10921099
```
10931100

10941101
**Options:**
@@ -1196,10 +1203,9 @@ Next steps:
11961203

11971204
**Options:**
11981205

1199-
- `--from URL`: Install from custom URL or Git repo
1200-
- `--version VERSION`: Install specific version
1201-
- `--dev PATH`: Install from local path (development mode)
1202-
- `--no-register`: Skip command registration (manual setup)
1206+
- `--from URL`: Install from a remote URL (archive). Does not accept Git repositories directly.
1207+
- `--dev`: Install from a local path in development mode (the PATH is the positional `extension` argument).
1208+
- `--priority NUMBER`: Set resolution priority (lower = higher precedence, default 10)
12031209

12041210
#### `specify extension remove NAME`
12051211

@@ -1280,6 +1286,29 @@ $ specify extension disable jira
12801286
To re-enable: specify extension enable jira
12811287
```
12821288

1289+
#### `specify extension set-priority NAME PRIORITY`
1290+
1291+
Change the resolution priority of an installed extension.
1292+
1293+
```bash
1294+
$ specify extension set-priority jira 5
1295+
1296+
✓ Extension 'Jira Integration' priority changed: 10 → 5
1297+
1298+
Lower priority = higher precedence in template resolution
1299+
```
1300+
1301+
**Priority Values:**
1302+
1303+
- Lower numbers = higher precedence (checked first in resolution)
1304+
- Default priority is 10
1305+
- Must be a positive integer (1 or higher)
1306+
1307+
**Use Cases:**
1308+
1309+
- Ensure a critical extension's templates take precedence
1310+
- Override default resolution order when multiple extensions provide similar templates
1311+
12831312
---
12841313

12851314
## Compatibility & Versioning

0 commit comments

Comments
 (0)