@ranger1/dx 0.1.116 → 0.1.118

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.116",
3
+ "version": "0.1.118",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -37,7 +37,6 @@ By the end, produce all of these or clearly state the blocker:
37
37
  | Issue branch | `codex/docs/<issue-id>-<slug>` for docs-only handoff, or matching repo convention |
38
38
  | Commit | Conventional commit ending with `Refs: #<issue-id>` |
39
39
  | Push | Branch pushed with upstream |
40
- | Pull request | PR created or updated with the repo PR template, non-empty body, linked issue, doc paths, verification evidence, and read-back validation |
41
40
  | Issue comment | Comment linking branch, commit, spec, plan, and handoff, plus the same project-manager-style assignment block from the final answer |
42
41
  | Final answer | Short status plus a copyable project-manager-style assignment block |
43
42
 
@@ -144,7 +143,7 @@ This is separate from the implementation plan. It is the short assignment packet
144
143
  - implementation order summary
145
144
  - top risks and invariants
146
145
  - required verification commands
147
- - PR expectations and acceptance checklist pointer
146
+ - delivery boundary and acceptance checklist pointer
148
147
 
149
148
  Run placeholder scan over all docs. Placeholders that must be filled before commit, such as issue id after creation, must not remain.
150
149
 
@@ -217,84 +216,11 @@ rtk git push -u origin <branch>
217
216
 
218
217
  Comment on the issue with branch, commit, spec path, plan path, handoff path, and the copyable project-manager-style assignment block from the final answer. This issue comment is mandatory; do not finish with only a local final answer.
219
218
 
220
- ### 10. Create or update the pull request
219
+ ### 10. Do not create a pull request
221
220
 
222
- If the user asks for a PR, or repo convention expects a PR for the handoff branch, create or update it before the final answer.
221
+ This skill stops after the handoff docs are committed, pushed to the remote issue branch, and linked from the GitHub issue comment. Do not create or update a PR for the docs-only handoff branch as part of this workflow, even when the repository's normal implementation flow expects PRs.
223
222
 
224
- PR body must be written to a temporary markdown file and passed with `--body-file "$pr_body_file"`. Never use `gh pr create --body-file -`, `gh pr edit --body-file -`, or `--body "multi-line text"` for PR content. Do not trust `ok` or a returned URL as proof that the body was saved; only trust a read-back from `gh pr view --json body`.
225
-
226
- Use the repository PR template. When this repo's template is the standard git workflow template, the body must include all of these headings exactly:
227
-
228
- - `## 变更目的`
229
- - `## 主要改动和解决的问题`
230
- - `## 遗留的问题`
231
- - `## 已做的验证`
232
- - `## PR 遗留未做的`
233
- - `## 关联`
234
-
235
- The body must also include:
236
-
237
- - `Closes: #<issue-id>`
238
- - branch name
239
- - commit sha or subject
240
- - spec path
241
- - plan path
242
- - handoff path
243
- - verification commands and results, or an explicit docs-only note
244
-
245
- Example shape:
246
-
247
- ```bash
248
- pr_body_file="$(mktemp "${TMPDIR:-/tmp}/handoff-pr-body.XXXXXX.md")"
249
- cat > "$pr_body_file" <<'MSG'
250
- ## 变更目的
251
- <why this handoff exists and which approved design it packages>
252
-
253
- ## 主要改动和解决的问题
254
- - 新增设计文档:`<spec-path>`
255
- - 新增实施计划:`<plan-path>`
256
- - 新增交接文档:`<handoff-path>`
257
- - 分支:`<branch>`
258
- - 提交:`<sha> <subject>`
259
-
260
- ## 遗留的问题
261
- - 无,或列出明确遗留风险和处理建议。
262
-
263
- ## 已做的验证
264
- - `rtk git diff --cached --check`:通过
265
- - `rtk rg -n "TBD|TODO|待定|占位|\\.\\.\\." <spec-path> <plan-path> <handoff-path>`:无真实占位
266
- - 文档交付,无需运行构建或测试。
267
-
268
- ## PR 遗留未做的
269
- - 无,或列出需要后续实现 PR 完成的事项。
270
-
271
- ## 关联
272
- Closes: #<issue-id>
273
- MSG
274
-
275
- pr_url="$(rtk gh pr create --base main --title 'docs: add <topic> handoff' --body-file "$pr_body_file")"
276
- pr_number="$(rtk gh pr view "$pr_url" --json number --jq '.number')"
277
- pr_body="$(rtk gh pr view "$pr_number" --json body --jq '.body')"
278
- test -n "$pr_body"
279
- for heading in \
280
- "## 变更目的" \
281
- "## 主要改动和解决的问题" \
282
- "## 遗留的问题" \
283
- "## 已做的验证" \
284
- "## PR 遗留未做的" \
285
- "## 关联"; do
286
- printf '%s\n' "$pr_body" | grep -F "$heading" >/dev/null
287
- done
288
- printf '%s\n' "$pr_body" | grep -F "Closes: #<issue-id>" >/dev/null
289
- printf '%s\n' "$pr_body" | grep -F "<branch>" >/dev/null
290
- printf '%s\n' "$pr_body" | grep -F "<sha>" >/dev/null
291
- printf '%s\n' "$pr_body" | grep -F "<spec-path>" >/dev/null
292
- printf '%s\n' "$pr_body" | grep -F "<plan-path>" >/dev/null
293
- printf '%s\n' "$pr_body" | grep -F "<handoff-path>" >/dev/null
294
- rm -f "$pr_body_file"
295
- ```
296
-
297
- If a PR already exists, use the same temp-file path with `rtk gh pr edit <pr-number> --body-file "$pr_body_file"`, then run the same read-back validation. If any heading, issue link, doc path, branch, commit, or verification evidence is missing, fix the temp body file, edit again, and read back again before continuing.
223
+ If the user explicitly asks for a PR, treat that as a separate follow-up workflow after this handoff is complete.
298
224
 
