Package as plugin

This commit is contained in:
2026-03-05 01:33:16 -06:00
parent ad31310a77
commit c9a311ad07
5 changed files with 32 additions and 135 deletions

View File

@@ -0,0 +1,9 @@
{
"name": "runescape-wiki",
"description": "Query the RuneScape Wiki (RS3 and OSRS) for items, quests, skills, and Grand Exchange prices",
"version": "1.0.0",
"author": {
"name": "sam"
},
"keywords": ["runescape", "osrs", "rs3", "wiki", "grand-exchange", "gaming"]
}

2
.gitignore vendored
View File

@@ -1,3 +1 @@
.claude/settings.local.json
scripts/rsw/rsw

View File

@@ -1,112 +0,0 @@
# rsw Build & Completion Notes
## What's done
All Go source files are written and structurally complete:
```
scripts/rsw/
├── main.go # Entry point
├── go.mod # Module definition (needs go mod tidy)
└── internal/
├── cmd/
│ ├── root.go # Root command, global flags, URL helpers
│ ├── game.go # osrs/rs3 parent commands + factory registration
│ ├── search.go # rsw <game> search <query>
│ ├── page.go # rsw <game> page <title> [--section]
│ ├── item.go # rsw <game> item <name> [--ironman]
│ ├── quest.go # rsw <game> quest <name> [--ironman]
│ ├── skill.go # rsw <game> skill <name> [--level] [--ironman]
│ └── price.go # rsw <game> price <name> [--ironman]
├── wiki/
│ ├── client.go # HTTP client for MediaWiki API
│ ├── search.go # action=query&list=search wrapper
│ └── parse.go # action=parse wrapper (wikitext, sections, HTML)
├── prices/
│ ├── client.go # HTTP client for prices.runescape.wiki API
│ └── mapping.go # Item ID↔name cache with disk persistence
├── render/
│ └── markdown.go # Markdown output builder (headings, tables, KV, GP formatting)
└── extract/
└── infobox.go # Wikitext template parser (handles nesting, wiki links, refs)
```
## What needs to happen next
### 1. `go mod tidy` + `go mod download`
The go.mod declares the cobra dependency but doesn't have a go.sum yet. Run:
```bash
cd scripts/rsw
go mod tidy
```
This will resolve the full dependency tree and create go.sum.
### 2. Compile & smoke test
```bash
go build -o rsw .
./rsw osrs search "dragon scimitar"
./rsw osrs item "abyssal whip"
./rsw osrs quest "Monkey Madness I"
./rsw osrs price "dragon bones"
./rsw rs3 quest "Plague's End"
```
### 3. Known issues to fix during testing
**`strings.Title` is deprecated** — Used in skill.go. Replace with:
```go
import "golang.org/x/text/cases"
import "golang.org/x/text/language"
caser := cases.Title(language.English)
trainingTitle := caser.String(strings.ToLower(skillName)) + " training"
```
Or just capitalize the first letter manually since we're dealing with single words.
**Template name variations** — The RS wiki uses inconsistent casing for templates
(e.g., `Infobox Item` vs `Infobox item`). The extract package does case-insensitive
matching, but you may discover new template names while testing (e.g., RS3 might use
`Infobox object` for some items). Easy to add — just extend the name list in
`findItemInfobox()`.
**Drop table templates** — OSRS uses `DropsLine`, RS3 may use different names.
Test with both games and add any missing template names to `renderDropSources()`.
**Price API for RS3** — The prices.runescape.wiki endpoint for RS3 (`/api/v1/rs/`)
may have different availability than OSRS. The mapping endpoint should work but
test it. RS3 also has the official Jagex GE API as a fallback if needed:
`https://secure.runescape.com/m=itemdb_rs/api/catalogue/detail.json?item=<id>`
### 4. Potential improvements
- **Fuzzy search for item command**: Right now `item` uses wiki search which is
good but could also cross-reference the price mapping cache for exact matches.
- **Structured drop table parsing**: The wikitext drop tables are complex
(conditional drops, noted items, etc.). Current parser handles the basics.
- **Monster lookup command**: `rsw <game> monster <name>` for combat stats,
weaknesses, drop tables. Same pattern as item/quest.
- **Category browsing**: MediaWiki has `action=query&list=categorymembers`
could support `rsw <game> list quests` or `rsw <game> list items --category "Melee weapons"`.
- **Timeseries charting**: The 5m/1h price data could generate ASCII sparklines
for price trends in the terminal.
## Architecture notes
**Factory pattern for cobra commands**: Each subcommand uses a `newXxxCmd()` factory
function registered via `RegisterCommand()`. This is because cobra doesn't support
a command having two parents — we need independent instances for osrs and rs3.
`wireCommands()` is called once at `Execute()` time to create and attach all
command instances.
**Wikitext parser**: The `extract` package implements a lightweight template parser
that handles `{{Template|key=value|...}}` with nesting, wiki links `[[Target|Display]]`,
and common markup stripping. It doesn't handle parser functions (`#if`, `#switch`)
— those are stripped as regular templates. This covers ~80% of useful data extraction
from infoboxes and drop tables.
**Price mapping cache**: Stored at `~/.rsw/cache/mapping.json` with a 24h TTL.
The mapping API returns all items (~4000 for OSRS, ~40000 for RS3) in a single call.
Caching avoids hitting this on every price lookup.

