# How to Execute master-route.ps1 for Primary Routing in Reverse-Skill

> Execute master-route.ps1 for primary routing by invoking it with the -Hint parameter. This script matches keywords, scores them, and identifies your primary skill with a confidence level.

- Repository: [ZhaoXu/reverse-skill](https://github.com/zhaoxuya520/reverse-skill)
- Tags: how-to-guide
- Published: 2026-08-06

---

**To execute `master-route.ps1` for primary routing, invoke the script with the `-Hint` parameter containing your task description, which triggers keyword matching against 40 skill IDs (R0-R39), scores the matches using a priority array, and outputs a [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md) file identifying the PRIMARY skill with confidence level.**

The `master-route.ps1` script serves as the core router for the **reverse-skill** framework, a modular system designed to route reverse engineering tasks to specialized skill modules. According to the source code in `zhaoxuya520/reverse-skill`, the script implements the contract defined in [`MASTER-ROUTING.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/MASTER-ROUTING.md) by analyzing natural language hints and selecting the most appropriate skill file from the repository.

## Understanding the Routing Contract

The routing process follows a strict contract documented in [`skills/MASTER-ROUTING.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/skills/MASTER-ROUTING.md). This contract specifies how the framework interprets task descriptions and maps them to concrete skill implementations.

When you provide a hint (e.g., "Analyze an Android APK for obfuscation"), the script performs four distinct operations:

1. **Keyword Extraction** – Parses the hint for English and Chinese keywords (e.g., `apk`, `ios`, `ida`, `k8s`, `ad`)
2. **Candidate Selection** – Maps keywords to skill IDs ranging from `R0` to `R39`
3. **Priority Scoring** – Applies a hard-coded `$priority` array to rank candidates
4. **Primary Assignment** – Designates the highest-scoring match as **PRIMARY** with confidence levels of *high*, *medium*, or *low*

If no keywords match, the script defaults to `R0` (general reverse-engineering) and suggests consulting [`routing.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.md) for manual matrix lookup.

## Prerequisites and Script Location

Before execution, verify that you have access to the repository structure. The primary routing script resides at:

```

skills/scripts/master-route.ps1

```

The script requires PowerShell 5.1 or higher. It resolves the project root automatically when invoked from within the repository, but you can override this using the `-ProjectRoot` parameter when calling the script from external locations.

## Parameter Reference

The script accepts three parameters as defined in lines 3-7 of `master-route.ps1`:

- **`-Hint`** (Required): The task description string containing keywords that determine routing (e.g., "Investigate Windows AD credential dump")
- **`-OutDir`** (Optional): Custom output directory for the generated [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md). Defaults to `work/master-route-<timestamp>/`
- **`-ProjectRoot`** (Optional): Explicit path to the repository root. Use this when invoking the script from outside the `reverse-skill` directory structure

## Executing the Script

Run the script using PowerShell with the appropriate parameters for your environment.

**Basic execution from within the repository:**

```powershell
powershell -File skills\scripts\master-route.ps1 -Hint "Analyze an Android APK for obfuscation"

```

**Specifying a custom output directory:**

```powershell
powershell -File skills\scripts\master-route.ps1 `
    -Hint "Investigate a potential Windows AD credential dump" `
    -OutDir "C:\my-analysis\work\custom-route"

```

**Running from outside the repository with explicit project root:**

```powershell
powershell -File skills\scripts\master-route.ps1 `
    -Hint "Find vulnerabilities in a Kubernetes cluster" `
    -ProjectRoot "D:\projects\reverse-skill"

```

## Understanding the Output

Upon successful execution, the script generates a markdown report at `work/master-route-<timestamp>/route-scope.md`. The console output displays the routing decision immediately:

```

PRIMARY -> skills/kubernetes-reverse/SKILL.md
Label: Cloud / K8s | confidence: medium
Wrote C:\my-analysis\work\custom-route\route-scope.md
ACTION: Open PRIMARY SKILL.md now and execute ACTION REQUIRED.

```

The generated [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md) contains:
- The resolved path to the PRIMARY skill file
- Human-readable label and confidence assessment
- List of secondary skills (all other matched candidates)
- Execution notes directing you to open the specific [`SKILL.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SKILL.md) file

## How the Routing Logic Works

The implementation in `master-route.ps1` follows a deterministic scoring algorithm.

**Pattern Matching Phase (Lines 101-148):**
The script converts the hint to lowercase and executes a series of regex matching statements. For example:

```powershell
if ($t -match "apk|android|dex") { $sel.Add('R1') }
if ($t -match "ios|ipa|xcode") { $sel.Add('R2') }

```

Each match adds a corresponding skill ID to the selection array `$sel`.

**Scoring and Prioritization (Lines 154-176):**
The script initializes a `$scores` hash table and references the `$priority` array—a hard-coded list that determines which skills take precedence when multiple keywords match. The selection loop iterates through candidates, assigning scores based on priority position.

**Confidence Assessment (Lines 78-86):**
The script evaluates match strength to assign confidence levels. If the primary candidate appears early in the priority list and matches multiple keywords, confidence is *high*. Single-keyword matches or low-priority positions yield *medium* or *low* confidence.

**File Validation and Output Generation:**
Before writing output, the script validates that the selected [`SKILL.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SKILL.md) exists at `skills/<skill-name>/SKILL.md`. The output file is written with UTF-8 BOM encoding using `StringBuilder` (lines 108-137), ensuring proper character handling for international skill labels.

## Summary

- **Invoke** `master-route.ps1` with the mandatory `-Hint` parameter containing your task description to trigger the routing engine
- **Review** the console output for the PRIMARY skill path and confidence level immediately after execution
- **Open** the generated [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md) in `work/master-route-<timestamp>/` to see the complete routing summary and secondary candidates
- **Follow** the action items in the output to open the designated [`SKILL.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/SKILL.md) file and begin concrete analysis
- **Use** `-ProjectRoot` when calling the script from outside the repository, and `-OutDir` to customize where the routing report is saved

## Frequently Asked Questions

### What happens if master-route.ps1 finds no matching keywords?

If the script detects no strong keyword matches in your hint, it falls back to skill ID `R0`, which corresponds to general reverse-engineering capabilities. The confidence level is set to *low*, and the output advises you to consult [`routing.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/routing.md) for a full matrix lookup of all 40 available skills.

### Can I run master-route.ps1 from a different directory than the repository root?

Yes, but you must specify the `-ProjectRoot` parameter with the absolute path to the reverse-skill repository. Without this parameter, the script attempts to resolve the project root automatically relative to its execution context, which may fail if invoked from outside the repository structure.

### Where does the script store the routing decision output?

By default, the script creates a timestamped directory under `work/master-route-<timestamp>/` and writes [`route-scope.md`](https://github.com/zhaoxuya520/reverse-skill/blob/main/route-scope.md) there. You can override this location using the `-OutDir` parameter to specify a custom directory path, which is useful when integrating the router into automated analysis pipelines.

### How does the script decide between multiple matching skills?

The script uses a priority-based scoring system defined in the `$priority` array (lines 154-176). When multiple keywords match (e.g., a hint containing both "apk" and "k8s"), each candidate ID receives a score based on its position in this hard-coded priority list. The candidate with the highest score becomes PRIMARY, while others are listed as secondary options in the output markdown.