299
225
  ### 11. Final verification
300
226
 
@@ -308,8 +234,6 @@ rtk git rev-parse --abbrev-ref --symbolic-full-name @{u}
308
234
 
309
235
  Report actual state. If no tests/builds were run because this is docs-only, say that.
310
236
 
311
- If a PR was created or updated, read back the PR body and verify it is non-empty, follows the repo template headings, includes `Closes: #<issue-id>`, and contains the branch, commit, spec path, plan path, handoff path, and verification evidence. If `gh pr create` or `gh pr edit` reported success but read-back is empty or incomplete, repair the PR with a temp body file and read it back again before claiming completion.
312
-
313
237
  Read back the issue comments and verify that the latest handoff comment contains the branch, commit, spec path, plan path, handoff path, and the same assignment block shown in the final answer. If `gh issue comment` failed, the comment is missing, or the readback does not match the final assignment block, fix that before claiming completion.
314
238
 
315
239
  ## Final Answer Template
@@ -320,7 +244,6 @@ Keep it short, then include this copyable block:
320
244
  已准备好交接资料:
321
245
 
322
246
  - Issue:#<issue-id> <issue-url>
323
- - PR:#<pr-id> <pr-url>
324
247
  - 分支:`<branch>`
325
248
  - 提交:`<sha> <subject>`
326
249
  - 设计文档:`<spec-path>`
@@ -346,7 +269,7 @@ Keep it short, then include this copyable block:
346
269
  - `<verification-command-2>`
347
270
  - `<verification-command-3>`
348
271
 
349
- 验收标准以 Issue #<issue-id> 的 checklist 为准。提 PR 时请逐条对应验收标准,并贴出验证命令结果;如遇到与设计文档冲突的实现细节,先在 Issue 中同步风险和建议处理方式。
272
+ 验收标准以 Issue #<issue-id> 的 checklist 为准。实现过程中如遇到与设计文档冲突的细节,先在 Issue 中同步风险和建议处理方式。
350
273
  ```
351
274
 
352
275
  In Codex app, after successful git actions, also emit the app directives for branch creation, staging, commit, and push.
@@ -363,7 +286,5 @@ In Codex app, after successful git actions, also emit the app directives for bra
363
286
  - Writing a handoff that says “add tests” without exact files, behaviors, and commands.
364
287
  - Forgetting the issue comment, leaving the receiving engineer to hunt for branch and docs.
365
288
  - Posting an issue comment with links only, but omitting the project-manager-style assignment block.
366
- - Creating or editing a PR with `--body-file -` and assuming the body was saved.
367
- - Trusting `gh pr create`, `gh pr edit`, or `ok` without reading back `gh pr view --json body`.
368
- - Creating a PR whose body is empty, misses the repo template headings, omits `Closes: #<issue-id>`, or lacks doc paths and verification evidence.
289
+ - Creating or updating a PR for the docs-only handoff branch instead of stopping after commit, push, and issue comment.
369
290
  - Final answer lists artifacts but omits the copyable project-manager-style assignment block.
@@ -7,76 +7,105 @@ description: 仅在用户显式调用 $online-debug-guard 或明确要求使用
7
7
 
8
8
  ## 概览
9
9
 
10
- 执行在线调试前先做硬性门禁,未通过即停止。仅在门禁通过后再进行排查动作,默认使用只读方式获取信息。
10
+ 在线调试先确认环境,再按环境选择门禁。只有 `production` 需要检查当前是否为 Plan 模式;其他环境不做 Plan 模式门禁。
11
11
 
12
- ## 执行流程(必须按顺序)
12
+ 调试默认只读取证。需要改变远程状态、数据状态或进程状态时,先停下并取得用户明确授权。
13
13
 
14
- 1. 识别目标环境
15
- 2. 校验协作模式与环境文件
16
- 3. 门禁通过后执行调试
14
+ ## 执行流程
17
15
 
18
- 任一步失败都必须立即终止,不得继续后续步骤。
16
+ 1. 识别目标环境。
17
+ 2. 如果目标环境是 `production`,校验当前会话是否为 Plan 模式。
18
+ 3. 使用 SSH config 连接远程机器。
19
+ 4. 通过远程运行时、pm2、shared 环境变量目录和当前代码目录取证。
20
+ 5. 汇总目标环境、门禁结果、关键证据和下一步建议。
19
21
 
20
- ## 步骤 1:识别目标环境
22
+ ## 1. 识别目标环境
21
23
 
22
24
  只接受 `development`、`staging`、`production` 三种值。
23
25
 
24
- 如果用户调用技能时未显式给出环境:
25
- - 先询问用户当前环境(只给这三个选项)。
26
- - 若用户未回复或信息仍不明确,则默认 `development`,并明确告知本次按 `development` 执行。
26
+ 如果用户未显式给出环境:
27
+ - 先询问用户当前环境。
28
+ - 若无法确认,则默认 `development`,并明确告知本次按 `development` 执行。
27
29
 
28
- 如果用户给了其他环境名(例如 `prod1`、`test`):
30
+ 如果用户给了其他环境名,例如 `prod1`、`test`:
29
31
  - 立即终止。
30
- - 明确提示“环境无效,仅支持 development/staging/production”。
32
+ - 提示:`环境无效,仅支持 development/staging/production。`
31
33
 
32
- ## 步骤 2:门禁校验
34
+ ## 2. Production 门禁
33
35
 
34
- ### 2.1 production 环境的模式限制
36
+ 当且仅当目标环境是 `production` 时,必须确认当前处于 Plan 模式。
35
37
 
36
- 当环境是 `production` 时,必须先确认当前处于 `Plan` 模式。
37
-
38
- 如果不是 `Plan` 模式:
39
- - 立即终止。
40
- - 使用如下提示:
38
+ 如果不是 Plan 模式,立即终止并提示:
41
39
 
