# How the mustAll Clause Ensures Compound Matches in reverse-skill

> Understand how the mustAll clause ensures compound matches in reverse-skill. Learn how it guarantees contextual accuracy in skill routing by matching every regex.

- Repository: [ZhaoXu/reverse-skill](https://github.com/zhaoxuya520/reverse-skill)
- Tags: deep-dive
- Published: 2026-08-22

---

**The `mustAll` clause guarantees compound matches by requiring every regular expression in its array to match the user hint after the primary `must` condition is satisfied, ensuring contextual accuracy in skill routing.**

The routing engine in **zhaoxuya520/reverse-skill** processes user hints to determine which specialized skill should handle a request. While the `must` field identifies primary keywords, the **`mustAll`** clause adds a secondary validation layer that prevents false positives by demanding additional contextual terms.

## Understanding the mustAll Compound Matching Logic

The `mustAll` field operates as a logical AND gate within the routing decision tree. When the PowerShell router evaluates a hint against the routing configuration in [`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json), it first checks whether the normalized hint matches the primary `must` pattern. Only upon a successful primary match does the system inspect the `mustAll` array.

According to the source code in `skills/scripts/master-route.ps1`, the implementation iterates through each pattern in the `mustAll` collection:

```powershell

# skills/scripts/master-route.ps1 – lines 42-47

if ($hit -and $null -ne $kw.mustAll) {
    foreach ($m in $kw.mustAll) {
        if ($t -notmatch $m) { $hit = $false; break }
    }
}

```

The loop evaluates each regular expression against the normalized hint (`$t`). If **any** pattern fails to match, the `$hit` flag immediately resets to `$false` and the loop exits. This strict enforcement ensures that a keyword only registers as a match when the hint contains the primary term **and** every contextual qualifier specified in `mustAll`.

## Practical Examples from routing.json

The [`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json) file contains concrete implementations of compound matching that demonstrate how `mustAll` refines routing accuracy for specific domains.

### Mobile Reverse Engineering Context

The following entry ensures that "jailbreak" queries route to mobile reverse engineering only when iOS context is present:

```json
{
  "must": "jailbreak",
  "mustAll": ["ios|iphone|ipad|mobile|objection|ipa"],
  "note": "jailbreak 仅当带 iOS 语境才归移动端"
}

```

Without this compound requirement, generic questions about container jailbreaking or Linux privilege escalation might incorrectly trigger the mobile skill.

### Malware Analysis Context

Similarly, the sandbox route uses `mustAll` to distinguish between malware analysis discussions and benign cloud development topics:

```json
{
  "must": "sandbox",
  "mustAll": ["malware|virus|恶意|木马|样本|cape|any\\.run|triage"],
  "note": "裸 sandbox 归 R9 需恶意语境（防误伤云沙箱/开发语境）"
}

```

This prevents false routing when users discuss Docker containers or cloud sandboxes in legitimate development contexts.

## PowerShell Implementation Details

The routing logic demonstrates defensive programming by normalizing input before evaluation. The router converts hints to lowercase using `$t = $Hint.ToLowerInvariant()` before checking against `mustAll` patterns, ensuring case-insensitive matching across Unicode text.

A complete evaluation flow appears as follows:

```powershell
$t = $Hint.ToLowerInvariant()
foreach ($route in $cfg.routes.PSObject.Properties) {
    foreach ($kw in $route.Value.keywords) {
        $hit = $false
        if ($kw.must -and $t -match $kw.must) { $hit = $true }
        
        # mustAll compound validation

        if ($hit -and $kw.mustAll) {
            foreach ($m in $kw.mustAll) {
                if ($t -notmatch $m) { $hit = $false; break }
            }
        }
        
        if ($hit) { $sel.Add($route.Name) }
    }
}

```

This structure allows `mustAll` to act as a gatekeeper that filters out ambiguous matches before they reach the scoring phase.

## Summary

- The **`mustAll`** clause requires **all** patterns in its array to match, functioning as a logical AND operator in the routing engine.
- Implementation resides in **`skills/scripts/master-route.ps1`** (lines 42-47), where a foreach loop validates each sub-pattern.
- Configuration occurs in **[`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json)**, pairing primary keywords with contextual qualifiers to prevent domain misrouting.
- Real-world applications include distinguishing iOS jailbreaking from container security and malware sandboxes from cloud development environments.

## Frequently Asked Questions

### What distinguishes mustAll from must in reverse-skill?

The **`must`** field defines the primary keyword trigger using a single regular expression, while **`mustAll`** contains an array of additional patterns that must **all** match to confirm the context. When both exist, the router evaluates `must` first, then validates every pattern in `mustAll` before confirming the match.

### How does mustAll prevent false positive routing?

By requiring supplemental contextual terms beyond the primary keyword, `mustAll` filters out ambiguous queries. For example, the sandbox route ignores generic container discussions unless terms like "malware," "virus," or "cape" appear in the hint, ensuring development-related sandbox queries do not route to malware analysis skills.

### Can mustAll entries include multiple alternative terms within a single pattern?

Yes, each string in the `mustAll` array is a regular expression that can contain alternation operators (|). The jailbreak example uses `"ios|iphone|ipad|mobile|objection|ipa"` as a single pattern, meaning the hint must match at least one of these terms to satisfy that specific `mustAll` requirement.

### Where is the mustAll processing logic located in the codebase?

The core logic resides in **`skills/scripts/master-route.ps1`** between lines 42-47, where the script checks for the existence of `mustAll` and iterates through its array. The routing definitions that utilize this feature are stored in **[`skills/config/routing.json`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/config/routing.json)**, which the PowerShell router loads at runtime.