bugx-cli 0.1.2 → 0.1.4
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.
- package/README.md +26 -29
- package/core/README.md +5 -3
- package/core/agent/agent_orchestrator.py +3 -0
- package/core/agent/agent_workspace.py +14 -2
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/twitter_promo_art.jpg +0 -0
- package/core/assets/twitter_promo_card.svg +166 -0
- package/core/assets/twitter_promo_clean.jpg +0 -0
- package/core/assets/twitter_terminal_real.png +0 -0
- package/core/bugx.md +3 -3
- package/core/bugx_paths.py +10 -2
- package/core/bundled_docs/OVERVIEW.md +310 -0
- package/core/bundled_docs/README.md +10 -0
- package/core/bundled_docs/README_EN.md +278 -0
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +833 -0
- package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
- package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
- package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
- package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +23 -0
- package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
- package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
- package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
- package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
- package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
- package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
- package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
- package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
- package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
- package/core/bundled_docs/manifest.json +140 -0
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +421 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
- package/core/cli-help.txt +7 -3
- package/core/cloud_sync/cloud_client.py +81 -2
- package/core/cloud_sync/endpoint_router.py +22 -9
- package/core/cloud_sync/issue_uploader.py +297 -0
- package/core/cloud_sync/sensitive_filter.py +77 -7
- package/core/contracts/AGENT_GUIDE.md +3 -9
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-opencode.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +10 -20
- package/core/contracts/bugx-worker.md +1 -1
- package/core/engine-integrity.json +267 -111
- package/core/host_acp/antigravity.py +153 -0
- package/core/host_acp/kimi.py +175 -0
- package/core/host_acp/minimax.py +28 -0
- package/core/host_runtime/adapters.py +5 -1
- package/core/host_runtime/antigravity.py +162 -0
- package/core/host_runtime/host_bootstrap.py +18 -7
- package/core/host_runtime/host_evaluators.py +4 -4
- package/core/host_runtime/host_registry.py +25 -4
- package/core/host_runtime/mcp_process_tracker.py +30 -3
- package/core/host_runtime/mcp_registry_gate.py +34 -11
- package/core/hosts/antigravity.py +115 -0
- package/core/hosts/codex.py +3 -0
- package/core/hosts/dsh.py +43 -24
- package/core/hosts/kimi.py +293 -0
- package/core/hosts/minimax.py +249 -0
- package/core/hosts/zcode.py +5 -0
- package/core/i18n.py +94 -5
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +30 -5
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/supervisor_bridge.py +16 -23
- package/core/launch_phases/supervisor_degraded.py +7 -5
- package/core/ledger/README.md +1 -1
- package/core/locales/en-US.json +3 -3
- package/core/locales/zh-CN.json +3 -3
- package/core/mcp_runtime_support/environment.py +6 -1
- package/core/metadata.txt +2 -2
- package/core/planning/README.md +1 -1
- package/core/planning/prompt_harness.py +2 -2
- package/core/probes/codebase_memory_probe.py +43 -24
- package/core/probes/probe_registry.py +10 -7
- package/core/prompts/command_routing_en.md +6 -5
- package/core/prompts/command_routing_zh.md +6 -5
- package/core/repair/rsi_rounds.py +3 -0
- package/core/repair/self_heal.py +160 -6
- package/core/retrieval/README.md +1 -1
- package/core/runtime/README.md +1 -1
- package/core/runtime/scenario_eval.py +5 -1
- package/core/runtime/setup_ui_env.py +4 -7
- package/core/runtime/tool_install_targets.py +12 -2
- package/core/skills/README.md +4 -2
- package/core/skills/bugx_docs_cloud_sync.py +658 -0
- package/core/skills/bugx_docs_mcp_server.py +966 -140
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/cli.py +2 -2
- package/core/supervisor/worker_execution.py +16 -3
- package/core/webui/docs_session_service.py +40 -2
- package/core/webui/mcp_inspector.py +12 -6
- package/core/webui/static/index.html +51 -3
- package/core/webui/static/manifest.webmanifest +1 -1
- package/core/webui/static/project-settings.js +18 -3
- package/core/webui/static/robots.txt +36 -0
- package/core/webui/static/sitemap.xml +15 -0
- package/docs/07_distribution/01_README_NPM.md +26 -29
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
- package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
- package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +2 -2
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
- package/ecosystem/integrations/qoder/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
- package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +8 -8
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +3 -3
- package/interfaces/bin/bugx.js +2 -0
- package/interfaces/cli/bugx_cli/__init__.py +2 -2
- package/interfaces/cli/bugx_cli/cli.py +153 -8
- package/interfaces/cli/bugx_cli/commands/agent.py +568 -136
- package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
- package/interfaces/cli/bugx_cli/commands/doctor.py +668 -223
- package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
- package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +99 -62
- package/interfaces/cli/bugx_cli/commands/plugin.py +301 -60
- package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
- package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +440 -0
- package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +522 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
- package/interfaces/cli/bugx_cli/commands/system.py +75 -5
- package/interfaces/cli/bugx_cli/common.py +135 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +190 -7
- package/interfaces/cli/bugx_cli/hosts/registry.py +6 -3
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +31 -11
- package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +242 -52
- package/package.json +38 -13
- package/pyproject.toml +57 -13
- package/scripts/sync-version.mjs +1 -1
- package/skills/README.md +24 -0
- package/skills/platform/bugx/SKILL.md +50 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bugx-dsh
|
|
3
|
+
description: BugX 自主代码审查与智能测试在 DeepSeek Harness (DSH) 宿主下的专属使用手册——新环境快速接入(构建/安装/doctor)、启动流程(pre 门禁→workers→checkpoint→post)、原生交互适配、Token 与模型用量采集。当用户在 DSH 里启动/排障/重置 BugX 审查与测试、配置新环境或需要查看 DSH 本地模型与 Token 用量报告时使用本 skill。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# BugX × DeepSeek Harness (DSH) 使用手册(实战复盘版)
|
|
7
|
+
|
|
8
|
+
本手册专为 **DeepSeek Harness (DSH)** 宿主环境深度定制,支持切换环境后秒级快速接入、零交互 `--dev` 调试与原生审计闭环。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 一、新环境快速接入(Fresh Machine Checklist)
|
|
13
|
+
|
|
14
|
+
切换新环境或新机器时,执行以下标准接入动作:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 1. 确认 Python 与 Node 环境(Python >= 3.11,推荐 3.14;Node >= 20)
|
|
18
|
+
python3 --version && node --version
|
|
19
|
+
|
|
20
|
+
# 2. 从源码构建安装最新 bugx-agent(避免 wheel 滞后)
|
|
21
|
+
cd <repo-root> \
|
|
22
|
+
&& python3 -m build --wheel \
|
|
23
|
+
&& python3 -m pip install dist/bugx_agent-*.whl --force-reinstall --no-deps
|
|
24
|
+
|
|
25
|
+
# 3. 为 DSH 安装专属 Agent 与 MCP 插件双通道
|
|
26
|
+
bugx install --root <项目根路径> --agent dsh --non-interactive --force
|
|
27
|
+
|
|
28
|
+
# 4. 体检(确保环境全绿无死锁)
|
|
29
|
+
bugx doctor --root <项目根路径>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> **要点**:
|
|
33
|
+
> 1. DSH 的 MCP 插件配置由安装器自动注入至 Cordis Profile(`~/Library/Application Support/dsh-desktop/harness/profiles/headless/cordis.patch.yml`)。
|
|
34
|
+
> 2. DSH 插件采用低层 JSON-RPC 绕过 `@modelcontextprotocol/sdk` 的 Zod 版本断言冲突,确保工具调用零异常。
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 二、启动挖掘标准流程(DSH 宿主)
|
|
39
|
+
|
|
40
|
+
### 1. 初始化
|
|
41
|
+
```bash
|
|
42
|
+
cd <项目根路径>
|
|
43
|
+
bugx init
|
|
44
|
+
```
|
|
45
|
+
- 自动完成项目画像对齐与本地基线构建。
|
|
46
|
+
- 只有需要跨设备同步时才追加 `--cloud-sync sync`:`sync` 是显式授权(会写盘共享状态),不传则维持 `local`;`--dev` 同样默认 `local`,不会替你开同步。
|
|
47
|
+
|
|
48
|
+
### 2. 免交互极速启动(--dev 模式)
|
|
49
|
+
在调试或快速排查阶段,使用 `--dev` 跳过所有宿主问答阻塞:
|
|
50
|
+
```bash
|
|
51
|
+
bugx engine --root . pre --dev
|
|
52
|
+
```
|
|
53
|
+
- **自动初始化 Git 基线**:仅当目录还不是仓库时才 `git init`;缺身份时写入仓库级 `user.name=BugX Dev` / `user.email=bugx-dev@localhost`;仅在暂存区为空时提交空基线,索引非空则打印 `⚠ 暂存区已有内容` 并跳过——全程不会 `git add` 你的任何文件;
|
|
54
|
+
- **自动批准作战方案**:自动确认策略计划(`--strategy-plan approve`);
|
|
55
|
+
- **全自动预设模式**:轮询 `auto`、审查 `mcp-auto`、修复 `auto`、提交 `round`、恢复 `resume`、启动动作 `start`;
|
|
56
|
+
- **云策略默认 `local`**:需要同步时显式传 `--cloud-sync sync`,或写入项目/全局配置的 `cloud_sync`。
|
|
57
|
+
|
|
58
|
+
### 3. 生成并发 Worker 与任务切片
|
|
59
|
+
```bash
|
|
60
|
+
bugx engine --root . workers --count 1
|
|
61
|
+
```
|
|
62
|
+
- 输出原子预占的 coverage unit 提示词切片(包含 `worker_id`、`lease_id` 与 `artifact_root`)。
|
|
63
|
+
- DSH 主智能体派发 Task 子智能体(`subagent_type: bugx-worker`),或者由当前会话并发承接。
|
|
64
|
+
|
|
65
|
+
### 4. Worker 执行、举证与 Checkpoint
|
|
66
|
+
在 Worker 子智能体中:
|
|
67
|
+
1. **立即确认开工**:
|
|
68
|
+
```bash
|
|
69
|
+
python3 "$(bugx engine path --name audit_supervisor.py)" worker-start \
|
|
70
|
+
--root . --state <supervisor.json> --worker <worker_id> \
|
|
71
|
+
--provider dsh --execution-id exec-<lease_id>
|
|
72
|
+
```
|
|
73
|
+
2. **生成测试与证据**:
|
|
74
|
+
- 将 PoC、Traceback、断言差异全部写入分配的 `artifact_root`。
|
|
75
|
+
3. **提交 Checkpoint**:
|
|
76
|
+
```bash
|
|
77
|
+
python3 "$(bugx engine path --name worker_checkpoint.py)" finalize \
|
|
78
|
+
--root . --state <supervisor.json> --worker <worker_id> \
|
|
79
|
+
--status covered --artifact <artifact_path> \
|
|
80
|
+
--command "<repro_cmd>" --exit-code 0 --tokens <tokens>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 5. 封存报告与结算
|
|
84
|
+
```bash
|
|
85
|
+
export BH_PRE_BASELINE=<pre-baseline.json 绝对路径>
|
|
86
|
+
bugx engine --root . post
|
|
87
|
+
```
|
|
88
|
+
- 自动结算当前 Round、更新复盘账本,并输出结构化 Round 报告。
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 二·五、确认协议(candidate → confirmed)
|
|
93
|
+
|
|
94
|
+
> **这一章缺了会导致整轮 BLOCKED。** 实测:OctoPrintMCP 真实项目,dsh 产出 2 条
|
|
95
|
+
> 高质量 finding(high 路径穿越 + low 目录创建),有 severity/confidence/root_cause/
|
|
96
|
+
> reproduction/3-4 条 path+line evidence,唯独 `confirmation` 为空 →
|
|
97
|
+
> `finding_confirmation_pending` → 整轮判 blocked,`recovery_required: true`。
|
|
98
|
+
> 工作白做。根因是 dsh SKILL 此前没有本章,而 zcode SKILL 有。
|
|
99
|
+
|
|
100
|
+
### 为什么不能「产出即成功」
|
|
101
|
+
|
|
102
|
+
`_validate_incoming_findings` 在**摄入侧**就校验 `reproducible=True` 必须带非空
|
|
103
|
+
`reproduction`,完成门禁再查 confirmation。这是刻意的:未确认的 finding 若被
|
|
104
|
+
当成成功,用户会以为审计过了,而实际没人验证过该缺陷真的存在。
|
|
105
|
+
|
|
106
|
+
### 两步
|
|
107
|
+
|
|
108
|
+
**第 1 步:同指纹 ≥2 次独立运行**
|
|
109
|
+
|
|
110
|
+
同一个 finding 用**两个不同 channel** 各复现一次,各落一份 artifact:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# 两次运行,run_id / channel 必须不同,各自记录 artifact_path + sha256
|
|
114
|
+
python3 <你的探针>.py > state/host-confirmation/<slug>-a.json
|
|
115
|
+
python3 <你的探针>.py > state/host-confirmation/<slug>-b.json
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**第 2 步:按 schema 提交 transition**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# 注意:transition 必须同时给 --id 和 --state,只给 --input 会被拒
|
|
122
|
+
python3 core/ledger/finding_confirmation.py transition \
|
|
123
|
+
--input <payload>.json \
|
|
124
|
+
--id <finding-id> \
|
|
125
|
+
--state reproduced \
|
|
126
|
+
--output <写回目标>.json
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
先用 `validate` 自检 schema,再用 `gate` 看还缺什么:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python3 core/ledger/finding_confirmation.py validate --input <payload>.json
|
|
133
|
+
python3 core/ledger/finding_confirmation.py gate --input <payload>.json
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
payload 逐项必须,缺一即拒:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"schema_version": 1,
|
|
141
|
+
"duration_seconds": 0,
|
|
142
|
+
"findings": [{
|
|
143
|
+
"id": "...", "fingerprint": "...", "title": "...",
|
|
144
|
+
"severity": "high", "confidence": 0.95,
|
|
145
|
+
"root_cause": "...",
|
|
146
|
+
"evidence": [{"path": "src/x.py", "line": 64}],
|
|
147
|
+
"reproducible": true,
|
|
148
|
+
"reproduction": "python3 ...",
|
|
149
|
+
"root_cause_verified": true,
|
|
150
|
+
"confirmation": {
|
|
151
|
+
"state": "reproduced",
|
|
152
|
+
"oracle": {
|
|
153
|
+
"tier": "differential",
|
|
154
|
+
"reference": "...",
|
|
155
|
+
"provenance": {
|
|
156
|
+
"kind": "runtime-invariant",
|
|
157
|
+
"independent_from_change": true,
|
|
158
|
+
"verified": true
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"observations": [
|
|
162
|
+
{"run_id": "run-a", "channel": "channel-a", "fingerprint": "...",
|
|
163
|
+
"reference": "...", "outcome": "failure",
|
|
164
|
+
"artifact_path": "...", "artifact_sha256": "..."},
|
|
165
|
+
{"run_id": "run-b", "channel": "channel-b", "fingerprint": "...",
|
|
166
|
+
"reference": "...", "outcome": "failure",
|
|
167
|
+
"artifact_path": "...", "artifact_sha256": "..."}
|
|
168
|
+
],
|
|
169
|
+
"negative_control": {"outcome": "pass", "reference": "..."},
|
|
170
|
+
"root_cause": {"location": "...", "mechanism": "..."}
|
|
171
|
+
},
|
|
172
|
+
"target_execution": {
|
|
173
|
+
"target_platform": "darwin-arm64-cpython-3.14",
|
|
174
|
+
"executed_platform": "darwin-arm64-cpython-3.14",
|
|
175
|
+
"executed": true, "simulated": false,
|
|
176
|
+
"outcome": "failure", "errors": []
|
|
177
|
+
}
|
|
178
|
+
}]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 四个实测踩过的坑
|
|
183
|
+
|
|
184
|
+
| 症状 | 原因 | 对策 |
|
|
185
|
+
|------|------|------|
|
|
186
|
+
| 目标平台与实际执行平台不一致 | `"darwin"` ≠ `"darwin-arm64-cpython-3.14"` | 两个字段**逐字相同** |
|
|
187
|
+
| negative_control 被拒 | `outcome` 写成 `"OK"` | 只能是 `failure` / `pass` / `blocked` |
|
|
188
|
+
| 两条 observation 不算独立 | 用了同一个 channel | 必须**两个不同** channel |
|
|
189
|
+
| post 快照校验失败 | `findings.json` 缺 `run_binding` | 顶层 `run_id` + `run_binding{run_id,lifecycle_id,round}` 与 `runtime.json` 逐字一致 |
|
|
190
|
+
|
|
191
|
+
### 确认之后
|
|
192
|
+
|
|
193
|
+
写回 lifecycle `findings.json`(confirmed 状态 + confirmation 块)→ post 自动结算 →
|
|
194
|
+
复盘自动落账 → Round 报告封存。
|
|
195
|
+
|
|
196
|
+
**只产出 candidate 不转 confirmed = 这一轮不算完成。** 宁可早期把
|
|
197
|
+
`reproducible` 显式置 `false` 并说明原因,也不要留下 `reproducible: true`
|
|
198
|
+
却没有 confirmation 的半成品——后者会让整轮卡住且难以定位。
|
|
199
|
+
|
|
200
|
+
## 三、Token 与模型用量核验(DSH 专属)
|
|
201
|
+
|
|
202
|
+
针对 DSH 宿主,系统内置专属用量收集器(`core/hosts/_dsh_usage.py`):
|
|
203
|
+
1. **自动读取会话归档**:
|
|
204
|
+
- 扫描 `~/Library/Application Support/dsh-desktop/harness/sessions/--<项目根>--/*.zstd` 日志;
|
|
205
|
+
- 提取当前 Lifecycle 时间窗(`started_epoch` 至结算)内的所有交互记录。
|
|
206
|
+
2. **测试报告展示**:
|
|
207
|
+
在 Round 结束报告中与 ZCode 保持一致,自动呈现细分指标:
|
|
208
|
+
- `调度侧 Token(本地宿主采集)`:包含主控制面上下文 Token;
|
|
209
|
+
- `Worker Token(宿主本地核验)`:Worker 执行开销;
|
|
210
|
+
- `模型用量`:按模型展示调用次数、Input/Output/CacheRead/Total Token 及流式响应总耗时;
|
|
211
|
+
- `模型调用时长汇总`:精确格式化时长(如 `12m 34s`)。
|
|
212
|
+
3. **明细持久化**:
|
|
213
|
+
- 完整明细落盘于 `.bugx/.../state/dsh-usage.json`,只进本地报告,不污染云端 Schema。
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 四、重置与故障恢复
|
|
218
|
+
|
|
219
|
+
若运行态出现死锁或脏状态:
|
|
220
|
+
```bash
|
|
221
|
+
# 1. 清理残留 MCP 进程
|
|
222
|
+
ps aux | grep "mcp serve" | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null || true
|
|
223
|
+
|
|
224
|
+
# 2. 项目级状态重置
|
|
225
|
+
bugx reset --scope project --root . --yes
|
|
226
|
+
|
|
227
|
+
# 3. 重新以 dev 模式跑通
|
|
228
|
+
bugx init && bugx engine --root . pre --dev
|
|
229
|
+
```
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bugx-opencode
|
|
3
|
+
description: "BugX 自主代码审查与智能测试在 OpenCode 宿主的操作手册。当宿主发起/执行 BugX 代码审查、智能测试、深度缺陷排查,或遇到 bugx engine pre 门禁、MCP 会话冲突(session_occupied)、Worker 派发(bugx-worker subagent)、headless/ACP 验收、判读式审计(judge)、findings 确认协议、post 结算封存等问题时使用。触发词:bugx 审查、智能测试、pre 门禁、session_occupied、bugx-worker、judge collect、post --final。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# BugX × OpenCode 使用手册(实战复盘版)
|
|
7
|
+
|
|
8
|
+
引擎源码仓库(本仓 dev 分支)。本手册共性部分继承
|
|
9
|
+
`bugx-zcode` skill(判读式审计/确认协议/坑位),特性部分按 OpenCode 宿主契约
|
|
10
|
+
(`core/contracts/bugx-opencode.md`)微调。所有坑位均实证。
|
|
11
|
+
|
|
12
|
+
## 〇、最短路径决策树
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
要审计一个项目
|
|
16
|
+
└─ cd <项目根> && opencode # 必须在项目根启动(MCP 是 --root . 相对绑定)
|
|
17
|
+
└─ agent 列表选 bugx(或默认对话说「用 bugx 审计」)
|
|
18
|
+
└─ bugx engine --root . pre # 交互 TUI:启动门禁逐组原生 question 询问
|
|
19
|
+
└─ 判读式五步(见 §四)→ post --final
|
|
20
|
+
└─ 失败先查 .bugx/.../state/judge/judge-log.jsonl(结构化事件流)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 一、OpenCode 特性事实(先记牢再动手)
|
|
24
|
+
|
|
25
|
+
1. **项目级 MCP**:`opencode.json` 在**项目根**(三个 bugx MCP:host/worker/docs,
|
|
26
|
+
`command: ["bugx", ...]` 走 PATH,`--root .` 相对绑定)。与 ZCode 的用户级单例
|
|
27
|
+
不同——**换项目无需 rebind,切靶场即换上下文**;但必须从项目根启动 TUI。
|
|
28
|
+
2. **agent 入口**:`.opencode/agents/bugx.md`(mode: all)+ `bugx-worker.md`;
|
|
29
|
+
全局软链 `~/.config/opencode/agents/`。
|
|
30
|
+
3. **权限形态**:agent 权限矩阵 `execute: deny`(仅白名单例外,含
|
|
31
|
+
`*bugx engine* pre*` / `*bugx engine* post*`)。**一切动作走 MCP 工具或
|
|
32
|
+
白名单 shell**,禁止绕过。
|
|
33
|
+
4. **交互原语**:TUI `interaction=question` 必须用宿主原生 `question` 工具
|
|
34
|
+
(单选 `multiple=false`,**一次只传一个阶段问题**),禁止普通文本提问替代;
|
|
35
|
+
无效/取消/失败留在当前阶段,不得自行降级。
|
|
36
|
+
|
|
37
|
+
## 二、启动与门禁(含 --dev 场景闸门)
|
|
38
|
+
|
|
39
|
+
1. **交互 TUI(用户在场)**:`bugx engine --root . pre` **不带任何跳过旗标**——
|
|
40
|
+
启动门禁(云端/方案/审查/轮询/修复/提交/报告处置)逐组原生 question 询问用户,逐项确认。
|
|
41
|
+
2. **⚠ --dev 场景闸门**:`pre --dev` 仅允许 ①用户明确要求无人值守 ②同一靶场
|
|
42
|
+
重验快审。**用户在场禁止默认用 --dev**;拿不准就先问用户选哪种模式。
|
|
43
|
+
headless/ACP 场景用 `pre --autonomous`(见 §三.4),也不是 --dev。
|
|
44
|
+
3. **resume 语义坑**:`runtime.active=true`(上一轮没跑 `post --final`)时,
|
|
45
|
+
pre 走会话恢复(resume)**静默跳过门禁**。中断后必须先收口(`post --final`
|
|
46
|
+
或确认 aborted 终态)再重跑 pre,否则永远不询问。
|
|
47
|
+
4. **pre 必须前台同步**:OpenCode v2 原生 shell 显式 `workdir`=项目根、
|
|
48
|
+
`timeout=300000`;禁止 `timeout` 包装、`&`/`nohup`/后台会话、sleep/ps 轮询、
|
|
49
|
+
输出重定向到项目根之外。工具超时记 `BLOCKED`,不得伪造退出码。
|
|
50
|
+
5. **门禁防逃逸锁**:严禁在对话文本里自述「我选选项 1」绕过门禁——启动决策必须
|
|
51
|
+
由 pre 写入 `.bugx/` 状态机,未写入前拒绝配 Worker。
|
|
52
|
+
|
|
53
|
+
## 三、OpenCode 特有纪律
|
|
54
|
+
|
|
55
|
+
1. **MCP 会话证明优先**:先调当前会话已加载的 `bugx-supervisor` Host MCP
|
|
56
|
+
(真实 MCP 在 tools/list 后写入短期会话证明,CLI 子进程读取该证明)。
|
|
57
|
+
**禁止**从 shell 再启动 `bugx mcp serve` / `bugx mcp probe` / stdio 探针——
|
|
58
|
+
会与 host controller lease 冲突得到 `session_occupied`。
|
|
59
|
+
2. **Worker 派发(C 路径代表)**:主 Agent 用 OpenCode v2 原生 `subagent` 工具,
|
|
60
|
+
agent ID `bugx-worker`,**每次调用必须显式传 `background=false`**(前台等结果)。
|
|
61
|
+
主 Agent 自己读 `bugx engine --root . workers` 完整输出,把完整任务块原样交子
|
|
62
|
+
Agent;严禁把 CLI 命令文本当 Worker prompt、不得省略 `WORKER_CLAIM_FACTS`。
|
|
63
|
+
Worker 首个工具调用:无预占事实 → `claim`;有完整预占事实 → `worker_start`。
|
|
64
|
+
两者成功前禁止任何项目探索。父 Agent 不代跑探测、不写 artifact、不调 Worker
|
|
65
|
+
MCP;必须等到每个 Worker 结果返回再推进,Worker 仍 active 时不得结束回合。
|
|
66
|
+
3. **headless/ACP 验收**:`opencode run --format json -f <prompt_file> <message>`;
|
|
67
|
+
`question` 工具会被宿主静默阻断(interaction=blocked)⇒ 此场景走
|
|
68
|
+
`pre --autonomous` + 显式门禁参数。ACP `session/new` 默认选项目主 Agent——
|
|
69
|
+
验收客户端必须先 `session/set_mode` 显式选 `bugx`,不可用则 fail-closed,
|
|
70
|
+
不得拿默认 Agent 结果冒充 BugX 验收。
|
|
71
|
+
4. **状态机与账本**:`.bugx/` 是运行态账本与证据库,严禁把运行时产物写进生产
|
|
72
|
+
源码与依赖(与所有宿主一致)。
|
|
73
|
+
|
|
74
|
+
## 四、判读式五步标准流(共性,每步一条命令)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bugx engine --root . pre # 交互场景:启动门禁逐组询问(用户逐项确认)
|
|
78
|
+
bugx engine --root . judge --all # 一次领满容量内全部单元;判读包并发给 bugx-judge
|
|
79
|
+
bugx engine --root . judge --settle-dir <verdicts目录>
|
|
80
|
+
bugx engine --root . findings-confirm --from-verdicts <verdicts.json>
|
|
81
|
+
bugx engine --root . post --final # 会话最后一条引擎命令必须是 --final
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **回合自检**:`state/judge/judge-log.jsonl` 里 `collect_summary` >2 次 = 在
|
|
85
|
+
浪费回合(judge collect 必须单轮领满);findings-confirm 拆多轮同理
|
|
86
|
+
(一条命令 ~6s,实测拆散拖到 235s)。
|
|
87
|
+
- **submit_finding 定级口径**:必带 `confidence`(≥2 独立通道 observations +
|
|
88
|
+
negative_control pass ⇒ ≥0.75;差分哨兵 SENTINEL ⇒ ≥0.85);severity 按
|
|
89
|
+
CWE 口径(任意代码执行/命令注入 = CRITICAL;SQL 注入/路径穿越/硬编码云凭据
|
|
90
|
+
= HIGH),不得因不确定保守降级——否则引擎 fallback 会把 confirmed 缺陷
|
|
91
|
+
兜底成 0.35。
|
|
92
|
+
- **证据落盘**:验收要求 artifact 在案时,probe 输出写 claim 的 `artifact_root`
|
|
93
|
+
相对路径,checkpoint finalize 用 `--artifact`(多单元 `--artifacts-json`)。
|
|
94
|
+
|
|
95
|
+
## 五、确认协议要点(共性)
|
|
96
|
+
|
|
97
|
+
finding 转 confirmed:同指纹 ≥2 次独立运行 + ≥2 独立通道 + negative_control
|
|
98
|
+
`pass`(不是 "OK")+ `root_cause_verified`;`target_execution` 的
|
|
99
|
+
`target_platform` 与 `executed_platform` **逐字相同**(darwin ≠
|
|
100
|
+
darwin-arm64-cpython-3.14)。findings.json 顶层 `run_binding.run_id` 用
|
|
101
|
+
`lifecycle-<polling>-<lifecycle>` 形式,`round` 与 runtime 当前轮逐字一致。
|
|
102
|
+
|
|
103
|
+
finding 的 `reproduction` 字段必须非空且可被第三方独立执行;`confirmation`
|
|
104
|
+
块必须带 `state:"reproduced"` 与非 heuristic 的 `oracle`(含
|
|
105
|
+
`provenance.independent_from_change:true`)。这两个字段名由
|
|
106
|
+
`core/ledger/finding_confirmation.py` 的 `confirmation_issues()` 直接读取,
|
|
107
|
+
写错或省略都会使候选永久停在 pending。复现脚本必须打印非空失败观测再
|
|
108
|
+
`exit 1`,否则只有 `engine-verify:exit-code` 单通道,门禁拒绝。
|
|
109
|
+
|
|
110
|
+
## 六、坑位表
|
|
111
|
+
|
|
112
|
+
| 症状 | 根因 | 对策 |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| pre 没弹门禁询问 | runtime 悬挂(上轮没 `--final`)→ resume | 收口后重跑;交互场景 pre 不带跳过旗标 |
|
|
115
|
+
| `session_occupied` | shell 重复起 serve / stdio 探针 | 只用会话内已装配的 MCP;禁 shell 探针 |
|
|
116
|
+
| Worker 没跑 / 提前结束回合 | subagent 未传 `background=false`,或父 Agent 先输出了结束文本 | 每次显式 `background=false`;Worker active 时主 Agent 必须等待 |
|
|
117
|
+
| ACP 验收拿默认 Agent 冒充 | `session/new` 默认主 Agent | 先 `session/set_mode` 选 `bugx`,不可用 fail-closed |
|
|
118
|
+
| pre 超时被记失败 | 工具级 timeout 包装/后台化 | 前台 300s 同步等待,超时如实记 BLOCKED |
|
|
119
|
+
| checkpoint 三连拒 | 手拼 payload | 用 `worker_checkpoint.py finalize`(自动绑指纹与 receipt) |
|
|
120
|
+
| post 报「必须紧接活动 pre」 | runtime aborted | 重跑 pre 走恢复;supervisor 冻结则 `pre --session-recovery new` |
|
|
121
|
+
| 引擎从 `~/.bugx/core` 加载 | 改了源码没同步 | `bugx install` 同步全局;只 pip install 不够 |
|
|
122
|
+
|
|
123
|
+
## 七、验收基线
|
|
124
|
+
|
|
125
|
+
- 交互 TUI 首轮 pre 启动门禁逐组原生 question 询问(用户逐项确认)
|
|
126
|
+
- 覆盖单元恰等于产品文件;judge 单轮领满;settle/确认秒级;judge-log 事件齐全
|
|
127
|
+
- post --final 收口后 runtime 终态明确(COMPLETE / ABORTED / BLOCKED /
|
|
128
|
+
RECOVERY_REQUIRED),无 NEXT_ROUND 悬挂
|
|
129
|
+
- 结构化失败原因输出,无静默降级;退出码 0 即收口成功
|