android-decrypt-hub 0.1.2__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {android_decrypt_hub-0.1.2/src/android_decrypt_hub.egg-info → android_decrypt_hub-0.2.0}/PKG-INFO +47 -5
- android_decrypt_hub-0.2.0/README.md +177 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/pyproject.toml +2 -1
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/__init__.py +1 -1
- android_decrypt_hub-0.2.0/src/adh/cli.py +349 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/endpoint.py +1 -1
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/http_mcp.py +15 -2
- android_decrypt_hub-0.2.0/src/adh/status.py +32 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0/src/android_decrypt_hub.egg-info}/PKG-INFO +47 -5
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/android_decrypt_hub.egg-info/SOURCES.txt +5 -1
- android_decrypt_hub-0.2.0/tests/test_agent_cli.py +71 -0
- android_decrypt_hub-0.2.0/tests/test_component_build.py +17 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/tests/test_endpoint.py +3 -3
- android_decrypt_hub-0.2.0/tests/test_operations.py +112 -0
- android_decrypt_hub-0.1.2/README.md +0 -135
- android_decrypt_hub-0.1.2/src/adh/cli.py +0 -194
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/LICENSE +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/MANIFEST.in +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/setup.cfg +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/__main__.py +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/config.py +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/adh/stdio.py +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/android_decrypt_hub.egg-info/dependency_links.txt +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/android_decrypt_hub.egg-info/entry_points.txt +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/android_decrypt_hub.egg-info/requires.txt +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/src/android_decrypt_hub.egg-info/top_level.txt +0 -0
- {android_decrypt_hub-0.1.2 → android_decrypt_hub-0.2.0}/tests/test_config.py +0 -0
{android_decrypt_hub-0.1.2/src/android_decrypt_hub.egg-info → android_decrypt_hub-0.2.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: android-decrypt-hub
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Connect to Host ADH Daemon and bridge HTTP MCP to stdio
|
|
5
5
|
Author: DecryptHub
|
|
6
6
|
License: MIT
|
|
@@ -40,9 +40,29 @@ adh connect 127.0.0.1:8088
|
|
|
40
40
|
adh devices
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
源码在 [decrypthub/adh-cli](https://github.com/decrypthub/adh-cli),PyPI 包名是 [android-decrypt-hub](https://pypi.org/project/android-decrypt-hub/)。产品仓库是 [AndroidDecryptHub](https://github.com/decrypthub/AndroidDecryptHub)。当前版本 **0.
|
|
43
|
+
源码在 [decrypthub/adh-cli](https://github.com/decrypthub/adh-cli),PyPI 包名是 [android-decrypt-hub](https://pypi.org/project/android-decrypt-hub/)。产品仓库是 [AndroidDecryptHub](https://github.com/decrypthub/AndroidDecryptHub)。当前版本 **0.2.0**。
|
|
44
44
|
|
|
45
|
-
Host ADH Daemon
|
|
45
|
+
Host ADH Daemon 的完整连接认证与 TLS 尚未实现,P1 的 operator 凭据只协调人类控制权。只在可信局域网里使用,不要暴露到公网。不要把 HTTP `/mcp` 直接配进 MCP 客户端。
|
|
46
|
+
|
|
47
|
+
## P1 持久任务与接管(源码待发布)
|
|
48
|
+
|
|
49
|
+
本分支与 AndroidDecryptHub 的 P1 Host 配套,尚未发布到 PyPI;不会升级或重启已有 Host。新 Host 的写入要求 `_operation` 中的 expectedRevision/controlEpoch/hostEpoch,旧无版本写调用会返回 CONTROL_REQUIRED。普通读取与 stdio 透传仍兼容;AI 需要明确观察版本后提交。统一执行层与状态定义见产品仓库 `docs/P1_OPERATIONS.md`。
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
adh tasks create --title "请求分析" --endpoint 127.0.0.1:18088 --json
|
|
53
|
+
adh run TOOL --arguments JSON --task-id TASK_ID --idempotency-key INTENT_ID --endpoint 127.0.0.1:18088 --json
|
|
54
|
+
adh tasks get OPERATION_ID --include-result --endpoint 127.0.0.1:18088 --json
|
|
55
|
+
adh tasks cancel OPERATION_ID --endpoint 127.0.0.1:18088
|
|
56
|
+
adh tasks cancel --task-id TASK_ID --endpoint 127.0.0.1:18088
|
|
57
|
+
adh tasks list --limit 50 --offset 0 --endpoint 127.0.0.1:18088
|
|
58
|
+
adh control snapshot --session SESSION --endpoint 127.0.0.1:18088
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`run` 观察一次状态并异步提交,返回 queued/running 只代表已接受;通过 `tasks get` 检查真实结果。AI 已有旧版本时用 `adh call TOOL --arguments JSON --operation METADATA_JSON` 保留原版本;发生冲突必须重新观察并规划,CLI 不替换版本重试。同一意图保持同一个 idempotency key。
|
|
62
|
+
|
|
63
|
+
人类在当前终端显式配置 ADH_OPERATOR_TOKEN 后,用 `adh control takeover|release --session SESSION --operator` 接管/释放;也可加 `--revision N --epoch N --host-epoch N` 使用已观察版本。完整 action 包括 snapshot/takeover/release/resolve/hold。`resolve --acknowledge --operator` 仅在检查未知副作用后使用,不代表停止或回滚目标。
|
|
64
|
+
|
|
65
|
+
默认 CLI 和 stdio AI 代理忽略继承的 operator 密钥;只有显式 `--operator` 才发送。任务可 pause/resume/complete;cancel 单个 operation 不取消整项 task。派发后取消仍可能执行成功,反馈 cancel_requested 或 succeeded + cancelRequested;派发后超时/断连为 unknown,保留晚到证据,不自动重放。HTTP 传输超时本身不能证明 Host 或目标已停止,使用持久 id/key 查询;不要直接重发旧写入。
|
|
46
66
|
|
|
47
67
|
## 安装
|
|
48
68
|
|
|
@@ -59,7 +79,7 @@ pipx upgrade android-decrypt-hub
|
|
|
59
79
|
|
|
60
80
|
## 连接
|
|
61
81
|
|
|
62
|
-
先在电脑上启动 Host ADH Daemon
|
|
82
|
+
先在电脑上启动 Host ADH Daemon,再保存它的地址。Daemon 和 CLI 的默认 HTTP 端口均为 `8088`。已保存或显式指定的其他端口继续有效:
|
|
63
83
|
|
|
64
84
|
```bash
|
|
65
85
|
adh connect 127.0.0.1:8088
|
|
@@ -124,7 +144,7 @@ adh call <tool_name> --endpoint http://127.0.0.1:8088
|
|
|
124
144
|
|
|
125
145
|
| 命令 | 作用 |
|
|
126
146
|
| --- | --- |
|
|
127
|
-
| `adh connect [地址]` | 探测并保存 Host ADH Daemon。默认 `127.0.0.1:
|
|
147
|
+
| `adh connect [地址]` | 探测并保存 Host ADH Daemon。默认 `127.0.0.1:8088` |
|
|
128
148
|
| `adh disconnect [地址]` | 移除一个已保存地址;`--all` 清空 |
|
|
129
149
|
| `adh devices` | 列出已保存地址,并显示在线状态 |
|
|
130
150
|
| `adh mcp` | 把已保存 Daemon 的 `POST /mcp` 转成 stdio MCP |
|
|
@@ -161,3 +181,25 @@ python -m twine upload --repository pypi dist/android_decrypt_hub-<version>*
|
|
|
161
181
|
## 协议
|
|
162
182
|
|
|
163
183
|
[MIT](./LICENSE)
|
|
184
|
+
|
|
185
|
+
## DecryptHub 桌面插件
|
|
186
|
+
|
|
187
|
+
在 DecryptHub 的「插件」入口安装官方网关,配置设备服务地址后即可启用 MCP。安装包只包含电脑端 CLI 和标准库启动器,要求 Python 3.10+;设备插件及 Host 服务仍按各自项目说明准备。
|
|
188
|
+
|
|
189
|
+
维护者构建组件:`python scripts/build_component.py`。输出 `dist/adh-<version>-any.zip`,包含 API 1 清单、源代码版本及逐文件 SHA-256,可独立通过 GitHub Releases 更新。`decrypthub-v<version>` 标签用于桌面组件分发,与 PyPI 发版独立。
|
|
190
|
+
|
|
191
|
+
## 桌面 Agent 与状态查询
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
adh status --json --endpoint http://127.0.0.1:8088
|
|
195
|
+
adh tools --json --endpoint http://127.0.0.1:8088
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`status --json` 返回带 `schemaVersion: 1` 和 `checkedAt` 的只读快照,分别列出 `connections` 的服务在线事实及 `targets` 的应用/PID/目标标识;离线地址不会冒充在线目标。状态查询不保存地址、不注入、不启停应用,也不自动升级 CLI。`tools --json` 返回当前目标的真实 MCP 工具说明和参数 schema。先查询状态,再选择本次返回的唯一目标,最后通过现有 `call` 或持久 MCP 连接执行分析;多个候选必须让用户选择。
|
|
199
|
+
|
|
200
|
+
ADH 省略端口时默认连接 8088;`devices --endpoint` 支持临时探测,`call` 收到 MCP 错误或 `isError` 时返回非零退出码。
|
|
201
|
+
|
|
202
|
+
## 开发验证
|
|
203
|
+
|
|
204
|
+
在源码目录运行 `python -m pytest`。测试配置优先导入本仓 `src`,避免误测电脑上已安装的旧版 `adh`。
|
|
205
|
+
发布前另运行 `python -m build` 与 `python -m twine check dist/*`,并在隔离环境验证构建后的 wheel。
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# adh
|
|
2
|
+
|
|
3
|
+
**中文** | [English](README.en.md)
|
|
4
|
+
|
|
5
|
+
`adh` 是 AndroidDecryptHub 的本机连接与 MCP 网关。它保存 Host ADH Daemon 的地址,并把 `POST /mcp` 转成 Cursor / Claude Desktop 可用的 stdio MCP。
|
|
6
|
+
|
|
7
|
+
运行时只使用 Python 标准库,要求 Python 3.10 或更高版本。
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install android-decrypt-hub
|
|
11
|
+
adh connect 127.0.0.1:8088
|
|
12
|
+
adh devices
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
源码在 [decrypthub/adh-cli](https://github.com/decrypthub/adh-cli),PyPI 包名是 [android-decrypt-hub](https://pypi.org/project/android-decrypt-hub/)。产品仓库是 [AndroidDecryptHub](https://github.com/decrypthub/AndroidDecryptHub)。当前版本 **0.2.0**。
|
|
16
|
+
|
|
17
|
+
Host ADH Daemon 的完整连接认证与 TLS 尚未实现,P1 的 operator 凭据只协调人类控制权。只在可信局域网里使用,不要暴露到公网。不要把 HTTP `/mcp` 直接配进 MCP 客户端。
|
|
18
|
+
|
|
19
|
+
## P1 持久任务与接管(源码待发布)
|
|
20
|
+
|
|
21
|
+
本分支与 AndroidDecryptHub 的 P1 Host 配套,尚未发布到 PyPI;不会升级或重启已有 Host。新 Host 的写入要求 `_operation` 中的 expectedRevision/controlEpoch/hostEpoch,旧无版本写调用会返回 CONTROL_REQUIRED。普通读取与 stdio 透传仍兼容;AI 需要明确观察版本后提交。统一执行层与状态定义见产品仓库 `docs/P1_OPERATIONS.md`。
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
adh tasks create --title "请求分析" --endpoint 127.0.0.1:18088 --json
|
|
25
|
+
adh run TOOL --arguments JSON --task-id TASK_ID --idempotency-key INTENT_ID --endpoint 127.0.0.1:18088 --json
|
|
26
|
+
adh tasks get OPERATION_ID --include-result --endpoint 127.0.0.1:18088 --json
|
|
27
|
+
adh tasks cancel OPERATION_ID --endpoint 127.0.0.1:18088
|
|
28
|
+
adh tasks cancel --task-id TASK_ID --endpoint 127.0.0.1:18088
|
|
29
|
+
adh tasks list --limit 50 --offset 0 --endpoint 127.0.0.1:18088
|
|
30
|
+
adh control snapshot --session SESSION --endpoint 127.0.0.1:18088
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`run` 观察一次状态并异步提交,返回 queued/running 只代表已接受;通过 `tasks get` 检查真实结果。AI 已有旧版本时用 `adh call TOOL --arguments JSON --operation METADATA_JSON` 保留原版本;发生冲突必须重新观察并规划,CLI 不替换版本重试。同一意图保持同一个 idempotency key。
|
|
34
|
+
|
|
35
|
+
人类在当前终端显式配置 ADH_OPERATOR_TOKEN 后,用 `adh control takeover|release --session SESSION --operator` 接管/释放;也可加 `--revision N --epoch N --host-epoch N` 使用已观察版本。完整 action 包括 snapshot/takeover/release/resolve/hold。`resolve --acknowledge --operator` 仅在检查未知副作用后使用,不代表停止或回滚目标。
|
|
36
|
+
|
|
37
|
+
默认 CLI 和 stdio AI 代理忽略继承的 operator 密钥;只有显式 `--operator` 才发送。任务可 pause/resume/complete;cancel 单个 operation 不取消整项 task。派发后取消仍可能执行成功,反馈 cancel_requested 或 succeeded + cancelRequested;派发后超时/断连为 unknown,保留晚到证据,不自动重放。HTTP 传输超时本身不能证明 Host 或目标已停止,使用持久 id/key 查询;不要直接重发旧写入。
|
|
38
|
+
|
|
39
|
+
## 安装
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python -m pip install -U android-decrypt-hub
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
也可以用 pipx:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pipx install android-decrypt-hub
|
|
49
|
+
pipx upgrade android-decrypt-hub
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 连接
|
|
53
|
+
|
|
54
|
+
先在电脑上启动 Host ADH Daemon,再保存它的地址。Daemon 和 CLI 的默认 HTTP 端口均为 `8088`。已保存或显式指定的其他端口继续有效:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
adh connect 127.0.0.1:8088
|
|
58
|
+
adh connect --json
|
|
59
|
+
adh devices
|
|
60
|
+
adh devices --json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`connect` 会先请求 `/health`。在线时打印 `online`,并写入配置。Daemon 暂时离线但仍要保存地址时:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
adh connect 127.0.0.1:8088 --force
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
连接写入 `~/.config/adh/connections.json`。可用 `ADH_CONFIG_PATH` 改这个文件的位置。查看或移除:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
adh disconnect 127.0.0.1:8088
|
|
73
|
+
adh disconnect --all
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
只保存了一个地址时,后面的 `devices`、`call`、`mcp` 会自动用它。保存了多个地址时,给单次命令加上 `--endpoint`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
adh devices --endpoint http://127.0.0.1:8088
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## MCP
|
|
83
|
+
|
|
84
|
+
Cursor / Claude Desktop 只配置这一次:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"mcpServers": {
|
|
89
|
+
"adh": {
|
|
90
|
+
"command": "adh",
|
|
91
|
+
"args": ["mcp"]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
多个已保存地址时,在参数里指定本次使用的 Daemon:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
adh mcp --endpoint http://127.0.0.1:8088
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`adh mcp` 启动时会再探一次 `/health`,目标不在线就直接退出。日志写到 stderr,stdout 只留给逐行 JSON-RPC。
|
|
104
|
+
|
|
105
|
+
## 调用单个工具
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
adh call <tool_name>
|
|
109
|
+
adh call <tool_name> --arguments '{"limit":3}' --json
|
|
110
|
+
adh call <tool_name> --endpoint http://127.0.0.1:8088
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`--arguments` 必须是一个 JSON 对象。
|
|
114
|
+
|
|
115
|
+
## 命令
|
|
116
|
+
|
|
117
|
+
| 命令 | 作用 |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `adh connect [地址]` | 探测并保存 Host ADH Daemon。默认 `127.0.0.1:8088` |
|
|
120
|
+
| `adh disconnect [地址]` | 移除一个已保存地址;`--all` 清空 |
|
|
121
|
+
| `adh devices` | 列出已保存地址,并显示在线状态 |
|
|
122
|
+
| `adh mcp` | 把已保存 Daemon 的 `POST /mcp` 转成 stdio MCP |
|
|
123
|
+
| `adh call <工具名>` | 调用一个 Host MCP 工具 |
|
|
124
|
+
| `adh --version` | 打印版本 |
|
|
125
|
+
|
|
126
|
+
## 开发
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
python -m pip install -e ".[dev]"
|
|
130
|
+
python -m pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 发版
|
|
134
|
+
|
|
135
|
+
源码版本和 PyPI 版本一起更新。`pyproject.toml` 的 `version` 与 `src/adh/__init__.py` 的 `__version__` 必须相同。PyPI 不能覆盖已发布的版本,所以每次发布都要升版本号。
|
|
136
|
+
|
|
137
|
+
用户能看到的行为或文案有变化时,同时改 `README.md` 和 `README.en.md`。
|
|
138
|
+
|
|
139
|
+
| 变更 | 升法 |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| 文档、文案、小修 | `+0.0.1` |
|
|
142
|
+
| 新命令或可感知的行为 | `+0.1.0` |
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
python -m pytest
|
|
146
|
+
python -m build
|
|
147
|
+
python -m twine check dist/*
|
|
148
|
+
python -m twine upload --repository pypi dist/android_decrypt_hub-<version>*
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
上传凭证放在本机 `~/.config/pypi/token`,不要写进仓库。上传成功后,把同一个提交推到 `decrypthub/adh-cli`。
|
|
152
|
+
|
|
153
|
+
## 协议
|
|
154
|
+
|
|
155
|
+
[MIT](./LICENSE)
|
|
156
|
+
|
|
157
|
+
## DecryptHub 桌面插件
|
|
158
|
+
|
|
159
|
+
在 DecryptHub 的「插件」入口安装官方网关,配置设备服务地址后即可启用 MCP。安装包只包含电脑端 CLI 和标准库启动器,要求 Python 3.10+;设备插件及 Host 服务仍按各自项目说明准备。
|
|
160
|
+
|
|
161
|
+
维护者构建组件:`python scripts/build_component.py`。输出 `dist/adh-<version>-any.zip`,包含 API 1 清单、源代码版本及逐文件 SHA-256,可独立通过 GitHub Releases 更新。`decrypthub-v<version>` 标签用于桌面组件分发,与 PyPI 发版独立。
|
|
162
|
+
|
|
163
|
+
## 桌面 Agent 与状态查询
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
adh status --json --endpoint http://127.0.0.1:8088
|
|
167
|
+
adh tools --json --endpoint http://127.0.0.1:8088
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`status --json` 返回带 `schemaVersion: 1` 和 `checkedAt` 的只读快照,分别列出 `connections` 的服务在线事实及 `targets` 的应用/PID/目标标识;离线地址不会冒充在线目标。状态查询不保存地址、不注入、不启停应用,也不自动升级 CLI。`tools --json` 返回当前目标的真实 MCP 工具说明和参数 schema。先查询状态,再选择本次返回的唯一目标,最后通过现有 `call` 或持久 MCP 连接执行分析;多个候选必须让用户选择。
|
|
171
|
+
|
|
172
|
+
ADH 省略端口时默认连接 8088;`devices --endpoint` 支持临时探测,`call` 收到 MCP 错误或 `isError` 时返回非零退出码。
|
|
173
|
+
|
|
174
|
+
## 开发验证
|
|
175
|
+
|
|
176
|
+
在源码目录运行 `python -m pytest`。测试配置优先导入本仓 `src`,避免误测电脑上已安装的旧版 `adh`。
|
|
177
|
+
发布前另运行 `python -m build` 与 `python -m twine check dist/*`,并在隔离环境验证构建后的 wheel。
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "android-decrypt-hub"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Connect to Host ADH Daemon and bridge HTTP MCP to stdio"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -47,3 +47,4 @@ where = ["src"]
|
|
|
47
47
|
|
|
48
48
|
[tool.pytest.ini_options]
|
|
49
49
|
testpaths = ["tests"]
|
|
50
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import uuid
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .config import clear_endpoints, config_path, load_saved_endpoints, remove_endpoint, save_endpoint
|
|
11
|
+
from .endpoint import DEFAULT_PORT, HostEndpoint
|
|
12
|
+
from .http_mcp import MCPHTTPClient, MCPTransportError, probe_endpoint
|
|
13
|
+
from .stdio import TransparentProxy, configure_stdio_utf8, serve_stdio
|
|
14
|
+
from .status import inventory
|
|
15
|
+
|
|
16
|
+
PROBE_TIMEOUT = 3.0
|
|
17
|
+
DEFAULT_CONNECT = f"127.0.0.1:{DEFAULT_PORT}"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
21
|
+
parser = argparse.ArgumentParser(
|
|
22
|
+
prog="adh",
|
|
23
|
+
description="AndroidDecryptHub connection & MCP gateway for Host ADH Daemon",
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument("--version", action="version", version=f"adh {__version__}")
|
|
26
|
+
sub = parser.add_subparsers(dest="command")
|
|
27
|
+
|
|
28
|
+
connect = sub.add_parser("connect", help="save and probe a Host ADH Daemon address")
|
|
29
|
+
connect.add_argument("endpoint", nargs="?", default=DEFAULT_CONNECT, help=f"host address (default {DEFAULT_CONNECT})")
|
|
30
|
+
connect.add_argument("--timeout", type=float, default=PROBE_TIMEOUT)
|
|
31
|
+
connect.add_argument("--force", action="store_true", help="save even when unreachable")
|
|
32
|
+
connect.add_argument("--json", action="store_true")
|
|
33
|
+
|
|
34
|
+
disconnect = sub.add_parser("disconnect", help="remove a saved Host address")
|
|
35
|
+
disconnect.add_argument("endpoint", nargs="?")
|
|
36
|
+
disconnect.add_argument("--all", action="store_true")
|
|
37
|
+
|
|
38
|
+
devices = sub.add_parser("devices", help="list saved Host daemons")
|
|
39
|
+
devices.add_argument("--json", action="store_true")
|
|
40
|
+
devices.add_argument("--endpoint", action="append", default=[])
|
|
41
|
+
|
|
42
|
+
status = sub.add_parser("status", help="read-only service and target inventory for desktop Agents")
|
|
43
|
+
status.add_argument("--endpoint", action="append", default=[])
|
|
44
|
+
status.add_argument("--timeout", type=float, default=PROBE_TIMEOUT)
|
|
45
|
+
status.add_argument("--json", action="store_true")
|
|
46
|
+
|
|
47
|
+
tools = sub.add_parser("tools", help="list the Host's real MCP tools and argument schemas")
|
|
48
|
+
tools.add_argument("--endpoint")
|
|
49
|
+
tools.add_argument("--json", action="store_true")
|
|
50
|
+
|
|
51
|
+
mcp = sub.add_parser("mcp", help="stdio MCP proxy to Host POST /mcp")
|
|
52
|
+
mcp.add_argument("--endpoint", help="override saved address for this run")
|
|
53
|
+
|
|
54
|
+
call = sub.add_parser("call", help="call one Host MCP tool")
|
|
55
|
+
call.add_argument("tool_name")
|
|
56
|
+
call.add_argument("--arguments", default="{}", metavar="JSON")
|
|
57
|
+
call.add_argument("--endpoint")
|
|
58
|
+
call.add_argument("--json", action="store_true")
|
|
59
|
+
call.add_argument("--operation", help="explicit operation control metadata as JSON")
|
|
60
|
+
call.add_argument("--operator", action="store_true", help="use ADH_OPERATOR_TOKEN explicitly")
|
|
61
|
+
|
|
62
|
+
run = sub.add_parser("run", help="observe current control once and submit a durable tool operation")
|
|
63
|
+
run.add_argument("tool_name")
|
|
64
|
+
run.add_argument("--arguments", default="{}")
|
|
65
|
+
run.add_argument("--task-id")
|
|
66
|
+
run.add_argument("--idempotency-key")
|
|
67
|
+
run.add_argument("--timeout-ms", type=int, default=120000)
|
|
68
|
+
run.add_argument("--endpoint")
|
|
69
|
+
run.add_argument("--operator", action="store_true")
|
|
70
|
+
run.add_argument("--json", action="store_true")
|
|
71
|
+
|
|
72
|
+
tasks = sub.add_parser("tasks", help="query/control persistent Host tasks and operations")
|
|
73
|
+
tasks.add_argument("action", choices=["create", "list", "get", "pause", "resume", "cancel", "complete"])
|
|
74
|
+
tasks.add_argument("id", nargs="?")
|
|
75
|
+
tasks.add_argument("--task-id")
|
|
76
|
+
tasks.add_argument("--title", default="analysis")
|
|
77
|
+
tasks.add_argument("--include-result", action="store_true")
|
|
78
|
+
tasks.add_argument("--limit", type=int, default=50)
|
|
79
|
+
tasks.add_argument("--offset", type=int, default=0)
|
|
80
|
+
tasks.add_argument("--endpoint")
|
|
81
|
+
tasks.add_argument("--operator", action="store_true")
|
|
82
|
+
tasks.add_argument("--json", action="store_true")
|
|
83
|
+
|
|
84
|
+
control = sub.add_parser("control", help="read state versions or explicitly transfer operator control")
|
|
85
|
+
control.add_argument("action", choices=["snapshot", "takeover", "release", "resolve", "hold"])
|
|
86
|
+
control.add_argument("--session")
|
|
87
|
+
control.add_argument("--resource")
|
|
88
|
+
control.add_argument("--revision", type=int)
|
|
89
|
+
control.add_argument("--epoch", type=int)
|
|
90
|
+
control.add_argument("--host-epoch", type=int)
|
|
91
|
+
control.add_argument("--acknowledge", action="store_true")
|
|
92
|
+
control.add_argument("--endpoint")
|
|
93
|
+
control.add_argument("--operator", action="store_true")
|
|
94
|
+
control.add_argument("--json", action="store_true")
|
|
95
|
+
return parser
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _resolve_saved(override: str | None) -> HostEndpoint:
|
|
99
|
+
if override:
|
|
100
|
+
return HostEndpoint.from_url(override)
|
|
101
|
+
saved = load_saved_endpoints()
|
|
102
|
+
if len(saved) == 1:
|
|
103
|
+
return saved[0]
|
|
104
|
+
if not saved:
|
|
105
|
+
raise SystemExit("adh: no saved host; run `adh connect 127.0.0.1:8088`")
|
|
106
|
+
raise SystemExit(
|
|
107
|
+
"adh: multiple saved hosts; pass --endpoint <url>\n"
|
|
108
|
+
+ "\n".join(f" {item.mcp_url}" for item in saved)
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _cmd_connect(args: argparse.Namespace) -> int:
|
|
113
|
+
endpoint = HostEndpoint.from_url(args.endpoint)
|
|
114
|
+
probed = probe_endpoint(endpoint, timeout=args.timeout)
|
|
115
|
+
status = probed.properties.get("status")
|
|
116
|
+
if status != "online" and not args.force:
|
|
117
|
+
print(f"adh: unreachable {probed.base_url} (need Host ADH Daemon on :{DEFAULT_PORT})", file=sys.stderr)
|
|
118
|
+
return 1
|
|
119
|
+
added = save_endpoint(endpoint)
|
|
120
|
+
payload = {
|
|
121
|
+
"url": probed.mcp_url,
|
|
122
|
+
"status": status,
|
|
123
|
+
"saved": True,
|
|
124
|
+
"added": added,
|
|
125
|
+
"config": str(config_path()),
|
|
126
|
+
"service": probed.properties.get("service"),
|
|
127
|
+
"version": probed.properties.get("version"),
|
|
128
|
+
"agents": probed.properties.get("agents"),
|
|
129
|
+
"mcp_tools": probed.properties.get("mcp_tools"),
|
|
130
|
+
}
|
|
131
|
+
if args.json:
|
|
132
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
133
|
+
else:
|
|
134
|
+
state = "online" if status == "online" else "saved (offline)"
|
|
135
|
+
print(f"adh: {state} {probed.base_url}")
|
|
136
|
+
print(f" mcp {probed.mcp_url}")
|
|
137
|
+
print(f" config {config_path()}")
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _cmd_disconnect(args: argparse.Namespace) -> int:
|
|
142
|
+
if args.all:
|
|
143
|
+
n = clear_endpoints()
|
|
144
|
+
print(f"adh: removed {n} saved host(s)")
|
|
145
|
+
return 0
|
|
146
|
+
if not args.endpoint:
|
|
147
|
+
print("adh: disconnect needs an address or --all", file=sys.stderr)
|
|
148
|
+
return 2
|
|
149
|
+
if remove_endpoint(args.endpoint):
|
|
150
|
+
print(f"adh: removed {HostEndpoint.from_url(args.endpoint).mcp_url}")
|
|
151
|
+
return 0
|
|
152
|
+
print("adh: address not saved", file=sys.stderr)
|
|
153
|
+
return 1
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _cmd_devices(args: argparse.Namespace) -> int:
|
|
157
|
+
saved = [HostEndpoint.from_url(value) for value in args.endpoint] if args.endpoint else load_saved_endpoints()
|
|
158
|
+
rows = [probe_endpoint(item) for item in saved]
|
|
159
|
+
if args.json:
|
|
160
|
+
print(
|
|
161
|
+
json.dumps(
|
|
162
|
+
[
|
|
163
|
+
{
|
|
164
|
+
"url": item.mcp_url,
|
|
165
|
+
"status": item.properties.get("status"),
|
|
166
|
+
"service": item.properties.get("service"),
|
|
167
|
+
"version": item.properties.get("version"),
|
|
168
|
+
"agents": item.properties.get("agents"),
|
|
169
|
+
}
|
|
170
|
+
for item in rows
|
|
171
|
+
],
|
|
172
|
+
ensure_ascii=False,
|
|
173
|
+
indent=2,
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
return 0
|
|
177
|
+
if not rows:
|
|
178
|
+
print("adh: no saved hosts. `adh connect 127.0.0.1:8088`")
|
|
179
|
+
return 0
|
|
180
|
+
for item in rows:
|
|
181
|
+
status = item.properties.get("status") or "unknown"
|
|
182
|
+
extra = item.properties.get("service") or ""
|
|
183
|
+
print(f"{status:12} {item.base_url} {extra}".rstrip())
|
|
184
|
+
return 0
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _cmd_status(args: argparse.Namespace) -> int:
|
|
188
|
+
endpoints = [HostEndpoint.from_url(value) for value in args.endpoint] if args.endpoint else load_saved_endpoints()
|
|
189
|
+
data = inventory(endpoints, timeout=args.timeout)
|
|
190
|
+
print(json.dumps(data, ensure_ascii=False, indent=2))
|
|
191
|
+
return 0
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _cmd_tools(args: argparse.Namespace) -> int:
|
|
195
|
+
endpoint = _resolve_saved(args.endpoint)
|
|
196
|
+
try:
|
|
197
|
+
response = MCPHTTPClient(endpoint, timeout=10.0).send({"jsonrpc": "2.0", "id": "adh-tools", "method": "tools/list", "params": {}})
|
|
198
|
+
result = response.get("result") if isinstance(response, dict) and "error" not in response else None
|
|
199
|
+
if not isinstance(result, dict) or not isinstance(result.get("tools"), list):
|
|
200
|
+
print("adh: invalid tools/list response", file=sys.stderr)
|
|
201
|
+
return 1
|
|
202
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
203
|
+
return 0
|
|
204
|
+
except MCPTransportError as exc:
|
|
205
|
+
print(f"adh: {exc}", file=sys.stderr)
|
|
206
|
+
return 1
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _cmd_mcp(args: argparse.Namespace) -> int:
|
|
210
|
+
endpoint = _resolve_saved(args.endpoint)
|
|
211
|
+
probed = probe_endpoint(endpoint)
|
|
212
|
+
if probed.properties.get("status") != "online":
|
|
213
|
+
print(f"adh: host unreachable {endpoint.base_url}", file=sys.stderr)
|
|
214
|
+
return 1
|
|
215
|
+
serve_stdio(TransparentProxy(endpoint).handle)
|
|
216
|
+
return 0
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _cmd_call(args: argparse.Namespace) -> int:
|
|
220
|
+
endpoint = _resolve_saved(args.endpoint)
|
|
221
|
+
try:
|
|
222
|
+
arguments = json.loads(args.arguments)
|
|
223
|
+
except json.JSONDecodeError as exc:
|
|
224
|
+
print(f"adh: --arguments must be a JSON object: {exc}", file=sys.stderr)
|
|
225
|
+
return 2
|
|
226
|
+
if not isinstance(arguments, dict):
|
|
227
|
+
print("adh: --arguments must be a JSON object", file=sys.stderr)
|
|
228
|
+
return 2
|
|
229
|
+
if args.operation:
|
|
230
|
+
try:
|
|
231
|
+
metadata = json.loads(args.operation)
|
|
232
|
+
if not isinstance(metadata, dict) or "_operation" in arguments:
|
|
233
|
+
raise ValueError("use one operation metadata object")
|
|
234
|
+
arguments["_operation"] = metadata
|
|
235
|
+
except (ValueError, json.JSONDecodeError) as exc:
|
|
236
|
+
print(f"adh: invalid --operation: {exc}", file=sys.stderr)
|
|
237
|
+
return 2
|
|
238
|
+
try:
|
|
239
|
+
client = MCPHTTPClient(endpoint, operator=True) if args.operator else MCPHTTPClient(endpoint)
|
|
240
|
+
response = client.send(
|
|
241
|
+
{
|
|
242
|
+
"jsonrpc": "2.0",
|
|
243
|
+
"id": "adh-call",
|
|
244
|
+
"method": "tools/call",
|
|
245
|
+
"params": {"name": args.tool_name, "arguments": arguments},
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
except MCPTransportError as exc:
|
|
249
|
+
print(f"adh: {exc}", file=sys.stderr)
|
|
250
|
+
return 1
|
|
251
|
+
if args.json:
|
|
252
|
+
print(json.dumps(response, ensure_ascii=False, indent=2))
|
|
253
|
+
else:
|
|
254
|
+
result = response.get("result") if isinstance(response, dict) else response
|
|
255
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
256
|
+
result = response.get("result") if isinstance(response, dict) else None
|
|
257
|
+
return 1 if not isinstance(result, dict) or result.get("isError") else 0
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _operation_rpc(client: MCPHTTPClient, arguments: dict) -> dict:
|
|
261
|
+
response = client.send({"jsonrpc": "2.0", "id": uuid.uuid4().hex, "method": "tools/call",
|
|
262
|
+
"params": {"name": "operations", "arguments": arguments}})
|
|
263
|
+
if not isinstance(response, dict) or "error" in response:
|
|
264
|
+
raise MCPTransportError("Host rejected operation management request")
|
|
265
|
+
result = response.get("result", {})
|
|
266
|
+
try:
|
|
267
|
+
value = json.loads(result["content"][0]["text"])
|
|
268
|
+
except (KeyError, IndexError, TypeError, json.JSONDecodeError) as exc:
|
|
269
|
+
raise MCPTransportError("Host does not support P1 operation management") from exc
|
|
270
|
+
if not isinstance(value, dict):
|
|
271
|
+
raise MCPTransportError("invalid operation response")
|
|
272
|
+
return value
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _cmd_operations(args: argparse.Namespace) -> int:
|
|
276
|
+
try:
|
|
277
|
+
endpoint = _resolve_saved(args.endpoint)
|
|
278
|
+
client = MCPHTTPClient(endpoint, operator=True) if args.operator else MCPHTTPClient(endpoint)
|
|
279
|
+
if args.command == "run":
|
|
280
|
+
values = json.loads(args.arguments)
|
|
281
|
+
if not isinstance(values, dict) or "_operation" in values:
|
|
282
|
+
raise ValueError("--arguments must be an object without _operation; use call for explicit versions")
|
|
283
|
+
snapshot = _operation_rpc(client, {"action": "snapshot", "tool": args.tool_name, "arguments": values})
|
|
284
|
+
if snapshot.get("ok") is False:
|
|
285
|
+
value = snapshot
|
|
286
|
+
else:
|
|
287
|
+
metadata = {"expectedRevision": snapshot["revision"], "controlEpoch": snapshot["epoch"],
|
|
288
|
+
"hostEpoch": snapshot["hostEpoch"], "idempotencyKey": args.idempotency_key or uuid.uuid4().hex,
|
|
289
|
+
"timeoutMs": args.timeout_ms}
|
|
290
|
+
if args.task_id:
|
|
291
|
+
metadata["taskId"] = args.task_id
|
|
292
|
+
value = _operation_rpc(client, {"action": "submit", "tool": args.tool_name, "arguments": values, "_operation": metadata})
|
|
293
|
+
elif args.command == "control":
|
|
294
|
+
target = {key: val for key, val in {"session": args.session, "resource": args.resource}.items() if val}
|
|
295
|
+
values = {"action": args.action, **target}
|
|
296
|
+
if args.action != "snapshot":
|
|
297
|
+
numbers = [args.revision, args.epoch, args.host_epoch]
|
|
298
|
+
if any(n is not None for n in numbers) and not all(n is not None for n in numbers):
|
|
299
|
+
raise ValueError("supply --revision, --epoch and --host-epoch together")
|
|
300
|
+
if args.acknowledge and args.action != "resolve":
|
|
301
|
+
raise ValueError("--acknowledge only applies to resolve")
|
|
302
|
+
snapshot = _operation_rpc(client, {"action": "snapshot", **target}) if numbers[0] is None else None
|
|
303
|
+
if snapshot and snapshot.get("ok") is False:
|
|
304
|
+
print(json.dumps(snapshot, ensure_ascii=False, indent=2))
|
|
305
|
+
return 1
|
|
306
|
+
values["_operation"] = {"expectedRevision": snapshot["revision"] if snapshot else args.revision,
|
|
307
|
+
"controlEpoch": snapshot["epoch"] if snapshot else args.epoch,
|
|
308
|
+
"hostEpoch": snapshot["hostEpoch"] if snapshot else args.host_epoch}
|
|
309
|
+
values["acknowledge"] = args.acknowledge
|
|
310
|
+
value = _operation_rpc(client, values)
|
|
311
|
+
else:
|
|
312
|
+
values = {"action": args.action, "limit": args.limit, "offset":args.offset, "includeResult": args.include_result}
|
|
313
|
+
if args.action == "create":
|
|
314
|
+
values["title"] = args.title
|
|
315
|
+
if args.task_id:
|
|
316
|
+
values["taskId"] = args.task_id
|
|
317
|
+
elif args.id:
|
|
318
|
+
values["taskId" if args.action in ["pause", "resume", "complete"] else "id"] = args.id
|
|
319
|
+
if args.action not in ["create", "list"] and not (args.id or args.task_id):
|
|
320
|
+
raise ValueError("a task/operation id is required")
|
|
321
|
+
value = _operation_rpc(client, values)
|
|
322
|
+
print(json.dumps(value, ensure_ascii=False, indent=2 if args.json else None))
|
|
323
|
+
# Queued/running acknowledges acceptance, never claims analysis succeeded.
|
|
324
|
+
return 0 if value.get("ok") is not False else 1
|
|
325
|
+
except (MCPTransportError, ValueError, KeyError) as exc:
|
|
326
|
+
print(f"adh: {exc}", file=sys.stderr)
|
|
327
|
+
return 1
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
331
|
+
configure_stdio_utf8()
|
|
332
|
+
parser = build_parser()
|
|
333
|
+
args = parser.parse_args(list(argv) if argv is not None else None)
|
|
334
|
+
if not args.command:
|
|
335
|
+
parser.print_help()
|
|
336
|
+
return 2
|
|
337
|
+
commands = {
|
|
338
|
+
"connect": _cmd_connect,
|
|
339
|
+
"disconnect": _cmd_disconnect,
|
|
340
|
+
"devices": _cmd_devices,
|
|
341
|
+
"status": _cmd_status,
|
|
342
|
+
"tools": _cmd_tools,
|
|
343
|
+
"mcp": _cmd_mcp,
|
|
344
|
+
"call": _cmd_call,
|
|
345
|
+
"run": _cmd_operations,
|
|
346
|
+
"tasks": _cmd_operations,
|
|
347
|
+
"control": _cmd_operations,
|
|
348
|
+
}
|
|
349
|
+
return commands[args.command](args)
|