oh-aicoding-tool 0.1.2 → 0.1.5

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.
Files changed (55) hide show
  1. package/README.md +79 -80
  2. package/bin/cli.js +257 -384
  3. package/package.json +27 -55
  4. package/CODEX_LANGFUSE_PLAN.md +0 -62
  5. package/bin/langfuse-cli.js +0 -718
  6. package/codex_langfuse_notify.py +0 -591
  7. package/langfuse_hook.py +0 -603
  8. package/opencode-ohai-report/.claude/commands/report-ai-issue.md +0 -60
  9. package/opencode-ohai-report/.opencode/commands/report-ai-issue.md +0 -30
  10. package/opencode-ohai-report/.opencode/plugins/oh-ai-report.ts +0 -569
  11. package/opencode-ohai-report/README.md +0 -45
  12. package/opencode-ohai-report/bin/cli.js +0 -421
  13. package/opencode-ohai-report/docs/opencode-ai-issue-collection-architecture.md +0 -313
  14. package/opencode-ohai-report/docs/opencode-ai-issue-collection-best-practices.md +0 -476
  15. package/opencode-ohai-report/docs/opencode-ai-issue-collection-phase1-summary.md +0 -405
  16. package/opencode-ohai-report/examples/issue_output.json +0 -4
  17. package/opencode-ohai-report/package.json +0 -40
  18. package/opencode-ohai-report/scripts/claude_report_hook.py +0 -257
  19. package/opencode-ohai-report/scripts/create_issue.py +0 -34
  20. package/opencode-ohai-report/scripts/install-claude-plugin.ps1 +0 -254
  21. package/opencode-ohai-report/scripts/install-opencode-plugin.ps1 +0 -264
  22. package/opencode-ohai-report/scripts/install-opencode-plugin.sh +0 -218
  23. package/opencode-ohai-report/scripts/merge-claude-settings.py +0 -99
  24. package/opencode-ohai-report/tools/ohai-report/README.md +0 -151
  25. package/opencode-ohai-report/tools/ohai-report/examples/issue-input.json +0 -26
  26. package/opencode-ohai-report/tools/ohai-report/ohai_report/__init__.py +0 -5
  27. package/opencode-ohai-report/tools/ohai-report/ohai_report/__main__.py +0 -9
  28. package/opencode-ohai-report/tools/ohai-report/ohai_report/cli.py +0 -319
  29. package/opencode-ohai-report/tools/ohai-report/ohai_report/git_context.py +0 -32
  30. package/opencode-ohai-report/tools/ohai-report/ohai_report/gitcode_defaults.py +0 -14
  31. package/opencode-ohai-report/tools/ohai-report/ohai_report/issue_markdown.py +0 -313
  32. package/opencode-ohai-report/tools/ohai-report/ohai_report/metadata.py +0 -360
  33. package/opencode-ohai-report/tools/ohai-report/ohai_report/observability/__init__.py +0 -1
  34. package/opencode-ohai-report/tools/ohai-report/ohai_report/observability/langfuse.py +0 -38
  35. package/opencode-ohai-report/tools/ohai-report/ohai_report/payload.py +0 -64
  36. package/opencode-ohai-report/tools/ohai-report/ohai_report/schema.py +0 -80
  37. package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/__init__.py +0 -1
  38. package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/base.py +0 -15
  39. package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/gitcode.py +0 -405
  40. package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/local.py +0 -21
  41. package/opencode-ohai-report/tools/ohai-report/ohai_report/sinks/webhook.py +0 -354
  42. package/opencode-ohai-report/tools/ohai-report/ohai_report/webhook_defaults.py +0 -9
  43. package/opencode-ohai-report/tools/ohai-report/ohai_report/workspace.py +0 -61
  44. package/opencode-ohai-report/tools/ohai-report/ohai_report.py +0 -10
  45. package/opencode-ohai-report/tools/ohai-report/schemas/report_issue.schema.json +0 -166
  46. package/scripts/codex-langfuse-check.mjs +0 -101
  47. package/scripts/codex-langfuse-setup.mjs +0 -181
  48. package/scripts/langfuse-check.mjs +0 -90
  49. package/scripts/langfuse-setup.mjs +0 -278
  50. package/scripts/opencode-langfuse-check.mjs +0 -94
  51. package/scripts/opencode-langfuse-run.mjs +0 -96
  52. package/scripts/opencode-langfuse-setup.mjs +0 -478
  53. package/scripts/resolve-opencode-cli.mjs +0 -58
  54. package/setup-langfuse.bat +0 -163
  55. package/setup-langfuse.sh +0 -130
