From 9a708a1ab96b76fa1167497b68d31fb81fd514b8 Mon Sep 17 00:00:00 2001 From: Advait Paliwal Date: Wed, 18 Mar 2026 16:53:26 -0700 Subject: [PATCH] Alpha Hub: Context Hub for research papers CLI + MCP server for searching papers and building persistent knowledge. Powered by alphaXiv for semantic search, paper reports, and PDF Q&A. Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitignore | 3 + README.md | 99 +++ cli/bin/alpha | 2 + cli/bin/alpha-mcp | 2 + cli/package-lock.json | 1170 ++++++++++++++++++++++++++++++++++ cli/package.json | 32 + cli/src/commands/annotate.js | 65 ++ cli/src/commands/ask.js | 24 + cli/src/commands/get.js | 39 ++ cli/src/commands/login.js | 31 + cli/src/commands/search.js | 37 ++ cli/src/index.js | 67 ++ cli/src/lib/alphaxiv.js | 110 ++++ cli/src/lib/annotations.js | 57 ++ cli/src/lib/auth.js | 245 +++++++ cli/src/lib/output.js | 20 + cli/src/lib/papers.js | 25 + cli/src/mcp/server.js | 84 +++ cli/src/mcp/tools.js | 94 +++ package.json | 6 + 20 files changed, 2212 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 cli/bin/alpha create mode 100755 cli/bin/alpha-mcp create mode 100644 cli/package-lock.json create mode 100644 cli/package.json create mode 100644 cli/src/commands/annotate.js create mode 100644 cli/src/commands/ask.js create mode 100644 cli/src/commands/get.js create mode 100644 cli/src/commands/login.js create mode 100644 cli/src/commands/search.js create mode 100644 cli/src/index.js create mode 100644 cli/src/lib/alphaxiv.js create mode 100644 cli/src/lib/annotations.js create mode 100644 cli/src/lib/auth.js create mode 100644 cli/src/lib/output.js create mode 100644 cli/src/lib/papers.js create mode 100644 cli/src/mcp/server.js create mode 100644 cli/src/mcp/tools.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7defa7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.env.local +.env diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a06d71 --- /dev/null +++ b/README.md @@ -0,0 +1,99 @@ +# Alpha Hub + +Research agents hallucinate paper details and forget what they learn in a session. Alpha Hub gives them semantic paper search, AI-generated reports, and persistent annotations — so they get smarter with every task. Search and content powered by [alphaXiv](https://alphaxiv.org). + +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) +[![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org) + +## Quick Start + +```bash +npm install -g @alpha-hub/cli +alpha login # sign in with alphaXiv +alpha search "attention mechanism" # search papers +alpha get 1706.03762 # fetch paper report +``` + +## How It Works + +Alpha is designed for your coding agent to use (not for you to use!). You can prompt your agent to use it (e.g., "Use the CLI command `alpha` to search for papers on LoRA. Run `alpha` to see how it works.") + +**Most of the time, it's simple — search, read, use:** + +```bash +alpha search "transformer attention" # find relevant papers +alpha get 1706.03762 # fetch AI-generated paper report +# Agent reads the report, understands the paper. Done. +``` + +**When the agent discovers something useful**, it can annotate locally for next time: + +```bash +alpha annotate 1706.03762 "Superseded by Flash Attention for efficiency" + +# Next session, the annotation appears automatically on alpha get. +``` + +**Need to go deeper?** Ask questions about any paper: + +```bash +alpha ask 1706.03762 "What datasets were used for evaluation?" +``` + +## Commands + +| Command | Purpose | +|---------|---------| +| `alpha search ` | Search papers (semantic, keyword, or agentic) | +| `alpha get ` | Fetch paper report + local annotation | +| `alpha ask ` | Ask a question about a paper | +| `alpha annotate ` | Attach a note to a paper | +| `alpha annotate --clear` | Remove a note | +| `alpha annotate --list` | List all notes | +| `alpha login` | Sign in with alphaXiv | +| `alpha logout` | Sign out | + +All commands accept `--json` for machine-readable output. + +## Self-Improving Agents + +Alpha Hub is designed for a loop where agents get better over time. + +**Annotations** are local notes that agents attach to papers. They persist across sessions and appear automatically on future fetches — so agents learn from past experience. + +``` + Without Alpha Hub With Alpha Hub + ───────────────── ────────────── + Search the web for papers Semantic search via alphaXiv + Read raw PDFs AI-generated paper reports + Miss context and gotchas Agent notes what it learns + Knowledge forgotten ↗ Even smarter next session + ↻ Repeat next session +``` + +## Key Features + +### Semantic Search + +Three search modes — semantic (embedding similarity), keyword (exact terms), and agentic (multi-turn retrieval) — so agents find the right papers regardless of how they phrase the query. + +```bash +alpha search "methods for reducing hallucination in LLMs" # semantic +alpha search "LoRA" --mode keyword # keyword +``` + +### Paper Q&A + +Ask questions about any paper without reading the full PDF. The answer is grounded in the paper's actual content. + +```bash +alpha ask 2106.09685 "What is the rank used for the low-rank matrices?" +``` + +### Annotations + +Local notes that agents attach to papers — they persist across sessions and appear automatically on future fetches. See the annotation as a gap the agent discovered and recorded so it doesn't repeat the same mistake. + +## License + +[MIT](LICENSE) diff --git a/cli/bin/alpha b/cli/bin/alpha new file mode 100755 index 0000000..d171ae5 --- /dev/null +++ b/cli/bin/alpha @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import '../src/index.js'; diff --git a/cli/bin/alpha-mcp b/cli/bin/alpha-mcp new file mode 100755 index 0000000..99b31eb --- /dev/null +++ b/cli/bin/alpha-mcp @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import '../src/mcp/server.js'; diff --git a/cli/package-lock.json b/cli/package-lock.json new file mode 100644 index 0000000..67b3ede --- /dev/null +++ b/cli/package-lock.json @@ -0,0 +1,1170 @@ +{ + "name": "@alpha-hub/cli", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@alpha-hub/cli", + "version": "0.1.0", + "license": "MIT", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.27.1", + "chalk": "^5.3.0", + "commander": "^12.0.0", + "zod": "^3.23.0" + }, + "bin": { + "alpha": "bin/alpha", + "alpha-mcp": "bin/alpha-mcp" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@hono/node-server": { + "version": "1.19.11", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.11.tgz", + "integrity": "sha512-dr8/3zEaB+p0D2n/IUrlPF1HZm586qgJNXK1a9fhg/PzdtkK7Ksd5l312tJX2yBuALqDYBlG20QEbayqPyxn+g==", + "license": "MIT", + "engines": { + "node": ">=18.14.1" + }, + "peerDependencies": { + "hono": "^4" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.27.1.tgz", + "integrity": "sha512-sr6GbP+4edBwFndLbM60gf07z0FQ79gaExpnsjMGePXqFcSSb7t6iscpjk9DhFhwd+mTEQrzNafGP8/iGGFYaA==", + "license": "MIT", + "dependencies": { + "@hono/node-server": "^1.19.9", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.2.1", + "express-rate-limit": "^8.2.1", + "hono": "^4.11.4", + "jose": "^6.1.3", + "json-schema-typed": "^8.0.2", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.25 || ^4.0", + "zod-to-json-schema": "^3.25.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + }, + "zod": { + "optional": false + } + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/commander": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/content-disposition": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz", + "integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.3.1.tgz", + "integrity": "sha512-D1dKN+cmyPWuvB+G2SREQDzPY1agpBIcTa9sJxOPMCNeH3gwzhqJRDWCXW3gg0y//+LQ/8j52JbMROWyrKdMdw==", + "license": "MIT", + "dependencies": { + "ip-address": "10.1.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hono": { + "version": "4.12.8", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.8.tgz", + "integrity": "sha512-VJCEvtrezO1IAR+kqEYnxUOoStaQPGrCmX3j4wDTNOcD1uRPFpGlwQUIW8niPuvHXaTUxeOUl5MMDGrl+tmO9A==", + "license": "MIT", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", + "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/jose": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.2.tgz", + "integrity": "sha512-d7kPDd34KO/YnzaDOlikGpOurfF0ByC2sEV4cANCtdqLlTfBlw2p14O/5d/zv40gJPbIQxfES3nSx1/oYNyuZQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json-schema-typed": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", + "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", + "license": "BSD-2-Clause" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", + "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "3.25.76", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", + "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.25.1", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.1.tgz", + "integrity": "sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25 || ^4" + } + } + } +} diff --git a/cli/package.json b/cli/package.json new file mode 100644 index 0000000..ad0717b --- /dev/null +++ b/cli/package.json @@ -0,0 +1,32 @@ +{ + "name": "@alpha-hub/cli", + "version": "0.1.0", + "description": "CLI for Alpha Hub - search papers and share community annotations", + "type": "module", + "bin": { + "alpha": "./bin/alpha", + "alpha-mcp": "./bin/alpha-mcp" + }, + "files": [ + "bin/", + "src/" + ], + "engines": { + "node": ">=18.0.0" + }, + "keywords": [ + "research", + "papers", + "annotations", + "alphaxiv", + "mcp", + "cli" + ], + "license": "MIT", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.27.1", + "chalk": "^5.3.0", + "commander": "^12.0.0", + "zod": "^3.23.0" + } +} diff --git a/cli/src/commands/annotate.js b/cli/src/commands/annotate.js new file mode 100644 index 0000000..2227a97 --- /dev/null +++ b/cli/src/commands/annotate.js @@ -0,0 +1,65 @@ +import chalk from 'chalk'; +import { writeAnnotation, readAnnotation, clearAnnotation, listAnnotations } from '../lib/annotations.js'; +import { normalizePaperId } from '../lib/papers.js'; +import { output, error } from '../lib/output.js'; + +function formatList(annotations) { + if (annotations.length === 0) { + console.log(chalk.dim('No annotations.')); + return; + } + annotations.forEach(a => { + console.log(`${chalk.bold(a.id)} ${chalk.dim(`(${a.updatedAt})`)}`); + console.log(` ${a.note}`); + console.log(); + }); +} + +export function registerAnnotateCommand(program) { + program + .command('annotate [paper-id] [note]') + .description('Read, write, or list local annotations') + .option('--clear', 'Remove annotation for this paper') + .option('--list', 'List all annotations') + .action(async (paperId, note, cmdOpts) => { + const opts = { ...program.opts(), ...cmdOpts }; + + if (opts.list) { + const all = listAnnotations(); + output(all, formatList, opts); + return; + } + + if (!paperId) { + error('Provide a paper ID, or use --list', opts); + } + + const id = normalizePaperId(paperId); + + if (opts.clear) { + const removed = clearAnnotation(id); + if (removed) { + console.log(chalk.green(`Cleared annotation for ${id}`)); + } else { + console.log(chalk.dim(`No annotation for ${id}`)); + } + return; + } + + if (note) { + const saved = writeAnnotation(id, note); + output(saved, () => console.log(chalk.green(`Annotation saved for ${id}`)), opts); + return; + } + + const existing = readAnnotation(id); + if (existing) { + output(existing, () => { + console.log(`${chalk.bold(existing.id)} ${chalk.dim(`(${existing.updatedAt})`)}`); + console.log(` ${existing.note}`); + }, opts); + } else { + console.log(chalk.dim(`No annotation for ${id}`)); + } + }); +} diff --git a/cli/src/commands/ask.js b/cli/src/commands/ask.js new file mode 100644 index 0000000..09dc83c --- /dev/null +++ b/cli/src/commands/ask.js @@ -0,0 +1,24 @@ +import { answerPdfQuery, disconnect } from '../lib/alphaxiv.js'; +import { output, error } from '../lib/output.js'; +import { toArxivUrl } from '../lib/papers.js'; + +function formatAnswer(data) { + console.log(typeof data === 'string' ? data : JSON.stringify(data, null, 2)); +} + +export function registerAskCommand(program) { + program + .command('ask ') + .description('Ask a question about a paper (arXiv/alphaXiv URL or ID)') + .action(async (url, question, cmdOpts) => { + const opts = { ...program.opts(), ...cmdOpts }; + try { + const answer = await answerPdfQuery(toArxivUrl(url), question); + output(answer, formatAnswer, opts); + } catch (err) { + error(err.message, opts); + } finally { + await disconnect(); + } + }); +} diff --git a/cli/src/commands/get.js b/cli/src/commands/get.js new file mode 100644 index 0000000..39c6f5b --- /dev/null +++ b/cli/src/commands/get.js @@ -0,0 +1,39 @@ +import chalk from 'chalk'; +import { getPaperContent, disconnect } from '../lib/alphaxiv.js'; +import { readAnnotation } from '../lib/annotations.js'; +import { output, error } from '../lib/output.js'; +import { normalizePaperId, toArxivUrl } from '../lib/papers.js'; + +function formatPaper({ content, annotation }) { + console.log(typeof content === 'string' ? content : JSON.stringify(content, null, 2)); + + if (annotation) { + console.log(); + console.log(chalk.dim('---')); + console.log(chalk.dim(`[Note — ${annotation.updatedAt}]`)); + console.log(annotation.note); + } +} + +export function registerGetCommand(program) { + program + .command('get ') + .description('Get paper content + local annotation (arXiv/alphaXiv URL or ID)') + .option('--full-text', 'Get raw extracted text instead of AI report') + .action(async (url, cmdOpts) => { + const opts = { ...program.opts(), ...cmdOpts }; + try { + const paperId = normalizePaperId(url); + const arxivUrl = toArxivUrl(url); + + const content = await getPaperContent(arxivUrl, { fullText: !!opts.fullText }); + const annotation = readAnnotation(paperId); + + output({ content, annotation }, formatPaper, opts); + } catch (err) { + error(err.message, opts); + } finally { + await disconnect(); + } + }); +} diff --git a/cli/src/commands/login.js b/cli/src/commands/login.js new file mode 100644 index 0000000..2524d9c --- /dev/null +++ b/cli/src/commands/login.js @@ -0,0 +1,31 @@ +import chalk from 'chalk'; +import { login, isLoggedIn, logout } from '../lib/auth.js'; + +export function registerLoginCommand(program) { + program + .command('login') + .description('Log in to alphaXiv (opens browser)') + .action(async () => { + try { + if (isLoggedIn()) { + process.stderr.write(chalk.dim('Already logged in. Use `alpha logout` to sign out first.\n')); + } + const { userInfo } = await login(); + const name = userInfo?.name || userInfo?.email || 'unknown'; + console.log(chalk.green(`Logged in to alphaXiv as ${name}`)); + } catch (err) { + process.stderr.write(`${chalk.red('Login failed:')} ${err.message}\n`); + process.exit(1); + } + }); +} + +export function registerLogoutCommand(program) { + program + .command('logout') + .description('Log out of alphaXiv') + .action(() => { + logout(); + console.log(chalk.green('Logged out')); + }); +} diff --git a/cli/src/commands/search.js b/cli/src/commands/search.js new file mode 100644 index 0000000..c3e1e17 --- /dev/null +++ b/cli/src/commands/search.js @@ -0,0 +1,37 @@ +import chalk from 'chalk'; +import { searchByEmbedding, searchByKeyword, disconnect } from '../lib/alphaxiv.js'; +import { output, error } from '../lib/output.js'; + +function formatResults(data) { + const text = typeof data === 'string' ? data : JSON.stringify(data, null, 2); + console.log(text); +} + +export function registerSearchCommand(program) { + program + .command('search ') + .description('Search papers via alphaXiv (semantic + keyword)') + .option('-m, --mode ', 'Search mode: semantic, keyword, both', 'semantic') + .action(async (query, cmdOpts) => { + const opts = { ...program.opts(), ...cmdOpts }; + try { + let results; + if (opts.mode === 'keyword') { + results = await searchByKeyword(query); + } else if (opts.mode === 'both') { + const [semantic, keyword] = await Promise.all([ + searchByEmbedding(query), + searchByKeyword(query), + ]); + results = { semantic, keyword }; + } else { + results = await searchByEmbedding(query); + } + output(results, formatResults, opts); + } catch (err) { + error(err.message, opts); + } finally { + await disconnect(); + } + }); +} diff --git a/cli/src/index.js b/cli/src/index.js new file mode 100644 index 0000000..889a45d --- /dev/null +++ b/cli/src/index.js @@ -0,0 +1,67 @@ +import chalk from 'chalk'; +import { Command } from 'commander'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname, join } from 'node:path'; +import { registerSearchCommand } from './commands/search.js'; +import { registerGetCommand } from './commands/get.js'; +import { registerAskCommand } from './commands/ask.js'; +import { registerAnnotateCommand } from './commands/annotate.js'; +import { registerLoginCommand, registerLogoutCommand } from './commands/login.js'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8')); + +function printUsage() { + console.log(` +${chalk.bold('alpha')} — Alpha Hub CLI v${pkg.version} +Search papers and annotate what you learn. Powered by alphaXiv. + +${chalk.bold.underline('Usage')} + + ${chalk.dim('$')} alpha search "transformer attention mechanisms" ${chalk.dim('# semantic search')} + ${chalk.dim('$')} alpha search "LoRA" --mode keyword ${chalk.dim('# keyword search')} + ${chalk.dim('$')} alpha get 1706.03762 ${chalk.dim('# paper content + annotation')} + ${chalk.dim('$')} alpha get https://arxiv.org/abs/2106.09685 ${chalk.dim('# by URL')} + ${chalk.dim('$')} alpha ask 1706.03762 "How does attention work?" ${chalk.dim('# ask about a paper')} + ${chalk.dim('$')} alpha annotate 1706.03762 "key insight" ${chalk.dim('# save a note')} + ${chalk.dim('$')} alpha annotate --list ${chalk.dim('# see all notes')} + +${chalk.bold.underline('Commands')} + + ${chalk.bold('login')} Log in to alphaXiv (opens browser) + ${chalk.bold('logout')} Log out + ${chalk.bold('search')} Search papers (semantic, keyword, or agentic) + ${chalk.bold('get')} Paper content + local annotation + ${chalk.bold('ask')} Ask a question about a paper + ${chalk.bold('annotate')} [paper-id] [note] Save a note — appears on future fetches + ${chalk.bold('annotate')} --clear Remove a note + ${chalk.bold('annotate')} --list List all notes + +${chalk.bold.underline('Flags')} + + --json JSON output (for agents and piping) + -m, --mode Search mode: semantic, keyword, both (default: semantic) + --full-text Get raw text instead of AI report (for get) +`); +} + +const program = new Command(); + +program + .name('alpha') + .description('Alpha Hub - search papers and annotate what you learn') + .version(pkg.version, '-V, --cli-version') + .option('--json', 'Output as JSON (machine-readable)') + .action(() => { + printUsage(); + }); + +registerLoginCommand(program); +registerLogoutCommand(program); +registerSearchCommand(program); +registerGetCommand(program); +registerAskCommand(program); +registerAnnotateCommand(program); + +program.parse(); diff --git a/cli/src/lib/alphaxiv.js b/cli/src/lib/alphaxiv.js new file mode 100644 index 0000000..5306b7d --- /dev/null +++ b/cli/src/lib/alphaxiv.js @@ -0,0 +1,110 @@ +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; +import { getValidToken, refreshAccessToken } from './auth.js'; + +const ALPHAXIV_MCP_URL = 'https://api.alphaxiv.org/mcp/v1'; + +let _client = null; +let _connected = false; + +async function getClient() { + if (_client && _connected) return _client; + + const token = await getValidToken(); + if (!token) { + throw new Error('Not logged in. Run `alpha login` first.'); + } + + _client = new Client({ name: 'alpha', version: '0.1.0' }); + + _client.onerror = (err) => { + process.stderr.write(`[alpha] alphaXiv MCP error: ${err.message || err}\n`); + }; + + const transport = new StreamableHTTPClientTransport(new URL(ALPHAXIV_MCP_URL), { + requestInit: { + headers: { + Authorization: `Bearer ${token}`, + }, + }, + }); + + await _client.connect(transport); + _connected = true; + + return _client; +} + +async function callTool(name, args) { + let client; + try { + client = await getClient(); + } catch (err) { + if (err.message?.includes('401') || err.message?.includes('Unauthorized')) { + const newToken = await refreshAccessToken(); + if (newToken) { + _client = null; + _connected = false; + client = await getClient(); + } else { + throw new Error('Session expired. Run `alpha login` to re-authenticate.'); + } + } else { + throw err; + } + } + + const result = await client.callTool({ name, arguments: args }); + + if (result.isError) { + const text = result.content?.[0]?.text || 'Unknown error'; + throw new Error(text); + } + + const text = result.content?.[0]?.text; + if (!text) return result.content; + + try { + return JSON.parse(text); + } catch { + return text; + } +} + +export async function searchByEmbedding(query) { + return await callTool('embedding_similarity_search', { query }); +} + +export async function searchByKeyword(query) { + return await callTool('full_text_papers_search', { query }); +} + +export async function agenticSearch(query) { + return await callTool('agentic_paper_retrieval', { query }); +} + +export async function getPaperContent(url, { fullText = false } = {}) { + const args = { url }; + if (fullText) args.fullText = true; + return await callTool('get_paper_content', args); +} + +export async function answerPdfQuery(url, query) { + return await callTool('answer_pdf_queries', { url, query }); +} + +export async function readGithubRepo(githubUrl, path = '/') { + return await callTool('read_files_from_github_repository', { githubUrl, path }); +} + +export async function disconnect() { + if (_client) { + _client.onerror = () => {}; + try { + await _client.close(); + } catch { + } + _client = null; + _connected = false; + } +} diff --git a/cli/src/lib/annotations.js b/cli/src/lib/annotations.js new file mode 100644 index 0000000..a6e2e2a --- /dev/null +++ b/cli/src/lib/annotations.js @@ -0,0 +1,57 @@ +import { readFileSync, writeFileSync, unlinkSync, readdirSync, mkdirSync, existsSync } from 'node:fs'; +import { join } from 'node:path'; +import { homedir } from 'node:os'; + +function getAnnotationsDir() { + const dir = join(homedir(), '.ahub', 'annotations'); + if (!existsSync(dir)) mkdirSync(dir, { recursive: true }); + return dir; +} + +function safeFilename(id) { + return id.replace(/\//g, '--') + '.json'; +} + +export function writeAnnotation(id, note) { + const filePath = join(getAnnotationsDir(), safeFilename(id)); + const data = { + id, + note, + updatedAt: new Date().toISOString(), + }; + writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8'); + return data; +} + +export function readAnnotation(id) { + try { + const filePath = join(getAnnotationsDir(), safeFilename(id)); + return JSON.parse(readFileSync(filePath, 'utf8')); + } catch { + return null; + } +} + +export function clearAnnotation(id) { + try { + const filePath = join(getAnnotationsDir(), safeFilename(id)); + unlinkSync(filePath); + return true; + } catch { + return false; + } +} + +export function listAnnotations() { + const dir = getAnnotationsDir(); + const files = readdirSync(dir).filter(f => f.endsWith('.json')); + const annotations = []; + for (const file of files) { + try { + const data = JSON.parse(readFileSync(join(dir, file), 'utf8')); + if (data.id && data.note) annotations.push(data); + } catch { + } + } + return annotations; +} diff --git a/cli/src/lib/auth.js b/cli/src/lib/auth.js new file mode 100644 index 0000000..f22683a --- /dev/null +++ b/cli/src/lib/auth.js @@ -0,0 +1,245 @@ +import { createHash, randomBytes } from 'node:crypto'; +import { createServer } from 'node:http'; +import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'; +import { join } from 'node:path'; +import { homedir } from 'node:os'; +import { execSync } from 'node:child_process'; +import { platform } from 'node:os'; + +const CLERK_ISSUER = 'https://clerk.alphaxiv.org'; +const AUTH_ENDPOINT = `${CLERK_ISSUER}/oauth/authorize`; +const TOKEN_ENDPOINT = `${CLERK_ISSUER}/oauth/token`; +const REGISTER_ENDPOINT = `${CLERK_ISSUER}/oauth/register`; +const CALLBACK_PORT = 9876; +const REDIRECT_URI = `http://127.0.0.1:${CALLBACK_PORT}/callback`; +const USERINFO_ENDPOINT = `${CLERK_ISSUER}/oauth/userinfo`; +const SCOPES = 'profile email offline_access'; + +function getAuthPath() { + const dir = join(homedir(), '.ahub'); + if (!existsSync(dir)) mkdirSync(dir, { recursive: true }); + return join(dir, 'auth.json'); +} + +function loadAuth() { + try { + return JSON.parse(readFileSync(getAuthPath(), 'utf8')); + } catch { + return null; + } +} + +function saveAuth(data) { + writeFileSync(getAuthPath(), JSON.stringify(data, null, 2), 'utf8'); +} + +export function getAccessToken() { + const auth = loadAuth(); + if (!auth?.access_token) return null; + return auth.access_token; +} + +export function getUserId() { + const auth = loadAuth(); + return auth?.user_id || null; +} + +export function getUserName() { + const auth = loadAuth(); + return auth?.user_name || null; +} + +async function fetchUserInfo(accessToken) { + const res = await fetch(USERINFO_ENDPOINT, { + headers: { Authorization: `Bearer ${accessToken}` }, + }); + if (!res.ok) return null; + return await res.json(); +} + +async function registerClient() { + const res = await fetch(REGISTER_ENDPOINT, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + client_name: 'Alpha Hub CLI', + redirect_uris: [REDIRECT_URI], + grant_types: ['authorization_code'], + response_types: ['code'], + token_endpoint_auth_method: 'none', + }), + }); + + if (!res.ok) throw new Error(`Client registration failed: ${res.status}`); + return await res.json(); +} + +function generatePKCE() { + const verifier = randomBytes(32).toString('base64url'); + const challenge = createHash('sha256').update(verifier).digest('base64url'); + return { verifier, challenge }; +} + +function openBrowser(url) { + const plat = platform(); + if (plat === 'darwin') execSync(`open "${url}"`); + else if (plat === 'linux') execSync(`xdg-open "${url}"`); + else if (plat === 'win32') execSync(`start "${url}"`); +} + +function waitForCallback(server) { + return new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + server.close(); + reject(new Error('Login timed out after 120 seconds')); + }, 120000); + + server.on('request', (req, res) => { + const url = new URL(req.url, `http://127.0.0.1:${CALLBACK_PORT}`); + + if (url.pathname !== '/callback') { + res.writeHead(404); + res.end(); + return; + } + + const code = url.searchParams.get('code'); + const error = url.searchParams.get('error'); + + if (error) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end('

Login failed

You can close this tab.

'); + clearTimeout(timeout); + server.close(); + reject(new Error(`OAuth error: ${error}`)); + return; + } + + if (code) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end('

Logged in to Alpha Hub

You can close this tab.

'); + clearTimeout(timeout); + server.close(); + resolve(code); + } + }); + }); +} + +async function exchangeCode(code, clientId, codeVerifier) { + const body = new URLSearchParams({ + grant_type: 'authorization_code', + code, + redirect_uri: REDIRECT_URI, + client_id: clientId, + code_verifier: codeVerifier, + }); + + const res = await fetch(TOKEN_ENDPOINT, { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: body.toString(), + }); + + if (!res.ok) { + const text = await res.text(); + throw new Error(`Token exchange failed (${res.status}): ${text}`); + } + + return await res.json(); +} + +export async function refreshAccessToken() { + const auth = loadAuth(); + if (!auth?.refresh_token || !auth?.client_id) return null; + + const body = new URLSearchParams({ + grant_type: 'refresh_token', + refresh_token: auth.refresh_token, + client_id: auth.client_id, + }); + + const res = await fetch(TOKEN_ENDPOINT, { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: body.toString(), + }); + + if (!res.ok) return null; + + const tokens = await res.json(); + saveAuth({ + ...auth, + access_token: tokens.access_token, + refresh_token: tokens.refresh_token || auth.refresh_token, + expires_at: tokens.expires_in ? Date.now() + tokens.expires_in * 1000 : auth.expires_at, + }); + + return tokens.access_token; +} + +export async function login() { + const registration = await registerClient(); + const clientId = registration.client_id; + const { verifier, challenge } = generatePKCE(); + + const state = randomBytes(16).toString('hex'); + + const authUrl = new URL(AUTH_ENDPOINT); + authUrl.searchParams.set('client_id', clientId); + authUrl.searchParams.set('redirect_uri', REDIRECT_URI); + authUrl.searchParams.set('response_type', 'code'); + authUrl.searchParams.set('scope', SCOPES); + authUrl.searchParams.set('code_challenge', challenge); + authUrl.searchParams.set('code_challenge_method', 'S256'); + authUrl.searchParams.set('state', state); + + const server = createServer(); + server.listen(CALLBACK_PORT); + + process.stderr.write('Opening browser for alphaXiv login...\n'); + openBrowser(authUrl.toString()); + process.stderr.write(`If browser didn't open, visit:\n${authUrl.toString()}\n\n`); + process.stderr.write('Waiting for login...\n'); + + const code = await waitForCallback(server); + + const tokens = await exchangeCode(code, clientId, verifier); + + const userInfo = await fetchUserInfo(tokens.access_token); + + saveAuth({ + client_id: clientId, + access_token: tokens.access_token, + refresh_token: tokens.refresh_token, + expires_at: tokens.expires_in ? Date.now() + tokens.expires_in * 1000 : null, + user_id: userInfo?.sub || null, + user_name: userInfo?.name || userInfo?.preferred_username || null, + user_email: userInfo?.email || null, + }); + + return { tokens, userInfo }; +} + +export async function getValidToken() { + let token = getAccessToken(); + if (token) { + const auth = loadAuth(); + if (auth?.expires_at && Date.now() > auth.expires_at - 60000) { + token = await refreshAccessToken(); + } + if (token) return token; + } + return null; +} + +export function isLoggedIn() { + return !!getAccessToken(); +} + +export function logout() { + try { + writeFileSync(getAuthPath(), '{}', 'utf8'); + } catch { + } +} diff --git a/cli/src/lib/output.js b/cli/src/lib/output.js new file mode 100644 index 0000000..4ab0f3f --- /dev/null +++ b/cli/src/lib/output.js @@ -0,0 +1,20 @@ +export function output(data, humanFormatter, opts) { + if (opts?.json) { + console.log(JSON.stringify(data, null, 2)); + } else { + humanFormatter(data); + } +} + +export function info(msg) { + process.stderr.write(msg + '\n'); +} + +export function error(msg, opts) { + if (opts?.json) { + console.log(JSON.stringify({ error: msg })); + } else { + process.stderr.write(`Error: ${msg}\n`); + } + process.exit(1); +} diff --git a/cli/src/lib/papers.js b/cli/src/lib/papers.js new file mode 100644 index 0000000..b25db1d --- /dev/null +++ b/cli/src/lib/papers.js @@ -0,0 +1,25 @@ +export function normalizePaperId(input) { + const patterns = [ + /arxiv\.org\/abs\/(\d+\.\d+)/, + /arxiv\.org\/pdf\/(\d+\.\d+)/, + /alphaxiv\.org\/(?:abs|overview)\/(\d+\.\d+)/, + ]; + + for (const pattern of patterns) { + const match = input.match(pattern); + if (match) return match[1]; + } + + if (/^\d+\.\d+$/.test(input)) return input; + + return input; +} + +export function toArxivUrl(input) { + const id = normalizePaperId(input); + if (/^\d+\.\d+$/.test(id)) { + return `https://arxiv.org/abs/${id}`; + } + if (input.startsWith('http')) return input; + return `https://arxiv.org/abs/${input}`; +} diff --git a/cli/src/mcp/server.js b/cli/src/mcp/server.js new file mode 100644 index 0000000..2dff8fa --- /dev/null +++ b/cli/src/mcp/server.js @@ -0,0 +1,84 @@ +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname, join } from 'node:path'; +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; +import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; +import { z } from 'zod'; +import { handleSearch, handleGet, handleAsk, handleAnnotate, handleCode } from './tools.js'; + +const _stderr = process.stderr; +console.log = (...args) => _stderr.write(args.join(' ') + '\n'); +console.warn = (...args) => _stderr.write('[warn] ' + args.join(' ') + '\n'); +console.info = (...args) => _stderr.write('[info] ' + args.join(' ') + '\n'); +console.debug = (...args) => _stderr.write('[debug] ' + args.join(' ') + '\n'); + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf8')); + +const server = new McpServer({ + name: 'alpha', + version: pkg.version, +}); + +server.tool( + 'alpha_search', + 'Search research papers via alphaXiv. Supports semantic (embedding), keyword, and agentic search modes.', + { + query: z.string().describe('Search query — use 2-3 sentences for semantic mode, keywords for keyword mode'), + mode: z.enum(['semantic', 'keyword', 'agentic']).optional().describe('Search mode (default: semantic)'), + }, + async (args) => handleSearch(args), +); + +server.tool( + 'alpha_get', + 'Get paper content and local annotation. Accepts arXiv URL, alphaXiv URL, or arXiv ID.', + { + url: z.string().describe('arXiv/alphaXiv URL or arXiv ID (e.g. "2106.09685")'), + full_text: z.boolean().optional().describe('Get raw text instead of AI-generated report (default: false)'), + }, + async (args) => handleGet(args), +); + +server.tool( + 'alpha_ask', + 'Ask a question about a specific paper. Uses AI to analyze the PDF and answer.', + { + url: z.string().describe('arXiv/alphaXiv URL or arXiv ID'), + question: z.string().describe('Question about the paper'), + }, + async (args) => handleAsk(args), +); + +server.tool( + 'alpha_annotate', + 'Read, write, clear, or list local annotations on papers. Annotations persist across sessions and appear on future fetches.', + { + id: z.string().optional().describe('Paper ID (arXiv ID or URL). Required unless using list mode.'), + note: z.string().optional().describe('Annotation text to save. Omit to read existing.'), + clear: z.boolean().optional().describe('Remove annotation for this paper'), + list: z.boolean().optional().describe('List all annotations'), + }, + async (args) => handleAnnotate(args), +); + +server.tool( + 'alpha_code', + "Read files from a paper's GitHub repository. Use path '/' for repo overview.", + { + github_url: z.string().describe('GitHub repository URL'), + path: z.string().optional().describe("File or directory path (default: '/')"), + }, + async (args) => handleCode(args), +); + +process.on('uncaughtException', (err) => { + _stderr.write(`[alpha-mcp] Uncaught exception: ${err.message}\n`); +}); +process.on('unhandledRejection', (reason) => { + _stderr.write(`[alpha-mcp] Unhandled rejection: ${reason}\n`); +}); + +const transport = new StdioServerTransport(); +await server.connect(transport); +_stderr.write(`[alpha-mcp] Server started (v${pkg.version})\n`); diff --git a/cli/src/mcp/tools.js b/cli/src/mcp/tools.js new file mode 100644 index 0000000..74df372 --- /dev/null +++ b/cli/src/mcp/tools.js @@ -0,0 +1,94 @@ +import { + searchByEmbedding, + searchByKeyword, + agenticSearch, + getPaperContent, + answerPdfQuery, + readGithubRepo, +} from '../lib/alphaxiv.js'; +import { writeAnnotation, readAnnotation, clearAnnotation, listAnnotations } from '../lib/annotations.js'; +import { normalizePaperId, toArxivUrl } from '../lib/papers.js'; + +function textResult(data) { + return { + content: [{ type: 'text', text: typeof data === 'string' ? data : JSON.stringify(data, null, 2) }], + }; +} + +function errorResult(message) { + return { + content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }], + isError: true, + }; +} + +export async function handleSearch({ query, mode = 'semantic' }) { + try { + if (mode === 'keyword') return textResult(await searchByKeyword(query)); + if (mode === 'agentic') return textResult(await agenticSearch(query)); + return textResult(await searchByEmbedding(query)); + } catch (err) { + return errorResult(`Search failed: ${err.message}`); + } +} + +export async function handleGet({ url, full_text = false }) { + try { + const paperId = normalizePaperId(url); + const arxivUrl = toArxivUrl(url); + + const content = await getPaperContent(arxivUrl, { fullText: full_text }); + const annotation = readAnnotation(paperId); + + return textResult({ content, annotation }); + } catch (err) { + return errorResult(`Failed to fetch paper: ${err.message}`); + } +} + +export async function handleAsk({ url, question }) { + try { + const answer = await answerPdfQuery(toArxivUrl(url), question); + return textResult(answer); + } catch (err) { + return errorResult(`Ask failed: ${err.message}`); + } +} + +export async function handleAnnotate({ id, note, clear = false, list = false }) { + try { + if (list) { + const all = listAnnotations(); + return textResult({ annotations: all, total: all.length }); + } + + if (!id) return errorResult('Provide a paper ID or use list mode.'); + + const paperId = normalizePaperId(id); + + if (clear) { + const removed = clearAnnotation(paperId); + return textResult({ status: removed ? 'cleared' : 'not_found', id: paperId }); + } + + if (note) { + const saved = writeAnnotation(paperId, note); + return textResult({ status: 'saved', annotation: saved }); + } + + const existing = readAnnotation(paperId); + if (existing) return textResult({ annotation: existing }); + return textResult({ status: 'no_annotation', id: paperId }); + } catch (err) { + return errorResult(`Annotation failed: ${err.message}`); + } +} + +export async function handleCode({ github_url, path = '/' }) { + try { + const result = await readGithubRepo(github_url, path); + return textResult(result); + } catch (err) { + return errorResult(`Code read failed: ${err.message}`); + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ece10e4 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "alpha-hub", + "version": "0.1.0", + "private": true, + "type": "module" +}