From 51bba46944f28c63967d05183da6b91d6a4a59d2 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 | 51 +++++++++++++++++++++++++++++++++ tests/test_component_build.py | 17 +++++++++++ 5 files changed, 106 insertions(+) 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..b464772 --- /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: adh-component-${{ runner.os }} + path: dist/adh-*.zip* diff --git a/README.en.md b/README.en.md index 00fa2ae..202d9e2 100644 --- a/README.en.md +++ b/README.en.md @@ -87,3 +87,9 @@ Keep the upload token in `~/.config/pypi/token` on the release machine. Do not c ## License [MIT](./LICENSE) + +## 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/adh--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 0122caa..5ce9c73 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,9 @@ python -m twine upload --repository pypi dist/android_decrypt_hub-* ## 协议 [MIT](./LICENSE) + +## DecryptHub 桌面插件 + +在 DecryptHub 的「插件」入口安装官方网关,配置设备服务地址后即可启用 MCP。安装包只包含电脑端 CLI 和标准库启动器,要求 Python 3.10+;设备插件及 Host 服务仍按各自项目说明准备。 + +维护者构建组件:`python scripts/build_component.py`。输出 `dist/adh--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..22f771f --- /dev/null +++ b/scripts/build_component.py @@ -0,0 +1,51 @@ +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' + 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()