14
hooks/hooks.json Normal file
View File

@@ -0,0 +1,14 @@
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "test -f ${CLAUDE_PLUGIN_ROOT}/scripts/rsw/rsw || (cd ${CLAUDE_PLUGIN_ROOT}/scripts/rsw && command -v go >/dev/null 2>&1 && go build -o rsw . 2>/dev/null || true)"
}
]
}
]
}
}

View File

@@ -1,5 +1,5 @@
---
name: runescape-wiki
name: wiki
description: >
Query the RuneScape Wiki (RS3 and OSRS) for item details, quest requirements,
skill training guides, and Grand Exchange prices. Use this skill whenever the
@@ -7,25 +7,25 @@ description: >
game-specific concepts like quests, skills, items, monsters, the Grand Exchange,
ironman mode, HCIM, or any RuneScape game mechanics. Also trigger when the user
mentions specific in-game items, quest names, skill names, or boss names that are
clearly RuneScape-related. This skill provides a Go CLI tool (rsw) that pulls
live data from the wiki — always prefer it over answering from memory, since wiki
data is authoritative and up-to-date.
clearly RuneScape-related. Always prefer this skill over answering from memory,
since it pulls live, authoritative data from the wiki.
---
# RuneScape Wiki CLI Plugin
# RuneScape Wiki Skill
This skill provides `rsw`, a Go CLI that queries the RuneScape Wiki APIs to get
This skill provides `rsw`, a CLI that queries the RuneScape Wiki for
authoritative, up-to-date game data. It supports both **OSRS** and **RS3**.
## Setup (first use)
The CLI needs to be compiled once. On first use, run:
The binary is auto-built on session start if Go is available. If the binary is
missing, compile it manually:
```bash
cd <skill-dir>/scripts/rsw && go build -o rsw . && chmod +x rsw
cd ${CLAUDE_PLUGIN_ROOT}/scripts/rsw && go build -o rsw .
```
After that, the binary is at `<skill-dir>/scripts/rsw/rsw`.
The binary lives at `${CLAUDE_PLUGIN_ROOT}/scripts/rsw/rsw`.
If Go is not installed, tell the user they need Go 1.22+ (`go.dev/dl`).
@@ -101,15 +101,3 @@ Most players clearly play one game or the other. Look for context clues:
Don't just dump raw CLI output. Read it, synthesize an answer, and cite specifics.
If the user asks "how do I get a fire cape", run the search, pull the relevant
page sections, and give them a coherent strategy — not a wall of wikitext.
## API Details (reference)
The CLI hits two API surfaces:
1. **MediaWiki API** (`{game}.runescape.wiki/api.php`) — search, parse, query.
Includes `User-Agent: rsw-cli/1.0` per wiki guidelines.
2. **Real-time Prices API** (`prices.runescape.wiki/api/v1/{game}/`) — latest
prices, mapping (item ID→name), 5m averages, 1h averages.
Item mapping is cached locally at `~/.rsw/cache/mapping.json` (24h TTL).