42
40
  ```text
43
41
  已终止:当前为 production 环境,但会话不在 Plan 模式。
44
42
  请切换到 Plan 模式后再继续在线调试。
45
43
  ```
46
44
 
47
- ### 2.2 环境文件存在性校验
45
+ `development` `staging` 不需要检查 Plan 模式,也不需要检查本地 `.env.*` 文件是否存在。
46
+
47
+ ## 3. 远程连接规范
48
+
49
+ 调试或查找问题时,通过本机 SSH config 中已有的 Host 配置连接远程机器。
50
+
51
+ 远程连接参数固定来自以下 SSH config Host:
52
+ - `production` 环境:`ai-prod`
53
+ - `staging` 环境:`ai-staging`
48
54
 
49
- 将项目根目录作为基准,检查以下文件:
50
- - `.env.${ENV_NAME}`
51
- - `.env.${ENV_NAME}.local`
55
+ ```bash
56
+ ssh ai-prod
57
+ ssh ai-staging
58
+ ```
59
+
60
+ 连接后如果需要 root 权限,运行:
61
+
62
+ ```bash
63
+ sudo -s
64
+ ```
52
65
 
53
- 校验规则:
54
- - 两个文件都必须存在。
55
- - 若 `.env.${ENV_NAME}.local` 不存在,视为环境指定有误,立即终止。
66
+ 不要手写散落的 IP、用户名、私钥路径或临时 SSH 参数;优先复用 SSH config,避免连错机器。
56
67
 
57
- 终止提示模板:
68
+ ## 4. 远程取证规范
69
+
70
+ 远程服务通常由 pm2 管理。优先使用 pm2 的只读命令获取信息,例如:
71
+
72
+ ```bash
73
+ pm2 list
74
+ pm2 describe <app>
75
+ pm2 logs <app> --lines 200
76
+ pm2 env <id>
77
+ ```
78
+
79
+ 远程环境变量通常在:
58
80
 
59
81
  ```text
60
- 已终止:未找到 .env.${ENV_NAME}.local,判定环境指定有误。
61
- 请确认环境仅为 development/staging/production,且对应本地覆盖文件存在。
82
+ /home/ubuntu/work/{$project_name}/shared
62
83
  ```
63
84
 
64
- ## 步骤 3:在线调试执行规范
85
+ 需要数据库、Redis、第三方服务等连接参数时,到该目录读取对应环境文件或配置。读取机密时只用于定位问题,不在最终回复中暴露完整密钥、密码或 token。
86
+
87
+ ## 5. 代码与产物边界
88
+
89
+ 本地运行代码一般在当前目录下执行。
90
+
91
+ 远程机器上运行的是编译后的产物。排查时区分:
92
+ - 本地源码:用于阅读、复现、运行测试和定位实现逻辑。
93
+ - 远程产物:用于确认线上实际运行版本、pm2 进程、日志、环境变量和部署状态。
94
+
95
+ 不要假设远程源码与本地源码完全一致;需要时用版本号、提交 SHA、构建时间、pm2 环境或部署目录内容交叉确认。
65
96
 
66
- 门禁通过后,才允许执行调试。
97
+ ## 安全规则
67
98
 
68
- 调试时遵循:
69
- - 默认只读:优先使用查询、检查、对比,不做写入。
70
- - 允许使用环境文件中的连接信息访问数据库、Redis 等依赖来定位问题。
71
- - 在未获用户明确授权前,禁止执行会改变状态的操作(例如写库、删键、迁移、重启、发布)。
72
- - 输出结论时必须包含:目标环境、已通过的门禁项、关键证据、下一步建议。
99
+ - 默认只读:优先查询、检查、对比、日志分析。
100
+ - 未获用户明确授权前,禁止写库、删键、迁移、重启、reload、发布、修改远程文件或改环境变量。
101
+ - 需要执行写操作时,先说明操作对象、影响范围、回滚方式和为什么必须这么做。
102
+ - 输出结论必须包含:目标环境、Plan 门禁是否适用与结果、关键证据、下一步建议。
73
103
 
74
104
  ## 标准开场模板
75
105
 
76
106
  ```text
77
107
  开始在线调试前先执行安全门禁:
78
108
  1) 确认环境(development/staging/production)
79
- 2) production 场景校验是否为 Plan 模式
80
- 3) 校验 .env.${ENV_NAME} .env.${ENV_NAME}.local 是否存在
81
- 任一失败将立即终止,避免误操作。
109
+ 2) 只有 production 需要校验当前是否为 Plan 模式
110
+ 3) 门禁通过后,通过 SSH config 连接远程机器,并优先用 pm2、shared 环境目录和日志只读取证
82
111
  ```
