From c9a311ad07f4371eda4f4fb0202ba2d964981c58 Mon Sep 17 00:00:00 2001 From: Sam Myers Date: Thu, 5 Mar 2026 01:33:16 -0600 Subject: [PATCH] Package as plugin --- .claude-plugin/plugin.json | 9 +++ .gitignore | 2 - BUILD_NOTES.md | 112 ------------------------------- hooks/hooks.json | 14 ++++ SKILL.md => skills/wiki/SKILL.md | 30 +++------ 5 files changed, 32 insertions(+), 135 deletions(-) create mode 100644 .claude-plugin/plugin.json delete mode 100644 BUILD_NOTES.md create mode 100644 hooks/hooks.json rename SKILL.md => skills/wiki/SKILL.md (79%) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..8f017dc --- /dev/null +++ b/.claude-plugin/plugin.json @@ -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"] +} diff --git a/.gitignore b/.gitignore index 6562d25..58d6a39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -.claude/settings.local.json - scripts/rsw/rsw diff --git a/BUILD_NOTES.md b/BUILD_NOTES.md deleted file mode 100644 index 04dc054..0000000 --- a/BUILD_NOTES.md +++ /dev/null @@ -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 search - │ ├── page.go # rsw page [--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. diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..af08fbe --- /dev/null +++ b/hooks/hooks.json @@ -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)" + } + ] + } + ] + } +} diff --git a/SKILL.md b/skills/wiki/SKILL.md similarity index 79% rename from SKILL.md rename to skills/wiki/SKILL.md index 214f240..360c1ae 100644 --- a/SKILL.md +++ b/skills/wiki/SKILL.md @@ -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).