@@ -1,476 +0,0 @@
1
- # OpenCode 问题采集最佳方案
2
-
3
- ## 1. 文档迁移分析
4
-
5
- 现有 `claude-ai-issue-collection-best-practices.md` 的核心思想可以复用,但不能原样照搬到 OpenCode。
6
-
7
- Claude Code 方案的重点是:
8
-
9
- - 用 `/report-ai-issue` 做入口。
10
- - 当前 LLM 只做轻量模板化。
11
- - 日志和完整会话交给 Langfuse。
12
- - Issue 中只保存 `session_id`、`trace_id`、`langfuse_url`、用户信息和问题模板。
13
- - 通过 `ohai-report` CLI/API 统一落库。
14
-
15
- 迁移到 OpenCode 后,需要调整的点是:
16
-
17
- | 能力 | Claude Code | OpenCode |
18
- | --- | --- | --- |
19
- | 用户入口 | `.claude/commands` | `.opencode/commands` 或 `opencode.jsonc` 的 `command` |
20
- | 降低主上下文污染 | Hook 拦截或短事务命令 | 优先使用 `subtask: true` 或短事务命令 |
21
- | 自动补元信息 | Claude Hook | OpenCode Plugin 或 `ohai-report --metadata auto` |
22
- | 自定义工具 | Claude tool/MCP | OpenCode custom tool 或 Plugin tool |
23
- | 日志来源 | Langfuse | Langfuse |
24
- | Issue 落库 | `ohai-report` | 同一套 `ohai-report` |
25
-
26
- 最终结论:
27
-
28
- > OpenCode 不需要重新开发一套问题采集系统,只需要实现 OpenCode adapter。通用核心仍然是 `ReportPayload + ohai-report + Langfuse 索引 + Issue 落库`。
29
-
30
- ## 2. OpenCode 最佳架构
31
-
32
- 推荐架构:
33
-
34
- ```text
35
- 开发者输入
36
- /report-ai-issue <一句话问题描述>
37
-
38
- OpenCode
39
- Custom Command
40
- - 读取 $ARGUMENTS
41
- - 当前 LLM 只做轻量模板化
42
- - 不读取完整日志、diff、源码、transcript
43
- - 不做长根因分析
44
- - 调用 ohai-report create --metadata auto --quiet --json
45
-
46
- OpenCode Plugin,可选
47
- - 监听 session / command / tool 事件
48
- - 补齐 session_id / trace_id / user_id / cwd / repo
49
- - 提供 report_ai_issue custom tool
50
- - 不上传日志正文
51
-
52
- Langfuse
53
- - 保存完整日志、trace、session、工具调用
54
-
55
- Issue 系统
56
- - 保存模板化问题
57
- - 保存 session_id / trace_id / langfuse_url
58
- - 保存用户和环境元信息
59
- ```
60
-
61
- 一句话原则:
62
-
63
- > OpenCode 只负责把用户问题模板化并提交索引;完整日志在 Langfuse,Issue 里不搬运日志。
64
-
65
- ## 3. 为什么 OpenCode 适合这样做
66
-
67
- ### 3.1 Custom Commands 适合作为入口
68
-
69
- OpenCode 支持自定义 commands。可以通过 `.opencode/commands/*.md` 或 `opencode.jsonc` 的 `command` 配置创建命令。命令支持 `$ARGUMENTS`,适合实现:
70
-
71
- ```text
72
- /report-ai-issue hdc 远程服务器无法连接本地开发板
73
- ```
74
-
75
- 这个入口足够自然,不需要用户离开 OpenCode。
76
-
77
- ### 3.2 `subtask: true` 适合降低污染
78
-
79
- OpenCode command 支持 `subtask` 配置。官方说明里,`subtask: true` 可以强制以 subagent 方式执行,用于减少 primary context 污染。
80
-
81
- 因此,OpenCode 侧的最低污染方案不是“命令级阻断”,而是:
82
-
83
- ```text
84
- /report-ai-issue
85
- -> subtask 执行轻量模板化
86
- -> 调用 ohai-report
87
- -> 主会话只收到 issue_id
88
- ```
89
-
90
- 这和 Claude Code 的 `UserPromptExpansion Hook + decision:block` 思路不同,但目标一致:减少主开发上下文污染。
91
-
92
- ### 3.3 Plugin 适合补元信息,不适合承载全部业务
93
-
94
- OpenCode Plugin 可以监听 `command.executed`、`session.created`、`session.error`、`session.idle`、`tool.execute.before/after`、`tui.command.execute` 等事件,也可以提供 custom tool。
95
-
96
- 但在当前需求里,日志已经由 Langfuse 采集,Issue 不上传完整日志。因此 Plugin 不需要保存大量现场,只需要做轻量 metadata:
97
-
98
- - 当前 OpenCode session 标识。
99
- - Langfuse trace_id 或 trace URL。
100
- - user_id / team。
101
- - cwd / repo / branch / commit。
102
- - source = `opencode`。
103
-
104
- ## 4. 上报内容设计
105
-
106
- Issue 上报 payload 建议统一为:
107
-
108
- ```json
109
- {
110
- "source": "opencode",
111
- "agent": "opencode",
112
- "session_id": "opencode-session-xxx",
113
- "trace_id": "langfuse-trace-xxx",
114
- "langfuse_url": "https://langfuse.example.com/project/xxx/traces/xxx",
115
- "user": {
116
- "id": "user001",
117
- "name": "zhangsan",
118
- "team": "OpenHarmony AI"
119
- },
120
- "issue": {
121
- "title": "HDC 远程服务器无法连接本地开发板",
122
- "category": "环境问题",
123
- "summary": "远程 OpenCode 无法访问本地 HDC 设备",
124
- "expected_behavior": "能够定位本地设备访问方案或给出明确配置提示",
125
- "actual_behavior": "无法发现或连接本地开发板",
126
- "severity": "P2",
127
- "user_description": "hdc 远程服务器无法连接本地开发板"
128
- },
129
- "context": {
130
- "repo": "openharmony/xxx",
131
- "branch": "feature/report",
132
- "commit": "abcdef",
133
- "cwd": "/workspace/project"
134
- }
135
- }
136
- ```
137
-
138
- 不上传:
139
-
140
- - 完整日志
141
- - 完整 transcript
142
- - 完整 diff
143
- - 源码片段
144
- - 工具 stdout/stderr
145
- - token、私钥、账号信息
146
-
147
- 完整排查链路通过 `session_id` / `trace_id` / `langfuse_url` 去 Langfuse 关联。
148
-
149
- ## 5. OpenCode Command 方案
150
-
151
- 项目级命令:
152
-
153
- ```text
154
- .opencode/commands/report-ai-issue.md
155
- ```
156
-
157
- 推荐内容:
158
-
159
- ```markdown
160
- ---
161
- description: 上报 AI 辅助开发问题
162
- agent: build
163
- subtask: true
164
- ---
165
-
166
- 你是一个短事务问题上报入口。请把用户描述模板化后提交,不要继续参与当前开发任务。
167
-
168
- 严格要求:
169
- 1. 只基于用户输入生成字段,不读取完整日志、diff、源码、transcript。
170
- 2. 不分析复杂根因,不展开长解释。
171
- 3. 不追问用户。
172
- 4. 不在当前会话中输出完整 Issue 正文。
173
- 5. 调用 `ohai-report create --source opencode --metadata auto --quiet --json`。
174
- 6. 最后只返回一行:`已上报:<issue_id>`。
175
-
176
- 用户描述:
177
- $ARGUMENTS
178
-
179
- 请生成以下字段:
180
- - title: 20 字以内
181
- - category: 模型输出错误 / 工具调用失败 / Skill 缺陷 / 上下文缺失 / 环境问题 / 其他
182
- - summary: 50 字以内
183
- - expected_behavior: 50 字以内
184
- - actual_behavior: 50 字以内
185
- - severity: P0 / P1 / P2 / P3
186
-
187
- 然后执行:
188
-
189
- ohai-report create \
190
- --source opencode \
191
- --title "<title>" \
192
- --category "<category>" \
193
- --summary "<summary>" \
194
- --expected-behavior "<expected_behavior>" \
195
- --actual-behavior "<actual_behavior>" \
196
- --severity "<severity>" \
197
- --user-description "$ARGUMENTS" \
198
- --metadata auto \
199
- --quiet \
200
- --json
201
- ```
202
-
203
- 说明:
204
-
205
- - `subtask: true` 用来降低对主上下文的污染。
206
- - 不使用 `!command` 注入日志,因为 shell output 会进入 prompt。
207
- - 不使用 `@file` 引用日志或源码文件。
208
- - `ohai-report` 必须 quiet,只返回结构化结果。
209
-
210
- ## 6. opencode.jsonc 配置方案
211
-
212
- 如果不想放 Markdown 文件,也可以写在 `opencode.jsonc`:
213
-
214
- ```jsonc
215
- {
216
- "$schema": "https://opencode.ai/config.json",
217
- "command": {
218
- "report-ai-issue": {
219
- "description": "上报 AI 辅助开发问题",
220
- "agent": "build",
221
- "subtask": true,
222
- "template": "你是一个短事务问题上报入口。只基于用户输入模板化问题,不读取日志、diff、源码或 transcript。用户描述:$ARGUMENTS。生成 title/category/summary/expected_behavior/actual_behavior/severity,然后调用 ohai-report create --source opencode --metadata auto --quiet --json,最后只返回一行:已上报 <issue_id>。"
223
- }
224
- }
225
- }
226
- ```
227
-
228
- 项目级团队推荐使用 Markdown 文件,便于版本管理和审查。
229
-
230
- ## 7. OpenCode Plugin 方案
231
-
232
- Plugin 不是第一阶段必需项,但适合做 metadata 自动补齐。
233
-
234
- 项目级插件路径:
235
-
236
- ```text
237
- .opencode/plugins/oh-ai-report.ts
238
- ```
239
-
240
- 示意:
241
-
242
- ```ts
243
- import type { Plugin } from "@opencode-ai/plugin"
244
-
245
- export const OHAIReportPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
246
- return {
247
- event: async ({ event }) => {
248
- if (
249
- event.type === "session.created" ||
250
- event.type === "session.updated" ||
251
- event.type === "command.executed"
252
- ) {
253
- await $`ohai-report metadata update --source opencode --cwd ${directory}`
254
- }
255
- }
256
- }
257
- }
258
- ```
259
-
260
- 这个插件只做:
261
-
262
- - 写入或刷新本地 metadata。
263
- - 关联 OpenCode session 和 Langfuse trace。
264
- - 不保存完整日志。
265
- - 不自动创建 Issue。
266
-
267
- ## 8. Custom Tool 方案
268
-
269
- 如果希望让 OpenCode agent 显式调用工具,可以在 Plugin 中提供 `report_ai_issue`。
270
-
271
- 示意:
272
-
273
- ```ts
274
- import type { Plugin } from "@opencode-ai/plugin"
275
- import { tool } from "@opencode-ai/plugin"
276
-
277
- export const OHAIReportPlugin: Plugin = async ({ $, directory }) => {
278
- return {
279
- tool: {
280
- report_ai_issue: tool({
281
- description: "Report an AI development issue. Do not include logs; logs are linked through Langfuse.",
282
- args: {
283
- title: tool.schema.string(),
284
- category: tool.schema.string(),
285
- summary: tool.schema.string(),
286
- expected_behavior: tool.schema.string(),
287
- actual_behavior: tool.schema.string(),
288
- severity: tool.schema.string().optional(),
289
- user_description: tool.schema.string()
290
- },
291
- async execute(args) {
292
- const result = await $`ohai-report create \
293
- --source opencode \
294
- --title ${args.title} \
295
- --category ${args.category} \
296
- --summary ${args.summary} \
297
- --expected-behavior ${args.expected_behavior} \
298
- --actual-behavior ${args.actual_behavior} \
299
- --severity ${args.severity ?? "P2"} \
300
- --user-description ${args.user_description} \
301
- --metadata auto \
302
- --quiet \
303
- --json`
304
-
305
- return result.text()
306
- }
307
- })
308
- }
309
- }
310
- }
311
- ```
312
-
313
- 这种方式适合跨命令复用,但第一阶段可以先不做。
314
-
315
- ## 9. `ohai-report` CLI 职责
316
-
317
- OpenCode adapter 不应该承担上报系统的核心逻辑。核心逻辑放在 `ohai-report`:
318
-
319
- ```bash
320
- ohai-report create \
321
- --source opencode \
322
- --title "HDC 远程服务器无法连接本地开发板" \
323
- --category "环境问题" \
324
- --summary "远程 OpenCode 无法访问本地 HDC 设备" \
325
- --expected-behavior "能够定位本地设备访问方案或给出明确配置提示" \
326
- --actual-behavior "无法发现或连接本地开发板" \
327
- --severity "P2" \
328
- --user-description "hdc 远程服务器无法连接本地开发板" \
329
- --metadata auto \
330
- --quiet \
331
- --json
332
- ```
333
-
334
- `--metadata auto` 负责补齐:
335
-
336
- - `session_id`
337
- - `trace_id`
338
- - `langfuse_url`
339
- - `user_id`
340
- - `team`
341
- - `cwd`
342
- - `repo`
343
- - `branch`
344
- - `commit`
345
-
346
- CLI 输出:
347
-
348
- ```json
349
- {
350
- "issue_id": "AI-DEV-123",
351
- "trace_id": "langfuse-trace-xxx",
352
- "langfuse_url": "https://langfuse.example.com/project/xxx/traces/xxx"
353
- }
354
- ```
355
-
356
- ## 10. 污染控制
357
-
358
- OpenCode 的污染控制重点:
359
-
360
- | 控制点 | 做法 |
361
- | --- | --- |
362
- | 不搬运日志 | 不使用 `!command` 注入日志,不读取日志文件 |
363
- | 不搬运源码 | 不使用 `@file` 引用源码或 diff |
364
- | 不长分析 | command 中明确禁止根因长分析 |
365
- | 降低主上下文影响 | 配置 `subtask: true` |
366
- | 输出极简 | 只返回 `已上报:AI-DEV-123` |
367
- | 完整现场回溯 | 通过 Langfuse 的 `trace_id` / `session_id` |
368
-
369
- 污染程度预估:
370
-
371
- ```text
372
- 低污染:
373
- /report-ai-issue + subtask + quiet CLI
374
-
375
- 中污染:
376
- /report-ai-issue + 当前主 agent 轻量模板化
377
-
378
- 高污染:
379
- command 读取日志、diff、源码,并在主会话生成完整 Issue 正文
380
- ```
381
-
382
- ## 11. 落地阶段
383
-
384
- ### 第一阶段:最小闭环
385
-
386
- - 创建 `.opencode/commands/report-ai-issue.md`。
387
- - 使用 `subtask: true`。
388
- - 调用 `ohai-report create --source opencode --metadata auto --quiet --json`。
389
- - Issue 只保存模板字段和 Langfuse 索引。
390
-
391
- ### 第二阶段:metadata 自动补齐
392
-
393
- - 增加 `.opencode/plugins/oh-ai-report.ts`。
394
- - 监听 `session.created`、`session.updated`、`command.executed`。
395
- - 写入本地 metadata。
396
- - 让 `ohai-report --metadata auto` 自动读取。
397
-
398
- ### 第三阶段:custom tool
399
-
400
- - 在 Plugin 中提供 `report_ai_issue`。
401
- - 让 agent 可以显式调用工具。
402
- - 统一复用 `ohai-report`。
403
-
404
- ### 第四阶段:平台化
405
-
406
- - 接入 GitCode/Jira/DTS。
407
- - 接入 Langfuse trace/session 跳转。
408
- - 增加用户、团队、场景统计。
409
- - 支持 Claude Code、OpenCode、Codex 多 adapter。
410
-
411
- ## 12. 与 Claude Code 方案的差异
412
-
413
- | 项目 | Claude Code | OpenCode |
414
- | --- | --- | --- |
415
- | 最低污染机制 | `UserPromptExpansion Hook + decision:block` | `subtask: true + quiet CLI` |
416
- | 第一阶段推荐 | 短事务 command 或 Hook 拦截 | 短事务 command |
417
- | 元信息补齐 | Hook | Plugin 或 `metadata auto` |
418
- | 自定义工具 | MCP/tool | Plugin custom tool |
419
- | 日志链路 | Langfuse | Langfuse |
420
- | 核心上报 | `ohai-report` | `ohai-report` |
421
-
422
- OpenCode 侧不建议把第一阶段做得太重。先用 command 跑通体验,再补 Plugin。
423
-
424
- ## 13. 最终建议
425
-
426
- OpenCode 的最佳问题采集方案是:
427
-
428
- ```text
429
- /report-ai-issue <用户一句话问题>
430
- -> OpenCode custom command
431
- -> subtask 轻量模板化
432
- -> ohai-report --metadata auto --quiet
433
- -> Issue 保存问题模板 + user + session_id + trace_id + langfuse_url
434
- -> 完整日志从 Langfuse 查询
435
- ```
436
-
437
- 不要为 OpenCode 重新开发完整上报系统。只需要做一个薄 adapter,复用统一的:
438
-
439
- - `ReportPayload`
440
- - `ohai-report` CLI/API
441
- - Langfuse trace/session 索引
442
- - GitCode/Jira/DTS 落库逻辑
443
-
444
- ## 14. 参考依据
445
-
446
- - OpenCode Commands: https://opencode.ai/docs/commands
447
- - OpenCode Plugins: https://opencode.ai/docs/plugins
448
- - OpenCode Custom Tools: https://opencode.ai/docs/custom-tools/
449
- - Claude Code 迁移源文档:[claude-ai-issue-collection-best-practices.md](../claude-ai-issue-collection-best-practices.md)
450
-
451
- ## 15. 当前第一版实现
452
-
453
- 本目录已按第一阶段落地了一个本地可运行版本:
454
-
455
- | 文件 | 作用 |
456
- | --- | --- |
457
- | `.opencode/commands/report-ai-issue.md` | OpenCode `/report-ai-issue` 短事务命令入口 |
458
- | `.opencode/plugins/oh-ai-report.ts` | 可选 OpenCode plugin,刷新 metadata 并提供 `report_ai_issue` custom tool |
459
- | `tools/ohai-report/ohai_report.py` | 本地 `ohai-report` CLI 原型 |
460
- | `tools/ohai-report/README.md` | CLI 使用说明 |
461
- | `.gitignore` | 忽略本地 `.ohai-report/` 运行产物 |
462
-
463
- 当前版本能力:
464
-
465
- - 支持 `create` 创建本地 issue payload。
466
- - 支持 `metadata update` 写入本地 metadata。
467
- - 支持 `--metadata auto` 从 metadata、环境变量和 git 上下文补齐字段。
468
- - 输出 `.ohai-report/issues/<issue_id>.json`。
469
- - 不采集、不上传完整日志、diff、transcript、源码或工具输出。
470
-
471
- 当前版本仍未接入:
472
-
473
- - GitCode/Jira/DTS 真实 Issue API。
474
- - Langfuse API 自动反查。
475
- - 组织级用户/团队映射。
476
- - 去重、归属推荐、质量评分。