From e8fcfbcf9fcdc282f88f67f10a2230ed2c69e453 Mon Sep 17 00:00:00 2001 From: taisuii <93462725+taisuii@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:40:14 +0800 Subject: [PATCH] Package independently installable DecryptHub MCP gateway component --- .github/workflows/component.yml | 26 +++++++++++++++++ README.en.md | 6 ++++ README.md | 6 ++++ scripts/build_component.py | 52 +++++++++++++++++++++++++++++++++ tests/test_component_build.py | 17 +++++++++++ tests/test_config.py | 5 +++- tests/test_settings.py | 6 +++- 7 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/component.yml create mode 100644 scripts/build_component.py create mode 100644 tests/test_component_build.py diff --git a/.github/workflows/component.yml b/.github/workflows/component.yml new file mode 100644 index 0000000..ba63cd9 --- /dev/null +++ b/.github/workflows/component.yml @@ -0,0 +1,26 @@ +name: Desktop MCP component +on: + push: + branches: [main] + pull_request: + workflow_dispatch: +permissions: + contents: read +jobs: + verify: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - run: python -m pip install -e ".[dev]" + - run: python -m pytest -q + - run: python scripts/build_component.py + - uses: actions/upload-artifact@v4 + with: + name: idh-component-${{ runner.os }} + path: dist/idh-*.zip* diff --git a/README.en.md b/README.en.md index 060c12a..d342e67 100755 --- a/README.en.md +++ b/README.en.md @@ -248,3 +248,9 @@ Search **DecryptHub** in WeChat, or scan the QR below. - Telegram: https://t.me/decrypthubteam - X: https://x.com/decrypthub_ + +## DecryptHub desktop plugin + +Install the official gateway from DecryptHub → Plugins, then configure your device service address. The component contains the PC CLI and a standard-library launcher and requires Python 3.10+. Device plugins and Host services are deployed separately. + +Maintainers: run `python scripts/build_component.py` to build `dist/idh--any.zip`, including an API 1 manifest, source revision and per-file SHA-256 checksums. GitHub Releases tags `decrypthub-v` distribute desktop components independently of PyPI releases. diff --git a/README.md b/README.md index bf5d21f..c526760 100755 --- a/README.md +++ b/README.md @@ -250,3 +250,9 @@ MCP 网关暴露 `idh_list_skills` 和 `idh_get_skill`;提示词与 skills 的 - Telegram:https://t.me/decrypthubteam - X:https://x.com/decrypthub_ + +## DecryptHub 桌面插件 + +在 DecryptHub 的「插件」入口安装官方网关,配置设备服务地址后即可启用 MCP。安装包只包含电脑端 CLI 和标准库启动器,要求 Python 3.10+;设备插件及 Host 服务仍按各自项目说明准备。 + +维护者构建组件:`python scripts/build_component.py`。输出 `dist/idh--any.zip`,包含 API 1 清单、源代码版本及逐文件 SHA-256,可独立通过 GitHub Releases 更新。`decrypthub-v` 标签用于桌面组件分发,与 PyPI 发版独立。 diff --git a/scripts/build_component.py b/scripts/build_component.py new file mode 100644 index 0000000..7be2476 --- /dev/null +++ b/scripts/build_component.py @@ -0,0 +1,52 @@ +import argparse +import hashlib +import json +import os +import pathlib +import re +import subprocess +import zipfile + +root = pathlib.Path(__file__).resolve().parents[1] +parser = argparse.ArgumentParser(description='Build an independently installable DecryptHub MCP gateway component.') +parser.add_argument('--output', default=str(root / 'dist')) +args = parser.parse_args() +plugin = 'idh' if (root / 'src' / 'idh').is_dir() else 'adh' +metadata = (root / 'pyproject.toml').read_text(encoding='utf-8') +version = re.search(r'^version\s*=\s*"([^"]+)"', metadata, re.M).group(1) +if not re.fullmatch(r'\d+\.\d+\.\d+(?:-[\w.-]+)?', version): + raise SystemExit('Unsupported component version') +repository = f'decrypthub/{plugin}-cli' +commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip() +launcher = ('import pathlib, runpy, sys\n' + 'sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent / "src"))\n' + + ('if "--no-auto-update" not in sys.argv: sys.argv.insert(1, "--no-auto-update")\n' if plugin == 'idh' else '') + + f'runpy.run_module("{plugin}", run_name="__main__")\n').encode() +files = [] +contents = {'launch.py': launcher} +for name in ['src', 'LICENSE', 'README.md', 'pyproject.toml']: + source = root / name + candidates = sorted(source.rglob('*')) if source.is_dir() else [source] + for item in candidates: + if item.is_symlink(): + raise SystemExit(f'Refusing linked source: {item}') + if not item.is_file() or '__pycache__' in item.parts or item.suffix in ['.pyc', '.pyo']: + continue + contents[item.relative_to(root).as_posix()] = item.read_bytes() +for name, data in sorted(contents.items()): + files.append({'path': name, 'size': len(data), 'sha256': hashlib.sha256(data).hexdigest()}) +manifest = {'manifestVersion': 1, 'id': plugin, 'version': version, 'apiVersion': 1, + 'runtime': 'python', 'python': '>=3.10', 'entrypoint': 'launch.py', + 'platform': 'any', 'arch': 'any', 'source': {'repository': repository, 'commit': commit}, 'files': files} +output = pathlib.Path(args.output).resolve() +output.mkdir(parents=True, exist_ok=True) +archive = output / f'{plugin}-{version}-any.zip' +with zipfile.ZipFile(archive, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as bundle: + bundle.writestr('component.json', json.dumps(manifest, indent=2) + '\n') + for name, data in sorted(contents.items()): + info = zipfile.ZipInfo(name, (2026, 1, 1, 0, 0, 0)) + info.external_attr = 0o100644 << 16 + bundle.writestr(info, data, compress_type=zipfile.ZIP_DEFLATED, compresslevel=9) +digest = hashlib.sha256(archive.read_bytes()).hexdigest() +(archive.with_suffix('.zip.sha256')).write_text(f'{digest} {archive.name}\n', encoding='utf-8') +print(json.dumps({'id': plugin, 'version': version, 'path': str(archive), 'sha256': digest, 'commit': commit})) diff --git a/tests/test_component_build.py b/tests/test_component_build.py new file mode 100644 index 0000000..bfc323a --- /dev/null +++ b/tests/test_component_build.py @@ -0,0 +1,17 @@ +import hashlib,json,pathlib,subprocess,sys,tempfile,unittest,zipfile +class ComponentBuildTest(unittest.TestCase): + def test_package_and_standard_library_launcher(self): + root=pathlib.Path(__file__).resolve().parents[1] + with tempfile.TemporaryDirectory(prefix='decrypthub-component-test-') as directory: + subprocess.run([sys.executable,str(root/'scripts/build_component.py'),'--output',directory],check=True,capture_output=True) + archive=next(pathlib.Path(directory).glob('*.zip')) + with zipfile.ZipFile(archive) as bundle: + manifest=json.loads(bundle.read('component.json')) + self.assertEqual(manifest['runtime'],'python');self.assertEqual(manifest['platform'],'any') + self.assertEqual(set(bundle.namelist()),{'component.json'}|{f['path'] for f in manifest['files']}) + for file in manifest['files']: + data=bundle.read(file['path']);self.assertEqual(len(data),file['size']);self.assertEqual(hashlib.sha256(data).hexdigest(),file['sha256']) + bundle.extractall(pathlib.Path(directory)/'installed') + result=subprocess.run([sys.executable,str(pathlib.Path(directory)/'installed/launch.py'),'--version'],check=True,capture_output=True,text=True) + self.assertIn(manifest['version'],result.stdout) +if __name__=='__main__':unittest.main() diff --git a/tests/test_config.py b/tests/test_config.py index 5c933d6..425c163 100755 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import json import pytest @@ -18,7 +19,9 @@ def test_saved_endpoints_round_trip_and_deduplicate(tmp_path) -> None: "http://192.168.100.65:8088/api/mcp" ] assert json.loads(path.read_text())["version"] == 1 - assert path.stat().st_mode & 0o777 == 0o600 + # Windows does not represent POSIX permission bits; its user ACL is separate. + if os.name != "nt": + assert path.stat().st_mode & 0o777 == 0o600 def test_remove_and_clear_saved_endpoints(tmp_path) -> None: diff --git a/tests/test_settings.py b/tests/test_settings.py index 49824b1..d77b618 100755 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,7 @@ from __future__ import annotations +import os + from idh.settings import load_settings, save_settings @@ -13,7 +15,9 @@ def test_settings_defaults_and_round_trip(tmp_path) -> None: loaded = load_settings(path) assert loaded["auto_update"] is False assert loaded["update_interval"] == 60 - assert path.stat().st_mode & 0o777 == 0o600 + # Windows does not represent POSIX permission bits; its user ACL is separate. + if os.name != "nt": + assert path.stat().st_mode & 0o777 == 0o600 def test_settings_env_override(monkeypatch, tmp_path) -> None: