How reverse-skill's refresh-tool-index Script Ensures Accurate Tool Paths: A Complete Technical Breakdown
The refresh-tool-index.ps1 script guarantees accurate tool paths by combining dynamic environment discovery, filesystem validation against actual skill definitions, and deterministic structured output generation.
The refresh-tool-index script is the backbone of path accuracy in the zhaoxuya520/reverse-skill repository. It eliminates stale entries, verifies executable availability, and produces both human-readable and machine-readable indexes that downstream routing logic trusts.
Why Path Accuracy Matters in reverse-skill
Reverse-engineering and penetration-testing workflows depend on precise tool locations. A misconfigured path breaks automation, corrupts skill routing, and wastes debugging time. The refresh-tool-index script solves this by treating the filesystem as the single source of truth rather than trusting static configuration files.
Step 1: Dynamic Tool Discovery via ToolDiscovery.ps1
The script begins by importing its discovery engine at skills/scripts/refresh-tool-index.ps1#L20:
. (Join-Path $PSScriptRoot 'lib\ToolDiscovery.ps1')
This module provides three critical functions that probe the host environment:
Get-ReverseToolReport– Scans registered tool specifications and queries each for availabilityResolve-ReverseToolSpec– Converts abstract tool definitions into concrete filesystem paths usingGet-Command, registry lookups, and well-known installation directories- Version detection – Executes tools with
--versionor-vflags and parses output to capture exact build numbers
The discovery layer handles cross-platform variations (Windows registry vs. Unix PATH) and normalizes results into a consistent PowerShell object structure.
Step 2: Validation Against Real Skill Files
Raw discovery produces candidate entries. The script filters these against the actual repository structure at skills/scripts/refresh-tool-index.ps1#L66-L70:
$skillMd = Join-Path $PSScriptRoot "..\..\$($report.Skill)\SKILL.md"
if (-not (Test-Path -LiteralPath $skillMd)) {
Write-Warning "Skipping $($report.Name): SKILL.md not found at $skillMd"
continue
}
This existence check guarantees that:
- Every indexed tool maps to an active skill definition
- Deleted or renamed skills automatically disappear from the index
- Orphaned tool installations do not pollute the output
Step 3: Structured Output Generation
Vetted reports flow into dual output pipelines. The script iterates at skills/scripts/refresh-tool-index.ps1#L87-L96:
foreach ($report in $reports) {
$mdLine = "| ``$($report.Name)`` | ``$($report.Skill)`` | $($report.Purpose) | $(if ($report.Available) { "yes" } else { "no" }) | ``$($report.ResolvedPath)`` | $($report.Version) | $($report.Source) | $($scriptRefs[$report.Name] -join ", ") |"
Add-Content -Path $OutputMarkdown -Value $mdLine
}
Markdown Table Output
The generated tool-index.md provides at-a-glance verification:
| Tool | Skill | Purpose | Available | Path | Version | Source | Script References |
|---|---|---|---|---|---|---|---|
jadx |
apk-reverse |
APK decompilation | yes | C:\Program Files\jadx\bin\jadx.exe |
1.4.7 | GitHub | apk-reverse/scripts/decode.ps1 |
frida |
apk-reverse |
Dynamic instrumentation | yes | C:\Python38\Scripts\frida.exe |
16.2.0 | pip | apk-reverse/scripts/frida-run.ps1 |
JSON Machine Output
Simultaneously, the script builds tool-index.json at skills/scripts/refresh-tool-index.ps1#L56-L78:
$jsonEntry = @{
name = $report.Name
skill = $report.Skill
purpose = $report.Purpose
available = $report.Available
is_executable = $report.IsExecutable
resolved_path = $report.ResolvedPath
version = $report.Version
source = $report.Source
script_refs = $scriptRefs[$report.Name]
}
$jsonOutput += $jsonEntry
This JSON enables programmatic capability checking:
{
"name": "jadx",
"skill": "apk-reverse",
"purpose": "APK decompilation",
"available": true,
"is_executable": true,
"resolved_path": "C:\\Program Files\\jadx\\bin\\jadx.exe",
"version": "1.4.7",
"source": "GitHub",
"script_refs": ["apk-reverse/scripts/decode.ps1"]
}
Running the refresh-tool-index Script
Default execution generates indexes in standard locations:
# From repository root
.\skills\scripts\refresh-tool-index.ps1
Custom output paths support documentation pipelines:
.\skills\scripts\refresh-tool-index.ps1 `
-OutputMarkdown ".\docs\tool-index.md" `
-OutputJson ".\docs\tool-index.json"
Core Architecture Files
| File | Responsibility | Line Reference |
|---|---|---|
skills/scripts/refresh-tool-index.ps1 |
Orchestrates discovery, validation, and output | Main script |
skills/scripts/lib/ToolDiscovery.ps1 |
Implements Get-ReverseToolReport, Resolve-ReverseToolSpec, and version detection |
Discovery module |
tool-index.md (generated) |
Human-readable reference for routing logic | Produced by script |
tool-index.json (generated) |
Machine-readable capability data | Produced by script |
Summary
- Dynamic discovery probes the actual runtime environment rather than trusting static configuration
- Filesystem validation cross-checks every tool against existing
SKILL.mddefinitions, eliminating stale entries - Dual output format serves both human reviewers and automated routing systems with identical underlying data
- Deterministic regeneration ensures the index reflects current system state every time the script runs
Frequently Asked Questions
How does refresh-tool-index handle tools that are installed but not referenced by any skill?
The script's Test-Path check against SKILL.md filters these out. Only tools with active skill definitions survive to the output stage.
What happens if a tool's executable moves or is uninstalled between index runs?
Resolve-ReverseToolSpec detects the missing path during the next discovery phase. The available flag becomes false and the entry either disappears (if strict filtering is enabled) or appears as unavailable in the output.
Can the script detect version downgrades or upgrades automatically?
Yes. The discovery module executes version flags on every run and captures the output string. Comparing successive tool-index.json files reveals version changes without manual tracking.
Is refresh-tool-index cross-platform compatible?
The underlying ToolDiscovery.ps1 implements platform-specific resolvers for Windows (registry, Program Files) and Unix-like systems (which, command -v). The main script remains portable PowerShell Core syntax.
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 →