oh-aicoding-tool 0.1.0
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/CODEX_LANGFUSE_PLAN.md +62 -0
- package/README.md +114 -0
- package/bin/cli.js +166 -0
- package/bin/langfuse-cli.js +718 -0
- package/codex_langfuse_notify.py +591 -0
- package/langfuse_hook.py +603 -0
- package/opencode-ohai-report/.claude/commands/report-ai-issue.md +60 -0
- package/opencode-ohai-report/.opencode/commands/report-ai-issue.md +30 -0
- package/opencode-ohai-report/.opencode/plugins/oh-ai-report.ts +569 -0
- package/opencode-ohai-report/README.md +45 -0
- package/opencode-ohai-report/bin/cli.js +421 -0
- package/opencode-ohai-report/docs/opencode-ai-issue-collection-architecture.md +313 -0
- package/opencode-ohai-report/docs/opencode-ai-issue-collection-best-practices.md +476 -0
- package/opencode-ohai-report/docs/opencode-ai-issue-collection-phase1-summary.md +405 -0
- package/opencode-ohai-report/examples/issue_output.json +4 -0
- package/opencode-ohai-report/package.json +40 -0
- package/opencode-ohai-report/scripts/claude_report_hook.py +257 -0
- package/opencode-ohai-report/scripts/create_issue.py +34 -0
- package/opencode-ohai-report/scripts/install-claude-plugin.ps1 +254 -0
- package/opencode-ohai-report/scripts/install-opencode-plugin.ps1 +264 -0
- package/opencode-ohai-report/scripts/install-opencode-plugin.sh +218 -0
- package/opencode-ohai-report/scripts/merge-claude-settings.py +99 -0
- package/opencode-ohai-report/tools/ohai-report/README.md +151 -0
- package/opencode-ohai-report/tools/ohai-report/examples/issue-input.json +26 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/__init__.py +5 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/__main__.py +9 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/cli.py +319 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/git_context.py +32 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/gitcode_defaults.py +14 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/issue_markdown.py +313 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/metadata.py +360 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/observability/__init__.py +1 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/observability/langfuse.py +38 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/payload.py +64 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/schema.py +80 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/__init__.py +1 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/base.py +15 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/gitcode.py +405 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/local.py +21 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/webhook.py +354 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/webhook_defaults.py +9 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report/workspace.py +61 -0
- package/opencode-ohai-report/tools/ohai-report/ohai_report.py +10 -0
- package/opencode-ohai-report/tools/ohai-report/schemas/report_issue.schema.json +166 -0
- package/package.json +59 -0
- package/scripts/codex-langfuse-check.mjs +101 -0
- package/scripts/codex-langfuse-setup.mjs +181 -0
- package/scripts/langfuse-check.mjs +90 -0
- package/scripts/langfuse-setup.mjs +278 -0
- package/scripts/opencode-langfuse-check.mjs +94 -0
- package/scripts/opencode-langfuse-run.mjs +96 -0
- package/scripts/opencode-langfuse-setup.mjs +478 -0
- package/scripts/resolve-opencode-cli.mjs +58 -0
- package/setup-langfuse.bat +163 -0
- package/setup-langfuse.sh +130 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# OpenCode 问题采集架构设计
|
|
2
|
+
|
|
3
|
+
## 1. 背景与目标
|
|
4
|
+
|
|
5
|
+
本设计用于维护 OpenCode 场景下的 AI 辅助开发问题采集能力。目标不是采集完整日志,而是将用户问题模板化,并通过 `session_id` / `trace_id` / `langfuse_url` 关联到 Langfuse 中的完整会话和日志。
|
|
6
|
+
|
|
7
|
+
核心目标:
|
|
8
|
+
|
|
9
|
+
- 降低 OpenCode 主上下文污染。
|
|
10
|
+
- 让 subagent 使用 LLM 完成轻量模板化。
|
|
11
|
+
- Issue 中不上传日志、diff、transcript、源码或工具输出。
|
|
12
|
+
- 上报核心与 Agent 入口解耦,便于后续支持 Claude Code、Codex 等适配器。
|
|
13
|
+
- 后端 sink 可替换,先本地 JSON,后续可升级 GitCode/Jira/DTS。
|
|
14
|
+
|
|
15
|
+
## 2. 总体架构
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
OpenCode 用户
|
|
19
|
+
/report-ai-issue <一句话问题>
|
|
20
|
+
|
|
|
21
|
+
v
|
|
22
|
+
OpenCode Command Adapter
|
|
23
|
+
.opencode/commands/report-ai-issue.md
|
|
24
|
+
subtask: true
|
|
25
|
+
|
|
|
26
|
+
v
|
|
27
|
+
Subagent / LLM Template Layer
|
|
28
|
+
title/category/summary/expected/actual/severity
|
|
29
|
+
|
|
|
30
|
+
v
|
|
31
|
+
ohai-report CLI
|
|
32
|
+
schema validation
|
|
33
|
+
metadata auto
|
|
34
|
+
payload assembly
|
|
35
|
+
sink dispatch
|
|
36
|
+
|
|
|
37
|
+
v
|
|
38
|
+
Sink
|
|
39
|
+
local JSON / GitCode / Webhook(默认 URL 见 webhook_defaults.py)
|
|
40
|
+
Jira/DTS 等可后续扩展
|
|
41
|
+
|
|
|
42
|
+
v
|
|
43
|
+
Langfuse
|
|
44
|
+
linked by session_id / trace_id / langfuse_url
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 3. 模块分层
|
|
48
|
+
|
|
49
|
+
| 层级 | 文件 | 职责 |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| Agent Adapter | `.opencode/commands/report-ai-issue.md` | `/report-ai-issue`;默认 `--sink webhook`(`WEBHOOK_URL` 优先,否则 `webhook_defaults`) |
|
|
52
|
+
| Plugin Adapter | `.opencode/plugins/oh-ai-report.ts` | 可选 metadata 刷新和 custom tool |
|
|
53
|
+
| CLI Entrypoint | `tools/ohai-report/ohai_report.py` | 兼容入口,转发到 package CLI |
|
|
54
|
+
| CLI Orchestration | `tools/ohai-report/ohai_report/cli.py` | 解析命令,编排 validation、metadata、payload、sink |
|
|
55
|
+
| Schema File | `tools/ohai-report/schemas/report_issue.schema.json` | 问题模板字段、枚举、长度约束 |
|
|
56
|
+
| Schema Runtime | `tools/ohai-report/ohai_report/schema.py` | 读取 schema 文件,执行校验 |
|
|
57
|
+
| Metadata | `tools/ohai-report/ohai_report/metadata.py` | 合并本地 metadata、环境变量、git 上下文 |
|
|
58
|
+
| Payload | `tools/ohai-report/ohai_report/payload.py` | 生成标准 ReportPayload |
|
|
59
|
+
| Issue 正文模板 | `tools/ohai-report/ohai_report/issue_markdown.py` | 「AI 使用问题反馈」Markdown,Webhook/GitCode 共用 |
|
|
60
|
+
| Sink | `tools/ohai-report/ohai_report/sinks/local.py` | 本地 JSON 落盘 |
|
|
61
|
+
| GitCode Sink | `tools/ohai-report/ohai_report/sinks/gitcode.py` | GitCode Issues API 落远端并回写本地 |
|
|
62
|
+
| GitCode 默认仓库 | `tools/ohai-report/ohai_report/gitcode_defaults.py` | 可选写死 owner/repo;Token 仅用环境变量 |
|
|
63
|
+
| Webhook Sink | `tools/ohai-report/ohai_report/sinks/webhook.py` | JSON Webhook 建单(title + Markdown body) |
|
|
64
|
+
| Webhook 默认地址 | `tools/ohai-report/ohai_report/webhook_defaults.py` | `WEBHOOK_URL` 未设时的回退地址 |
|
|
65
|
+
| 快捷脚本 | `scripts/create_issue.py` | 读取 `examples/issue_output.json` 等并 POST Webhook |
|
|
66
|
+
|
|
67
|
+
GitCode sink 在维护者自动建标签模式下会为新标签分配稳定颜色:agent、优先级和分类标签使用不同色系;已有标签只绑定,不主动改色。Webhook sink 目前只发送逗号分隔的 ASCII 标签字符串,颜色由 Webhook 服务端决定。
|
|
68
|
+
|
|
69
|
+
## 4. 数据流
|
|
70
|
+
|
|
71
|
+
### 4.1 用户上报
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
用户输入:
|
|
75
|
+
/report-ai-issue hdc 远程服务器无法连接本地开发板
|
|
76
|
+
|
|
77
|
+
OpenCode command:
|
|
78
|
+
以 subtask 执行
|
|
79
|
+
使用 LLM 生成模板字段
|
|
80
|
+
|
|
81
|
+
ohai-report create:
|
|
82
|
+
校验字段
|
|
83
|
+
metadata auto 补齐 session/trace/user/context
|
|
84
|
+
生成 payload
|
|
85
|
+
写入 local sink
|
|
86
|
+
|
|
87
|
+
返回:
|
|
88
|
+
已上报:AI-DEV-yyyymmddHHMMSS
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 4.2 Metadata 更新
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
OpenCode plugin 或人工命令
|
|
95
|
+
-> ohai-report metadata update
|
|
96
|
+
-> .ohai-report/metadata.json
|
|
97
|
+
|
|
98
|
+
create --metadata auto
|
|
99
|
+
-> 读取 metadata.json
|
|
100
|
+
-> 读取环境变量
|
|
101
|
+
-> 读取 git context
|
|
102
|
+
-> 组装最终 metadata
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 5. ReportPayload 协议
|
|
106
|
+
|
|
107
|
+
当前 payload 结构:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"issue_id": "AI-DEV-20260508120000",
|
|
112
|
+
"created_at": "2026-05-08T12:00:00+08:00",
|
|
113
|
+
"source": "opencode",
|
|
114
|
+
"agent": "opencode",
|
|
115
|
+
"session_id": "opencode-session-xxx",
|
|
116
|
+
"trace_id": "langfuse-trace-xxx",
|
|
117
|
+
"langfuse_url": "https://langfuse.example.com/project/xxx/traces/xxx",
|
|
118
|
+
"user": {
|
|
119
|
+
"id": "user001",
|
|
120
|
+
"name": "zhangsan",
|
|
121
|
+
"team": "OpenHarmony AI"
|
|
122
|
+
},
|
|
123
|
+
"issue": {
|
|
124
|
+
"title": "HDC 远程连接失败",
|
|
125
|
+
"category": "环境问题",
|
|
126
|
+
"summary": "远程 OpenCode 无法访问本地 HDC 设备",
|
|
127
|
+
"expected_behavior": "能够给出本地设备访问配置提示",
|
|
128
|
+
"actual_behavior": "无法发现或连接本地开发板",
|
|
129
|
+
"severity": "P2",
|
|
130
|
+
"user_description": "hdc 远程服务器无法连接本地开发板"
|
|
131
|
+
},
|
|
132
|
+
"context": {
|
|
133
|
+
"repo": "",
|
|
134
|
+
"branch": "",
|
|
135
|
+
"commit": "",
|
|
136
|
+
"cwd": ""
|
|
137
|
+
},
|
|
138
|
+
"privacy": {
|
|
139
|
+
"uploads_logs": false,
|
|
140
|
+
"uploads_diff": false,
|
|
141
|
+
"uploads_transcript": false,
|
|
142
|
+
"note": "Issue only stores template fields and Langfuse/session indexes."
|
|
143
|
+
},
|
|
144
|
+
"status": "created-local"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
约束:
|
|
149
|
+
|
|
150
|
+
- `issue.category` 必须来自 `schema.py` 枚举。
|
|
151
|
+
- `issue.severity` 必须是 `P0/P1/P2/P3`。
|
|
152
|
+
- `privacy.uploads_logs/uploads_diff/uploads_transcript` 当前必须为 `false`。
|
|
153
|
+
- 完整日志只通过 Langfuse 查询。
|
|
154
|
+
|
|
155
|
+
## 6. 维护与升级方式
|
|
156
|
+
|
|
157
|
+
### 6.1 修改模板字段
|
|
158
|
+
|
|
159
|
+
修改位置:
|
|
160
|
+
|
|
161
|
+
- `.opencode/commands/report-ai-issue.md`
|
|
162
|
+
- `tools/ohai-report/schemas/report_issue.schema.json`
|
|
163
|
+
|
|
164
|
+
通常不需要修改 `schema.py`、`payload.py` 或 sink。新增非固定参数可通过 CLI 的 `--field key=value`、`--issue-json` 或 `--issue-file` 传入。
|
|
165
|
+
|
|
166
|
+
例如新增 `scenario`:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"scenario": {
|
|
171
|
+
"type": "string",
|
|
172
|
+
"required": false,
|
|
173
|
+
"enum": ["HDC/设备操作", "CI 失败分析", "代码生成", "其他"],
|
|
174
|
+
"description": "Issue scenario"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
OpenCode command 中增加:
|
|
180
|
+
|
|
181
|
+
```text
|
|
182
|
+
- scenario: HDC/设备操作 / CI 失败分析 / 代码生成 / 其他
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
调用 CLI 时增加:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
--field scenario="<scenario>"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 6.2 增加 GitCode/Jira/DTS 后端
|
|
192
|
+
|
|
193
|
+
新增或完善:
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
tools/ohai-report/ohai_report/sinks/gitcode.py
|
|
197
|
+
tools/ohai-report/ohai_report/sinks/jira.py
|
|
198
|
+
tools/ohai-report/ohai_report/sinks/dts.py
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
建议扩展 CLI:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
ohai-report create --sink local
|
|
205
|
+
ohai-report create --sink gitcode
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Agent command 不需要知道 sink 细节。
|
|
209
|
+
|
|
210
|
+
### 6.3 增加新的 Agent
|
|
211
|
+
|
|
212
|
+
保持 `ohai-report` 不变,只新增适配器:
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
.claude/commands/report-ai-issue.md
|
|
216
|
+
.codex/report adapter
|
|
217
|
+
other-agent adapter
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
这些适配器都生成同一套模板字段并调用同一个 CLI/API。
|
|
221
|
+
|
|
222
|
+
### 6.4 接入 Langfuse API
|
|
223
|
+
|
|
224
|
+
如果后续需要从 Langfuse 自动生成 URL 或校验 trace 存在,建议新增:
|
|
225
|
+
|
|
226
|
+
```text
|
|
227
|
+
tools/ohai-report/ohai_report/observability/langfuse.py
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
不要把 Langfuse 查询逻辑写进 command prompt 或 sink。
|
|
231
|
+
|
|
232
|
+
## 7. 污染控制策略
|
|
233
|
+
|
|
234
|
+
OpenCode 主上下文污染控制由三层保证:
|
|
235
|
+
|
|
236
|
+
- `subtask: true`:模板化在子任务里完成。
|
|
237
|
+
- command 约束:禁止读取日志、diff、源码、transcript。
|
|
238
|
+
- CLI quiet 输出:只返回 JSON 或 issue id。
|
|
239
|
+
|
|
240
|
+
预期主上下文只保留:
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
用户:/report-ai-issue xxx
|
|
244
|
+
助手:已上报:AI-DEV-xxx
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## 8. 安全与隐私
|
|
248
|
+
|
|
249
|
+
默认禁止进入 Issue payload 的内容:
|
|
250
|
+
|
|
251
|
+
- 完整日志
|
|
252
|
+
- 完整 transcript
|
|
253
|
+
- 完整 diff
|
|
254
|
+
- 源码片段
|
|
255
|
+
- 工具 stdout/stderr
|
|
256
|
+
- token、私钥、账号、设备敏感信息
|
|
257
|
+
|
|
258
|
+
允许进入 Issue payload 的内容:
|
|
259
|
+
|
|
260
|
+
- 用户主动描述的问题
|
|
261
|
+
- LLM 模板化字段
|
|
262
|
+
- session_id / trace_id / langfuse_url
|
|
263
|
+
- 用户和团队元信息
|
|
264
|
+
- repo / branch / commit / cwd
|
|
265
|
+
|
|
266
|
+
## 9. 测试建议
|
|
267
|
+
|
|
268
|
+
每次修改 CLI 后至少运行:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
python -m py_compile tools/ohai-report/ohai_report.py
|
|
272
|
+
python -m py_compile tools/ohai-report/ohai_report/*.py
|
|
273
|
+
python tools/ohai-report/ohai_report.py metadata update --source opencode --json
|
|
274
|
+
python tools/ohai-report/ohai_report.py create --source opencode --title "测试问题" --category "其他" --summary "验证上报链路" --expected-behavior "生成 payload" --actual-behavior "生成 JSON" --severity P3 --user-description "测试" --metadata auto --quiet --json
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
每次修改 schema 后,再运行:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
python tools/ohai-report/ohai_report.py create --source opencode --issue-json "{\"title\":\"测试问题\",\"category\":\"其他\",\"summary\":\"验证上报链路\",\"expected_behavior\":\"生成 payload\",\"actual_behavior\":\"生成 JSON\",\"severity\":\"P3\",\"user_description\":\"测试\"}" --metadata auto --quiet --json
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Windows/脚本环境建议优先验证 `--issue-file`,避免 shell 引号差异:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
python tools/ohai-report/ohai_report.py create --source opencode --issue-file .ohai-report/issue-input.json --metadata auto --quiet --json
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
验证 `.ohai-report/latest.json` 中:
|
|
290
|
+
|
|
291
|
+
- `privacy.uploads_logs` 为 `false`
|
|
292
|
+
- `privacy.uploads_diff` 为 `false`
|
|
293
|
+
- `privacy.uploads_transcript` 为 `false`
|
|
294
|
+
- payload 中没有日志正文
|
|
295
|
+
|
|
296
|
+
## 10. 当前状态
|
|
297
|
+
|
|
298
|
+
已实现:
|
|
299
|
+
|
|
300
|
+
- OpenCode command adapter
|
|
301
|
+
- OpenCode plugin adapter
|
|
302
|
+
- 模块化 `ohai-report` CLI
|
|
303
|
+
- 独立问题模板 schema
|
|
304
|
+
- 本地 JSON sink
|
|
305
|
+
- metadata auto
|
|
306
|
+
- Langfuse 索引字段
|
|
307
|
+
|
|
308
|
+
未实现:
|
|
309
|
+
|
|
310
|
+
- GitCode/Jira/DTS sink
|
|
311
|
+
- Langfuse API 自动查询
|
|
312
|
+
- 组织级用户映射
|
|
313
|
+
- 单元测试套件
|