How the Priority Array in routing.json Determines Rule Precedence in Reverse-Skill
The priority array resolves ties by selecting the route ID that appears earliest in the list when multiple routes achieve equal matching scores.
The routing.json file in the zhaoxuya520/reverse-skill repository serves as the central configuration for task-routing logic, where the priority array explicitly defines the precedence hierarchy for all 42 routes (R0 through R41). When incoming requests match multiple keyword patterns simultaneously, this ordered list determines which route takes precedence without requiring changes to individual keyword definitions.
The Three-Stage Precedence Algorithm
The routing engine implements a deterministic decision tree defined in skills/config/routing.json. Understanding each stage reveals why the priority array's order is critical to system behavior.
Stage 1: Score Accumulation
Every route that matches a user request accumulates points based on the number and type of keyword hits defined in the configuration (lines 4-7). Routes with more matching keywords or higher-weighted patterns receive higher scores. This initial filtering identifies all viable candidates for a given request.
Stage 2: Winner Selection
If a single route achieves a uniquely high score, the engine immediately designates it as the PRIMARY route. No tie-breaking occurs in this scenario, regardless of the priority array's order.
Stage 3: Priority Array Tie-Breaker
When two or more routes share identical top scores, the engine iterates through the priority array from the first element to the last. The first route ID present among the tied candidates wins the selection (lines 24-29). For example, if both R1 and R2 tie for the highest score, but R1 appears before R2 in the priority list, R1 becomes the active route.
Priority Array Configuration and Fallback Behavior
The explicit ordering of route IDs in the priority array directly encodes business logic priorities. Routes positioned at the beginning of the array possess the highest precedence, while those at the end serve as catch-all fallbacks.
The fallback route R0 occupies the final position in the priority array, ensuring it only activates when no other route registers any keyword matches. This兜底 mechanism guarantees that every request receives a routing decision even when specific keywords are absent.
Verifying and Querying Route Precedence
You can inspect the current precedence hierarchy directly from the configuration file without loading the PowerShell routing scripts.
To view the exact priority order using jq:
jq '.priority' skills/config/routing.json
This outputs the ordered list (e.g., ["R4","R1","R2",...,"R0"]), revealing which routes take precedence during ties.
To trace how a specific request would resolve when multiple patterns match:
# Example: A request matching both APK reverse engineering and mobile security patterns
$request = "I need to decompile an Android APK and bypass root detection"
# The routing logic in master-route.ps1 executes:
# 1. Pattern matching against all routes in routing.json
# 2. Score calculation (R1 and R2 both match)
# 3. Priority array consultation: R1 appears before R2, so R1 wins
Summary
- The
priorityarray inskills/config/routing.jsonserves as the final arbiter when multiple routes achieve equal matching scores. - Earlier positions in the array indicate higher precedence; the engine selects the first matching route ID from left to right during tie-breaking.
- Route R0 occupies the final position as the universal fallback for unmatched requests.
- The PowerShell scripts
master-route.ps1andverify-routing-coherence.ps1implement and validate this precedence logic against the configuration andMASTER-ROUTING.md. - Modifying the array order changes routing behavior without altering individual keyword definitions.
Frequently Asked Questions
What happens if two routes tie for the highest score but neither appears in the priority array?
This scenario should not occur in a properly configured system. The verify-routing-coherence.ps1 script validates that all routes defined in routing.json are represented in the priority array and documented in MASTER-ROUTING.md. If a route were missing, the tie-breaker logic would skip it, potentially resulting in no primary route selection.
Can I change route precedence without editing keyword patterns?
Yes. Simply reordering the route IDs in the priority array within skills/config/routing.json changes precedence immediately. For example, moving "R2" before "R1" ensures R2 wins all future ties between these routes, while their underlying keyword definitions in the configuration remain unchanged.
Why does R0 always appear at the end of the priority array?
R0 serves as the catch-all fallback route designed to handle requests that match no specific keywords. Its terminal position ensures it only wins when all other routes score zero hits. Moving R0 earlier would cause it to intercept requests that should route to more specific handlers with actual keyword matches.
How does master-route.ps1 use the priority array during execution?
The master-route.ps1 script loads routing.json into memory, computes match scores for all routes against the incoming request, identifies the maximum score group, and then filters that group against the ordered priority list. It selects the first route ID from the priority array that exists within the tied high-score candidates, as implemented in the routing logic at lines 24-29 of the configuration.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →