Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
},
{
"name": "pathiel-research",
"source": "./services/research_mcp",
"source": {
"source": "github",
"repo": "Julian-dev28/pathiel",
"ref": "plugin-research"
},
"description": "The risk-gated research layer AI agents trade through: a free, read-only, keyless MCP server with 6 tools (research_brief, events, prediction_odds, fred_series, headlines, levels) for BRENTOIL, HYPE, BTC, ETH and SP500. Hyperliquid public candles, news/RSS, Polymarket/Kalshi odds, the scheduled-event calendar, and pathiel's own stored desk thesis. Never touches a key, an account or an order.",
"category": "finance",
"keywords": ["research", "mcp", "claude-code", "hyperliquid", "polymarket", "kalshi", "fred", "market-research", "oil", "crypto"]
Expand Down
272 changes: 236 additions & 36 deletions scripts/build_plugin_bundle.py

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions scripts/pathiel-research-mcp.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/env bash
# The pathiel research MCP server as a Claude Code plugin entry point.
#
# services/research_mcp/.claude-plugin/plugin.json runs this as
# "${CLAUDE_PLUGIN_ROOT}/../../scripts/pathiel-research-mcp.sh" (the plugin's
# source is the services/research_mcp/ subdirectory of this same monorepo; a
# relative-path plugin source resolves against the already-cloned repo, so
# that ../../ reaches the repo root on disk -- see the marketplace docs on
# relative-path plugin sources).
# .claude-plugin/plugin.json (bundle root; the checked-in copy lives at
# services/research_mcp/.claude-plugin/plugin.json and is relocated there by
# scripts/build_plugin_bundle.py --plugin research) runs this as
# "${CLAUDE_PLUGIN_ROOT}/scripts/pathiel-research-mcp.sh". Claude Code only
# copies a plugin's OWN source directory into its cache -- a relative-path
# marketplace entry scoped to services/research_mcp/ alone never carries
# scripts/, services/intel/, services/strategies/ or contracts/ along with
# it, so this file could not import the server at all (see
# code.claude.com/docs/en/plugins/loading#in-place-and-copied-plugins). The
# real install instead comes from the self-contained `plugin-research`
# branch, whose root holds this same scripts/ directory alongside every
# other file the server's import closure touches -- see
# .claude-plugin/marketplace.json's pathiel-research entry (a `github`
# source pinned to that branch) and build_plugin_bundle.py's own
# RESEARCH_* constants for the exact file list.
#
# Deliberately does NOT source scripts/_plugin_env.sh: that file resolves
# PATHIEL_HOME=~/.pathiel and loads the trading server's keys/config. This
Expand Down
6 changes: 3 additions & 3 deletions services/research_mcp/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "pathiel-research",
"displayName": "pathiel research",
"version": "0.1.0",
"version": "0.2.0",
"description": "The risk-gated research layer AI agents trade through: a free, read-only, keyless MCP server with 6 tools (research_brief, events, prediction_odds, fred_series, headlines, levels) for BRENTOIL, HYPE, BTC, ETH and SP500. Hyperliquid public candles, news/RSS, Polymarket/Kalshi odds, the scheduled-event calendar, and pathiel's own stored desk thesis. Never touches a key, an account or an order.",
"author": {
"name": "Julian Martinez",
"url": "https://github.com/Julian-dev28"
},
"homepage": "https://julian-dev28.github.io/pathiel/",
"documentationUrl": "https://github.com/Julian-dev28/pathiel/blob/main/services/research_mcp/README.md",
"privacyPolicyUrl": "https://github.com/Julian-dev28/pathiel/blob/main/docs/PRIVACY.md",
"privacyPolicyUrl": "https://julian-dev28.github.io/pathiel/privacy.html",
"supportUrl": "https://github.com/Julian-dev28/pathiel/issues",
"termsOfServiceUrl": "https://github.com/Julian-dev28/pathiel/blob/main/docs/TERMS.md",
"repository": "https://github.com/Julian-dev28/pathiel",
Expand All @@ -18,7 +18,7 @@
"mcpServers": {
"pathiel-research": {
"command": "bash",
"args": ["${CLAUDE_PLUGIN_ROOT}/../../scripts/pathiel-research-mcp.sh"]
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/pathiel-research-mcp.sh"]
}
}
}
2 changes: 1 addition & 1 deletion services/research_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# cert-bundle patch, PATHIA_*/PATHIEL_* environment mirroring) that this
# server has no reason to carry, and importing it would be one more thing
# tests/test_no_trading_imports.py's reviewer has to re-check stays clean.
SERVER_VERSION = "0.1.0"
SERVER_VERSION = "0.2.0"

SERVER_INSTRUCTIONS = (
"pathiel research: the risk-gated research layer AI agents trade through. Read-only and "
Expand Down
12 changes: 12 additions & 0 deletions services/research_mcp/tests/test_server_version_matches_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""The version the research server reports in initialize must match its
plugin.json (2026-11-22: plugin.json said 0.2.0, the server still said 0.1.0)."""
import json
import pathlib

from services.research_mcp import server

PLUGIN_JSON = pathlib.Path(__file__).resolve().parents[1] / ".claude-plugin" / "plugin.json"


def test_server_version_matches_plugin_json():
assert server.SERVER_VERSION == json.loads(PLUGIN_JSON.read_text())["version"]
125 changes: 125 additions & 0 deletions tests/test_eval_plugin_bundle_research.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""Eval: would the plugin directory's review of the RESEARCH bundle come
back clean? Mirrors tests/test_eval_plugin_bundle.py for the research
server (scripts/build_plugin_bundle.py --plugin research).

Rows (every one must meet its target):

bundle files / repo files < 1/3
paths that escape ${CLAUDE_PLUGIN_ROOT} 0
install commands in shipped Markdown 0 (docker run/build, git clone)
dead relative links in shipped Markdown 0
banned trading/credential files shipped 0
forbidden module loaded, fresh import 0
MCP server declarations, named interpreter 1, bash
server tools, bundle vs checkout equal, 6
claude plugin validate --profile directory 0 findings, 0 warnings (--strict)

The validator row needs the claude CLI; without it the row says "not run"
in its got column and does not fail (CI has no claude).

.venv/bin/python -m pytest -q -s tests/test_eval_plugin_bundle_research.py
"""
from __future__ import annotations

import importlib.util
import json
import re
import shutil
import subprocess
from pathlib import Path
from typing import List

ROOT = Path(__file__).resolve().parents[1]
HERE = Path(__file__).resolve().parent

_spec = importlib.util.spec_from_file_location("_eval_plugin_bundle_research_checks",
HERE / "test_plugin_bundle_research.py")
T = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(T)
B = T.B


def _validate(bundle: Path) -> dict:
proc = subprocess.run(["claude", "plugin", "validate", "--profile", "directory", "--strict",
"--json", str(bundle)], capture_output=True, text=True, timeout=120)
report = json.loads(proc.stdout)
parts = [report["manifest"], *report.get("contents", [])]
return {"exit": proc.returncode,
"errors": sum(len(p["errors"]) for p in parts),
"warnings": sum(len(p["warnings"]) for p in parts),
"findings": len(report["directory"]["findings"]) + len(report["directory"]["undecided"])}


def run(bundle: Path, public_env) -> List[dict]:
def row(check: str, got, want, ok: bool) -> dict:
return {"check": check, "got": got, "want": want, "ok": bool(ok)}

files = B.ls_tree(B.INDEX)
paths = B.research_build(B.INDEX, bundle)
rows: List[dict] = []
rows.append(row("bundle files / repo files", f"{len(paths)}/{len(files)}", "< 1/3",
len(paths) * 3 < len(files)))

escapees = []
import posixpath
for p in paths:
dest = B._research_dest(p)
if dest.startswith("..") or dest.startswith("/") or posixpath.normpath(dest) != dest:
escapees.append(dest)
rows.append(row("paths that escape ${CLAUDE_PLUGIN_ROOT}", len(escapees), 0, not escapees))

shipped = set(paths) | {B._research_dest(p) for p in paths}
readme = (bundle / "README.md").read_text(encoding="utf-8")
installs = sum(readme.count(n) for n in ("docker run", "docker build", "git clone"))
dead = sum(1 for m in re.finditer(r"\]\((?!https?://|mailto:|#)([^)\s#]+)", readme)
if m.group(1) not in shipped)
rows.append(row("install commands in shipped Markdown", installs, 0, installs == 0))
rows.append(row("dead relative links in shipped Markdown", dead, 0, dead == 0))

banned_prefixes = ("pathiel/agents/bracket.py", "pathiel/agents/executor.py",
"pathiel/client/exchange.py", "services/strategies/next_trade.py",
"services/accounts/")
banned = [p for p in paths if any(p == b or p.startswith(b) for b in banned_prefixes)]
rows.append(row("banned trading/credential files shipped", len(banned), 0, not banned))

import subprocess as sp
import sys as _sys
code = ("import sys, json\n"
f"sys.path.insert(0, {str(bundle)!r})\n"
"from services.research_mcp import server\n"
f"forbidden = {sorted(B.RESEARCH_FORBIDDEN_MODULES)!r}\n"
"hits = [m for m in sys.modules if any(m == f or m.startswith(f + '.') for f in forbidden)]\n"
"print(json.dumps(hits))\n")
proc = sp.run([_sys.executable, "-c", code], capture_output=True, text=True, timeout=30,
cwd=str(bundle))
hits = json.loads(proc.stdout.strip()) if proc.returncode == 0 else ["<import failed>"]
rows.append(row("forbidden module loaded, fresh import", hits, [], not hits))

plugin = json.loads((bundle / ".claude-plugin" / "plugin.json").read_text())
servers = plugin.get("mcpServers", {})
decl = len(servers) + int((bundle / ".mcp.json").exists())
cmd = servers.get("pathiel-research", {}).get("command")
rows.append(row("MCP server declarations, interpreter", f"{decl}, {cmd}", "1, bash",
decl == 1 and cmd == "bash"))

from_bundle = T._tools(bundle / "scripts" / "pathiel-research-mcp.py", public_env)
from_checkout = T._tools(ROOT / "scripts" / "pathiel-research-mcp.py", public_env)
rows.append(row("server tools, bundle vs checkout", f"{len(from_bundle)} vs {len(from_checkout)}",
"equal, 6", from_bundle == from_checkout and len(from_bundle) == 6))

if shutil.which("claude"):
v = _validate(bundle)
rows.append(row("claude plugin validate --profile directory --strict",
f"exit {v['exit']}, {v['errors']} errors, {v['warnings']} warnings, "
f"{v['findings']} findings", "exit 0, all 0",
v["exit"] == 0 and not (v["errors"] or v["warnings"] or v["findings"])))
else:
rows.append(row("claude plugin validate --profile directory --strict",
"not run (no claude CLI on PATH)", "exit 0, all 0", True))
return rows


def test_eval_plugin_bundle_research_meets_every_target(tmp_path, public_env, scorecard):
card = scorecard("plugin_bundle_research", run(tmp_path / "pathiel-research", public_env))
failed = [r for r in card["rows"] if not r["ok"]]
assert not failed, f"research plugin bundle eval: {card['passed']}/{card['total']}; failed: {failed}"
13 changes: 13 additions & 0 deletions tests/test_listing_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,16 @@ def test_listing_urls_point_at_files_that_exist_and_terms_say_what_matters(copy_
"never withdraw", "charges no fee", "opt-in"):
assert must in terms, must
assert copy_lint.style_hits(terms) == [] and copy_lint.claim_hits(terms) == []


def test_research_plugin_privacy_url_matches_the_trading_one():
"""services/research_mcp/.claude-plugin/plugin.json shares the same
hosted privacy page (site/privacy.html has its own "The research
server" section) instead of the old docs/PRIVACY.md repo-blob link,
which described only the trading server's keys."""
research = _json(ROOT / "services" / "research_mcp" / ".claude-plugin" / "plugin.json")
plugin = _json(PLUGIN_JSON)
assert research["privacyPolicyUrl"] == plugin["privacyPolicyUrl"] == \
"https://julian-dev28.github.io/pathiel/privacy.html"
privacy_text = (ROOT / "site" / "privacy.html").read_text(encoding="utf-8")
assert "pathiel-research" in privacy_text and "research server" in privacy_text.lower()
22 changes: 19 additions & 3 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ def test_the_plugin_and_marketplace_names_agree_and_the_version_is_the_packages(
server, services/research_mcp/ — its own deploy unit, see
tests/test_deploy_config.py::test_dockerfile_does_not_bundle_research_mcp).
Only the trading plugin's version tracks pathiel/__init__.py; the
research plugin is a genuinely separate product with its own version."""
research plugin is a genuinely separate product with its own version.

pathiel-research's entry is a `github` source pinned to the
`plugin-research` branch (scripts/build_plugin_bundle.py --plugin
research), not a relative path: Claude Code only copies a relative-path
entry's OWN directory into the cache, so "./services/research_mcp" ships
none of scripts/, services/intel/, services/strategies/ or contracts/ on
a real (non-local) marketplace install and the server cannot start (see
code.claude.com/docs/en/plugins/loading#in-place-and-copied-plugins).
The checked-in services/research_mcp/.claude-plugin/plugin.json is bundle
SOURCE input only now (relocated to the branch's own .claude-plugin/
plugin.json byte for byte); see tests/test_plugin_bundle_research.py."""
from pathiel import __version__
m, mk = _manifest(), _marketplace()
assert m["name"] == "pathiel"
Expand All @@ -63,11 +74,16 @@ def test_the_plugin_and_marketplace_names_agree_and_the_version_is_the_packages(
assert m["author"]["name"] and mk["owner"]["name"]

research_source = by_name["pathiel-research"]["source"]
assert research_source == "./services/research_mcp"
research_manifest = json.loads((ROOT / research_source.removeprefix("./") /
assert research_source == {"source": "github", "repo": "Julian-dev28/pathiel",
"ref": "plugin-research"}
research_manifest = json.loads((ROOT / "services" / "research_mcp" /
".claude-plugin" / "plugin.json").read_text())
assert research_manifest["name"] == "pathiel-research" == by_name["pathiel-research"]["name"]
assert re.fullmatch(r"\d+\.\d+\.\d+", research_manifest["version"])
assert research_manifest["mcpServers"]["pathiel-research"]["args"] == \
["${CLAUDE_PLUGIN_ROOT}/scripts/pathiel-research-mcp.sh"], \
"the args must stay inside ${CLAUDE_PLUGIN_ROOT}: see the bug this plugin shipped with " \
"(../../scripts/...), fixed by building a self-contained bundle instead"
assert research_manifest["author"]["name"]


Expand Down
Loading