@@ -0,0 +1,676 @@
1
+ ---
2
+ name: ship-issue-pr
3
+ description: 仅在用户显式调用 $ship-issue-pr 或明确要求使用 ship-issue-pr 技能时使用;不要通过关键词、任务类型或上下文自动触发。
4
+ ---
5
+
6
+ # Ship Issue PR
7
+
8
+ ## 概览
9
+
10
+ 把一次变更从 `Issue -> 分支 -> Commit -> 验证 -> PR -> 审查修复 -> 自动合并 -> 合并后回访` 独立闭环交付。核心原则:没有 Issue 不提交,没有验证不发 PR,没有审查修复不合并,没有真合并和 Issue 回访不算完成。
11
+
12
+ 本技能是完整流程说明,不依赖其他 Git 流程技能。
13
+
14
+ ## 使用场景
15
+
16
+ - 用户要求“一键从 Issue 到 PR 合并”。
17
+ - 当前工作树有改动,需要创建或绑定 Issue、提交、推送、建 PR、验证并合并。
18
+ - 已有 PR,但用户要求继续验证、审查、修复并合并。
19
+ - PR Train 需要严格串行:前一个 PR 真正合并到 `main` 后才继续下一个。
20
+
21
+ 不要用于:
22
+
23
+ - 只讨论方案、不准备写入 GitHub。
24
+ - 只想做只读代码审查。
25
+ - 无法访问 `git` / `gh` / 远端仓库的环境。
26
+
27
+ ## 全局硬门禁
28
+
29
+ | 门禁 | 要求 |
30
+ |---|---|
31
+ | 中文输出 | 所有过程说明、报告、阻塞原因用中文 |
32
+ | Issue | 提交/发 PR 前必须有 Issue ID;没有就先创建 |
33
+ | 分支 | 禁止在 `main/master` 直接提交;分支必须含 Issue ID |
34
+ | 命令位置 | 仓库命令从仓库根目录执行 |
35
+ | Heredoc | 多行 Issue body、commit message、PR body、PR comment 必须用 heredoc |
36
+ | 验证 | 发 PR 前必须运行并记录相关验证;改代码后必须重跑 |
37
+ | Issue/PR 形状 | 必须产出“标准样本”级正文;空 PR body、泛泛模板、占位文字一律阻塞 |
38
+ | PR body | 必须使用本技能内置 PR 模板,不得只写“已通过本地测试” |
39
+ | 评论发布 | 审查、验收、修复、验证总结由主流程统一发布 |
40
+ | 合并 | 只能 `gh pr merge --squash --auto`,禁止 `--admin` 和无 `--auto` 合并 |
41
+ | 真完成 | 必须轮询到 `mergedAt` 非空,并回访关联 Issue 状态 |
42
+
43
+ ## 快速流程
44
+
45
+ | 阶段 | 产物 |
46
+ |---|---|
47
+ | 状态检测 | 当前分支、工作树、默认 base、已有关联 PR/Issue |
48
+ | Issue | 新建或确认 `#<id>`,正文含背景/目标/验收标准 |
49
+ | 分支 | `codex/<type>/<issue-id>-<slug>` 或 `<type>/<issue-id>-<slug>` |
50
+ | Commit | Conventional Commit,正文末尾 `Refs: #<issue-id>` |
51
+ | 验证 | `dx lint`、目标构建、相关测试,记录关键输出 |
52
+ | PR | 标题 Conventional Commit,正文含本仓模板,`Closes: #<issue-id>` |
53
+ | 审查修复 | Issue 验收、验证流水线、代码审查、逐项修复并提交 |
54
+ | 合并 | 设置 auto-merge,等待真实 merged |
55
+ | 回访 | 确认 Issue 自动关闭;未完成则重开或拆 follow-up |
56
+
57
+ ## 标准正文契约
58
+
59
+ Issue 与 PR 不是记录动作的流水账,而是给 reviewer 的验收契约。正文必须像一个可审计交付说明:
60
+
61
+ - Issue:写清真实背景、目标、方案、验收标准、关联;验收标准必须能逐项对照 diff 和命令结果。
62
+ - PR:写清变更目的、主要改动和解决的问题、遗留的问题、已做的验证、PR 遗留未做的、关联。
63
+ - 有能力边界就明说边界和原因;有未完成项就创建 follow-up Issue 并引用。
64
+ - 验证必须列出实际命令、涉及测试文件/用例、关键结果;不能写“已测试”“本地通过”。
65
+ - PR body 不得为空。创建或更新后必须 `gh pr view --json body` 读回确认。
66
+
67
+ ## 阶段一:状态检测
68
+
69
+ 并行收集:
70
+
71
+ ```bash
72
+ git status --short
73
+ git branch --show-current
74
+ git log -1 --format='%H %s' 2>/dev/null || echo "no-commits"
75
+ git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "no-upstream"
76
+ git remote -v
77
+ git rev-parse --abbrev-ref origin/HEAD 2>/dev/null || echo "origin/main"
78
+ git log --oneline -n 5
79
+ git log origin/main..HEAD --oneline
80
+ git diff --stat origin/main...HEAD
81
+ gh pr status
82
+ ```
83
+
84
+ 决策:
85
+
86
+ - 工作树有改动:执行完整链路。
87
+ - 工作树干净且当前分支已有未发 PR 提交:直接进入 PR 创建/更新与验证链路。
88
+ - 当前分支已有 OPEN PR:进入审查修复与合并链路。
89
+ - 工作树干净且无分支差异、无 OPEN PR:输出“无需交付”并结束。
90
+
91
+ 阻塞条件:
92
+
93
+ - 不在 Git 仓库。
94
+ - `gh auth status` 不可用且需要写 GitHub。
95
+ - 当前分支为 `main/master` 且无法创建新分支。
96
+ - 远端默认 base 无法确定。
97
+
98
+ ## 阶段二:Issue 创建或绑定
99
+
100
+ 先从用户输入、分支名、commit、PR body 中提取 Issue ID。提取不到就创建 Issue。
101
+
102
+ Issue 标题格式:
103
+
104
+ - `<type>(<scope>): 简洁目标`
105
+ - `[模块] 简洁目标`
106
+
107
+ Issue 标签从这些里选择:`bug`、`enhancement`、`documentation`、`performance`、`refactor`、`backend`、`frontend`、`infrastructure`、`test`。
108
+
109
+ Issue 正文必须包含以下五段。禁止使用“现状/问题、期望行为、执行计划、影响范围”作为主模板;这些信息要归入“背景/目标/方案/验收标准/关联”。
110
+
111
+ ```bash
112
+ gh issue create \
113
+ --title "fix(scope): 问题摘要" \
114
+ --label enhancement \
115
+ --body-file - <<'MSG'
116
+ ## 背景
117
+
118
+ 说明触发问题、现有行为、失败证据、相关文件/PR/Issue。背景必须让 reviewer 理解为什么现在要做。
119
+
120
+ ## 目标
121
+
122
+ 描述完成后系统应该达到的可观察状态。目标写结果,不写操作清单。
123
+
124
+ ## 方案
125
+
126
+ 写当前准备采用的实现路径、能力边界、取舍和已知阻塞。若方案依赖上游配置、外部服务或后续 PR,必须在这里说明。
127
+
128
+ ## 验收标准
129
+
130
+ - [ ] 可客观验证的一件事,能在 PR diff、命令输出或手测步骤中找到证据
131
+ - [ ] 覆盖边界条件、错误路径、配置/权限/契约等关键风险
132
+
133
+ ## 关联
134
+
135
+ Refs: #<相关 issue/pr-id>
136
+ MSG
137
+ ```
138
+
139
+ 验收标准写不出时先停止,回到目标澄清。禁止为了凑格式写“代码更优雅”这类主观标准。
140
+
141
+ Issue 创建后必须读回校验:
142
+
143
+ ```bash
144
+ gh issue view <ISSUE_ID> --json title,body,labels,url
145
+ ```
146
+
147
+ 校验失败条件:
148
+
149
+ - 缺少任一必需段落。
150
+ - 验收标准少于 1 条。
151
+ - 验收标准是动作清单而不是可验证结果。
152
+ - 正文仍保留占位文字。
153
+ - 关联项应存在但没有 `Refs:`。
154
+
155
+ ## 阶段三:分支处理
156
+
157
+ 分支类型只用:`feat`、`fix`、`refactor`、`docs`、`chore`、`test`。
158
+
159
+ 允许格式:
160
+
161
+ - `codex/<type>/<issue-id>-<slug>`
162
+ - `<type>/<issue-id>-<slug>`
163
+
164
+ 其中 `<type>` 只能是 `feat`、`fix`、`refactor`、`docs`、`chore`、`test`。
165
+
166
+ 规则:
167
+
168
+ - 当前分支是 `main/master`:必须创建新分支。
169
+ - 当前分支不含 Issue ID:创建或切换到合规分支。
170
+ - 当前分支已合规且不是主分支:继续使用。
171
+
172
+ 示例:
173
+
174
+ ```bash
175
+ git switch -c codex/fix/1234-short-topic
176
+ ```
177
+
178
+ ## 阶段四:提交前验证与 Commit
179
+
180
+ 提交前先看暂存范围:
181
+
182
+ ```bash
183
+ git diff --stat
184
+ git diff --name-only
185
+ ```
186
+
187
+ 按改动范围执行最低验证:
188
+
189
+ | 改动范围 | 必跑命令 |
190
+ |---|---|
191
+ | 任意 JS/TS | `dx lint` |
192
+ | 后端 | `dx build backend --dev`,相关 `dx test unit backend [path]` |
193
+ | 后端 E2E 相关 | `dx test e2e backend <file-or-dir>`,禁止无参全量 E2E |
194
+ | 前端用户端 | `dx build front --dev`,相关 `dx test unit front [path]` |
195
+ | 管理端 | `dx build admin --dev`,相关 `dx test unit admin [path]` |
196
+ | DTO/API 契约 | `dx build backend --dev` 后再 `dx build api-contracts` |
197
+ | 共享包 | `dx build shared` 或相关 shared 测试 |
198
+ | Flutter | `cd apps/mobile && flutter analyze`,相关 `flutter test <path>` |
199
+ | 范围不确定 | `dx lint` + `dx build affected --dev` + 相关测试 |
200
+
201
+ 验证失败必须修复后重跑。无法在当前 PR 内修复的预存错误,必须创建 follow-up Issue,并在 PR body 与审查报告同时登记编号。
202
+
203
+ 提交:
204
+
205
+ ```bash
206
+ git add -A
207
+ git diff --cached --stat
208
+ git commit -F - <<'MSG'
209
+ fix: 简洁摘要
210
+
211
+ 变更说明:
212
+ - 说明关键改动
213
+ - 说明影响范围
214
+
215
+ Refs: #123
216
+ MSG
217
+ ```
218
+
219
+ 提交标题必须是 Conventional Commit:`feat:`、`fix:`、`refactor:`、`docs:`、`chore:`、`test:`。
220
+
221
+ 提交后确认:
222
+
223
+ ```bash
224
+ git status --short
225
+ git log -1 --oneline
226
+ ```
227
+
228
+ ## 阶段五:PR 创建或更新
229
+
230
+ 先推送:
231
+
232
+ ```bash
233
+ git push -u origin HEAD
234
+ ```
235
+
236
+ 生成 PR 前收集:
237
+
238
+ ```bash
239
+ git log origin/main..HEAD --oneline
240
+ git diff origin/main...HEAD --stat
241
+ git diff origin/main...HEAD --name-only
242
+ ```
243
+
244
+ PR body 必须先生成到临时文件并自检。禁止直接创建空 body PR,禁止用“稍后补充”。
245
+
246
+ ```bash
247
+ cat > /tmp/ship-pr-body.md <<'MSG'
248
+ ## 变更目的
249
+
250
+ - 闭环 Issue #123 中的具体目标,说明用户可观察问题如何被解决。
251
+ - 对应 Issue 验收标准 [1]:说明实现落点和关键取舍。
252
+ - 能力边界:如果只完成目标的一部分,写清为什么、证据是什么、follow-up 是哪个 Issue。
253
+
254
+ ## 主要改动和解决的问题
255
+
256
+ - 解决问题 1:对应 Issue 验收标准 [1],列出关键文件/模块和原因。
257
+ - 解决问题 2:对应 Issue 验收标准 [2],说明行为变化、配置变化或契约变化。
258
+ - 测试/契约/文档改动:列出为什么需要这些改动。
259
+
260
+ ## 遗留的问题
261
+
262
+ - 无;或写明未覆盖的 Issue 范围、原因、follow-up #<id>。
263
+
264
+ ## 已做的验证
265
+
266
+ - 变更提交:
267
+ - `<full-sha>`(`fix: ...`)
268
+ - 涉及测试文件:
269
+ - `path/to/spec.ts`
270
+ - 最终通过命令:
271
+ - `rtk dx lint`
272
+ - `rtk dx build <target> --dev`
273
+ - `rtk dx test ...`(列出文件数/用例数或关键通过摘要)
274
+ - 手测:无;或列出关键路径步骤与结果。
275
+
276
+ ## PR 遗留未做的
277
+
278
+ - 无;或 `Owner: <owner>。后续在 #<id> 中完成 <事项>。`
279
+
280
+ ## 关联
281
+
282
+ Closes: #123
283
+ Refs: #<相关 issue/pr-id>
284
+ MSG
285
+ ```
286
+
287
+ 创建或更新 PR:
288
+
289
+ ```bash
290
+ grep -q '^## 变更目的' /tmp/ship-pr-body.md
291
+ grep -q '^## 主要改动和解决的问题' /tmp/ship-pr-body.md
292
+ grep -q '^## 遗留的问题' /tmp/ship-pr-body.md
293
+ grep -q '^## 已做的验证' /tmp/ship-pr-body.md
294
+ grep -q '^## PR 遗留未做的' /tmp/ship-pr-body.md
295
+ grep -q '^## 关联' /tmp/ship-pr-body.md
296
+ grep -q 'Closes: #[0-9]' /tmp/ship-pr-body.md
297
+ ! grep -qE '稍后补充|TODO|TBD|path/to/spec|<full-sha>|#<|问题摘要|简洁摘要' /tmp/ship-pr-body.md
298
+
299
+ gh pr create --base main --title "fix: 简洁摘要" --body-file /tmp/ship-pr-body.md
300
+ ```
301
+
302
+ 规则:
303
+
304
+ - `#123` 只用于真实 GitHub Issue/PR 引用。
305
+ - 普通序号写 `[1]`、`问题 1`、`PR1`,禁止写会被 GitHub 自动链接的普通 `#1`。
306
+ - 若 Issue 有未覆盖验收标准,不得写“无”;必须补做或创建 follow-up Issue 并引用。
307
+ - `已做的验证` 必须包含实际命令;如果命令未跑,PR 不得创建或必须标记阻塞。
308
+ - 有新增/修改测试时必须列测试文件;没有测试时必须说明为什么没有。
309
+ - 有多个 commit、冲突提交或审查修复提交时,`变更提交` 必须列出关键 commit。
310
+ - 只更新既有 PR 时,也要确保 body 符合模板,不合格立即用 `gh pr edit <PR_NUMBER> --body-file /tmp/ship-pr-body.md` 修正。
311
+ - PR 创建或更新后必须读回:
312
+
313
+ ```bash
314
+ gh pr view <PR_NUMBER> --json title,body,url
315
+ ```
316
+
317
+ 读回校验失败条件:
318
+
319
+ - body 为空。
320
+ - 缺少任一必需段落。
321
+ - 仍有占位符、示例路径、`TODO`、`TBD`、`稍后补充`。
322
+ - `已做的验证` 没有实际命令。
323
+ - `遗留的问题` 或 `PR 遗留未做的` 写“无”,但 Issue 验收标准仍有未覆盖项。
324
+ - 缺少 `Closes: #<issue-id>`。
325
+
326
+ ## 阶段六:合并冲突检测
327
+
328
+ 如果 PR body 含 `PR Train`、`依赖 #<PR_NUMBER>`、`depends on #<PR_NUMBER>` 等串行依赖标记,先检查依赖 PR:
329
+
330
+ ```bash
331
+ gh pr view <DEPENDS_ON_PR> --json state,mergedAt,url
332
+ ```
333
+
334
+ - `mergedAt` 非空:继续。
335
+ - `mergedAt` 为空:停止,输出“依赖 PR 尚未真实合并到 main”,禁止继续审查、修复或合并当前 PR。
336
+
337
+ 依赖通过后再检测与 `main` 的冲突:
338
+
339
+ ```bash
340
+ git fetch origin main
341
+ git merge --no-commit --no-ff origin/main
342
+ ```
343
+
344
+ - 无冲突:`git merge --abort` 后继续。
345
+ - 有冲突:`git merge --abort`,再执行真实合并、解冲突、验证、提交、推送。
346
+
347
+ 冲突提交:
348
+
349
+ ```bash
350
+ git add -A
351
+ git commit -F - <<'MSG'
352
+ fix: 解决与 main 的合并冲突
353
+
354
+ 变更说明:
355
+ - 说明冲突文件
356
+ - 说明保留哪一侧语义以及原因
357
+
358
+ Refs: #123
359
+ MSG
360
+ git push
361
+ ```
362
+
363
+ ## 阶段七:审查修复循环
364
+
365
+ 最多 3 轮。每轮必须包含:Issue 验收、验证流水线、代码审查、修复报告。
366
+
367
+ ### 7.1 Issue 验收
368
+
369
+ 读取关联 Issue:
370
+
371
+ ```bash
372
+ gh issue view 123 --json title,body,state,labels
373
+ gh pr diff <PR_NUMBER>
374
+ gh pr view <PR_NUMBER> --json title,body,headRefName,baseRefName,url
375
+ ```
376
+
377
+ 逐条核对 Issue 的「验收标准」:
378
+
379
+ | 状态 | 含义 | 后续 |
380
+ |---|---|---|
381
+ | 通过 | diff 有明确实现证据 | 记录文件/行号或模块 |
382
+ | 部分 | 实现不完整或边界缺失 | 必须修复 |
383
+ | 未实现 | 核心标准没有落地 | 必须补做或拆 follow-up Issue |
384
+ | 超出范围 | PR 做了 Issue 未描述事项 | PR body 补释或拆 Issue |
385
+
386
+ 发布独立评论:
387
+
388
+ ```bash
389
+ gh pr comment <PR_NUMBER> --body-file - <<'MSG'
390
+ ## Issue 验收报告(第 N 轮)
391
+
392
+ - Issue:#123 标题
393
+ - 验收标准条目数:N
394
+ - 结论:全部完成 / 部分完成 / 严重缺失
395
+
396
+ | 序号 | 验收标准 | 状态 | 证据 / 欠缺 |
397
+ |---|---|---|---|
398
+ | [1] | 原文 | 通过/部分/未实现 | 文件:行号 或欠缺说明 |
399
+
400
+ ### 后续处理
401
+
402
+ - 未实现或部分实现项:进入本轮修复,或登记 follow-up Issue
403
+ MSG
404
+ ```
405
+
406
+ ### 7.2 验证流水线
407
+
408
+ 执行阶段四的相关验证。失败时必须保留完整错误,包括文件、行号、命令、失败摘要。
409
+
410
+ 将失败分类:
411
+
412
+ - 本 PR 引入:正常 `fix:` commit 修复。
413
+ - 历史遗留:仍需修复;若修复,单独 `chore(precheck):` commit;若无法修,创建 follow-up Issue,并在 PR body 与审查报告登记。
414
+
415
+ ### 7.3 代码审查
416
+
417
+ 审查范围:
418
+
419
+ - `gh pr diff <PR_NUMBER>` 的改动。
420
+ - diff 涉及文件内顺手发现的真实 bug。
421
+ - 不主动扩大到无关模块。
422
+
423
+ 每条问题必须有四要素:
424
+
425
+ - 严重级:`Critical` / `Major` / `Minor`
426
+ - 文件:行号
427
+ - 具体问题描述
428
+ - 具体改法
429
+
430
+ 严重级:
431
+
432
+ | 严重级 | 例子 | 默认处理 |
433
+ |---|---|---|
434
+ | Critical | 构建失败、测试失败、安全漏洞、数据丢失 | 必修 |
435
+ | Major | 逻辑缺陷、错误处理缺失、性能问题、验收部分缺失 | 修复或拆 follow-up |
436
+ | Minor | 命名、局部风格、文档、小范围清理 | 小于 5 行优先修,否则说明拒绝理由 |
437
+
438
+ 审查质量自检:
439
+
440
+ - 缺四要素的条目不进入报告。
441
+ - “建议优化”“可以考虑”这类没有具体改法的条目不进入报告。
442
+ - 功能未实现类问题归入 Issue 验收,不重复写进代码审查。
443
+
444
+ 发布独立评论:
445
+
446
+ ```bash
447
+ gh pr comment <PR_NUMBER> --body-file - <<'MSG'
448
+ ## 代码审查报告(第 N 轮)
449
+
450
+ ### 概要
451
+
452
+ - Critical:0
453
+ - Major:0
454
+ - Minor:0
455
+
456
+ ### 验证流水线
457
+
458
+ - Lint:通过/失败
459
+ - 构建:通过/失败
460
+ - 测试:通过/失败/跳过(列实际命令)
461
+
462
+ ### 问题列表
463
+
464
+ | 严重级 | 来源 | 文件:行号 | 描述 | 建议改法 |
465
+ |---|---|---|---|---|
466
+ | Major | 代码审查 | path/file.ts:42 | 具体描述 | 具体改法 |
467
+
468
+ ### 处理决策
469
+
470
+ - 每条问题标记:修复 / 拒绝 / follow-up
471
+ - 拒绝必须写具体理由
472
+ MSG
473
+ ```
474
+
475
+ ### 7.4 逐项修复
476
+
477
+ 按 `Critical -> Major -> Minor` 顺序处理。每个问题一个 commit,禁止攒到最后。
478
+
479
+ ```bash
480
+ git add <files>
481
+ git commit -F - <<'MSG'
482
+ fix: 修复审查问题 - 简洁描述
483
+
484
+ 变更说明:
485
+ - 说明具体修复
486
+
487
+ Refs: #123
488
+ MSG
489
+ git push
490
+ ```
491
+
492
+ 历史遗留验证失败修复:
493
+
494
+ ```bash
495
+ git add <files>
496
+ git commit -F - <<'MSG'
497
+ chore(precheck): 修复合并前验证发现的历史问题
498
+
499
+ 变更说明:
500
+ - 说明该问题不是本 PR diff 引入
501
+ - 说明按合并前门禁修复
502
+
503
+ Refs: #123
504
+ MSG
505
+ git push
506
+ ```
507
+
508
+ 发布修复报告:
509
+
510
+ ```bash
511
+ gh pr comment <PR_NUMBER> --body-file - <<'MSG'
512
+ ## 修复报告(第 N 轮)
513
+
514
+ ### 已修复
515
+
516
+ | 序号 | 问题 | 修复方式 | Commit |
517
+ |---|---|---|---|
518
+ | [1] | 描述 | 修复说明 | abc1234 |
519
+
520
+ ### 拒绝修复
521
+
522
+ | 序号 | 问题 | 理由 |
523
+ |---|---|---|
524
+ | [1] | 描述 | 具体理由 |
525
+
526
+ ### Follow-up
527
+
528
+ | 序号 | 问题 | Issue |
529
+ |---|---|---|
530
+ | [1] | 描述 | #456 |
531
+ MSG
532
+ ```
533
+
534
+ 继续下一轮条件:
535
+
536
+ - 本轮修过代码,并且有 Critical/Major 修复。
537
+ - Issue 验收从未实现/部分实现变为需要复核。
538
+ - 验证失败被修复后需要重跑。
539
+
540
+ 结束条件:
541
+
542
+ - 验收全部完成。
543
+ - 验证全部通过或不可修项已登记 follow-up。
544
+ - 代码审查无未处理 Critical/Major。
545
+ - 已达 3 轮但仍未完成时,禁止合并,输出阻塞原因。
546
+
547
+ ## 阶段八:最终验证总结
548
+
549
+ 合并前最后一次运行相关验证。发布总结:
550
+
551
+ ```bash
552
+ gh pr comment <PR_NUMBER> --body-file - <<'MSG'
553
+ ## 验证总结
554
+
555
+ | 步骤 | 状态 | 备注 |
556
+ |---|---|---|
557
+ | Lint (`dx lint`) | 通过 | 关键输出 |
558
+ | 构建 | 通过 | 实际命令 |
559
+ | 测试 | 通过/跳过 | 实际命令和原因 |
560
+
561
+ ### 审查统计
562
+
563
+ - 审查轮数:N
564
+ - 发现问题:X 个
565
+ - 已修复:Y 个
566
+ - 拒绝修复:Z 个
567
+ - Follow-up:K 个
568
+
569
+ ### 结论
570
+
571
+ 所有合并门禁已满足,PR 可进入 auto-merge。
572
+ MSG
573
+ ```
574
+
575
+ 禁止在验证失败时写“可合并”。
576
+
577
+ ## 阶段九:自动合并与监控
578
+
579
+ 设置自动合并:
580
+
581
+ ```bash
582
+ gh pr merge <PR_NUMBER> --squash --auto
583
+ ```
584
+
585
+ 轮询直到终态:
586
+
587
+ ```bash
588
+ gh pr view <PR_NUMBER> --json state,mergedAt,statusCheckRollup,mergeStateStatus,url
589
+ ```
590
+
591
+ 终止条件:
592
+
593
+ - `mergedAt` 非空:合并成功。
594
+ - `state=CLOSED` 且 `mergedAt=null`:PR 已关闭但未合并,阻塞。
595
+ - `statusCheckRollup` 有失败:CI 失败,回到修复循环。
596
+ - 超过 30 分钟仍未合并:输出 stuck 状态,禁止 `--admin` 越权。
597
+
598
+ ## 阶段十:合并后回访
599
+
600
+ 合并成功后:
601
+
602
+ ```bash
603
+ gh pr view <PR_NUMBER> --json mergedAt,mergeCommit,url
604
+ gh issue view 123 --json state,title,url
605
+ ```
606
+
607
+ 检查:
608
+
609
+ - Issue 是否因 `Closes: #123` 正确关闭。
610
+ - Issue 验收标准是否真的全部覆盖。
611
+ - PR body 的遗留项是否都有 follow-up Issue。
612
+ - 若 Issue 被误关但仍有未完成验收标准:重开 Issue 或拆 follow-up,并在最终输出写明编号。
613
+
614
+ ## 成功输出
615
+
616
+ 最终只在确认真合并和 Issue 回访后输出:
617
+
618
+ ```text
619
+ Ship Issue PR 完成
620
+
621
+ - Issue:#123 标题
622
+ - PR:#456 链接
623
+ - 分支:codex/fix/123-short-topic
624
+ - Commit:首个提交摘要;修复提交 X 个
625
+ - 验证:Lint 通过;构建通过;测试通过/跳过原因
626
+ - 审查:N 轮;发现 X 个;修复 Y 个;拒绝 Z 个;Follow-up K 个
627
+ - 合并:已合并到 main,merged_at=<timestamp>
628
+ - 回访:Issue 状态已确认
629
+ ```
630
+
631
+ ## 阻塞输出
632
+
633
+ 遇到不可继续情况,必须输出:
634
+
635
+ ```text
636
+ Ship Issue PR 阻塞
637
+
638
+ - 停止阶段:阶段名
639
+ - 已完成:列出已经完成的可审计动作
640
+ - 阻塞原因:具体错误、缺权限、验证失败、依赖未合并等
641
+ - 不应做的事:说明禁止绕过的门禁
642
+ - 下一步建议:给出可执行命令或需要用户提供的信息
643
+ ```
644
+
645
+ ## 常见错误
646
+
647
+ | 错误 | 正确做法 |
648
+ |---|---|
649
+ | 没 Issue 就提交 | 先创建或绑定 Issue |
650
+ | 在 `main/master` commit | 先切含 Issue ID 的分支 |
651
+ | 分支名没有 Issue ID | 重命名或新建合规分支 |
652
+ | Issue 使用“期望行为/执行计划/影响范围”旧模板 | 改为“背景/目标/方案/验收标准/关联” |
653
+ | PR body 为空 | 立即用完整模板 `gh pr edit --body-file` 修正,未修正不得进入审查/合并 |
654
+ | PR body 只写“已测试” | 填完整 PR 模板和命令证据 |
655
+ | PR body 有模板占位符 | 替换成真实 commit、文件、命令、follow-up 编号后再创建/更新 |
656
+ | 普通序号写 `#1` | 写 `[1]` 或 `问题 1` |
657
+ | E2E 无参全量运行 | 指定文件或目录 |
658
+ | 验证失败说“历史遗留不管” | 修复或登记 follow-up Issue |
659
+ | 多个审查修复攒一个 commit | 每个问题一个 commit |
660
+ | `gh pr merge --squash` 不带 `--auto` | 只允许 `--squash --auto` |
661
+ | 设置 auto-merge 后立即宣称完成 | 必须轮询到 `mergedAt` |
662
+ | 合并后不看 Issue | 必须回访 Issue 状态和验收覆盖 |
663
+
664
+ ## 红旗
665
+
666
+ 出现这些想法时停止并回到对应阶段:
667
+
668
+ - “这个改动很小,不需要 Issue。”
669
+ - “PR body 之后再补。”
670
+ - “CI 应该会过,先合并。”
671
+ - “历史遗留错误不是我引入的,跳过。”
672
+ - “GitHub 已显示 mergeable,不用逐条核对验收标准。”
673
+ - “auto-merge 已设置,所以算完成。”
674
+ - “先 `--admin` 合了再说。”
675
+
676
+ 这些都表示流程正在失真。交付的定义是真实合并且 Issue 回访完成,不是把 PR 发出去。
@@ -1,7 +0,0 @@
1
- interface:
2
- display_name: "Online Debug Guard"
3
- short_description: "Guarded workflow for environment-aware online debugging"
4
- default_prompt: "使用 $online-debug-guard 执行安全的在线调试流程,先判定环境与模式,再执行只读排查。"
5
-
6
- policy:
7
- allow_implicit_invocation: false