finish-task

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<objective> Cleanly close out the current task. Validate that work is complete, create an atomic commit with a proper conventional commit message, update Linear, and optionally create a PR. Detect incomplete work and surface it before closing. </objective> <context> Input: $ARGUMENTS — optional commit type override (feat, fix, refactor, etc.) Requires: git repo with changes, on a feature branch with a Linear issue ID Optional: .planning/ directory </context> <process>
<objective> 干净地关闭当前任务。验证工作已完成,使用规范的约定式提交信息创建原子提交,更新Linear,可选创建PR。检测未完成的工作并在关闭前提示用户。 </objective> <context> 输入: $ARGUMENTS — 可选的提交类型覆盖(feat、fix、refactor等) 要求:带有变更的git仓库,处于包含Linear issue ID的功能分支上 可选:.planning/ 目录 </context> <process>

0. Validate Environment

0. 验证环境

Check preconditions:
  • Inside a git repo
  • On a feature branch (not main/master)
  • linear
    CLI available
Read project scope (silent):
  • IF
    .linear-project
    exists →
    PROJECT=$(cat .linear-project)
    , store
    PROJECT_FLAG
  • IF missing → continue unscoped
Extract issue ID from branch name using
linear issue id
.
  • IF no issue ID detected: ask "I can't find a Linear issue for this branch. What's the issue ID?"
  • IF issue not found in Linear: warn and continue without Linear updates
检查前置条件:
  • 处于git仓库内
  • 处于功能分支(非main/master)
  • linear
    CLI可用
读取项目范围(静默执行):
  • 若存在
    .linear-project
    PROJECT=$(cat .linear-project)
    ,存储
    PROJECT_FLAG
  • 若不存在 → 继续无范围执行
使用
linear issue id
从分支名中提取issue ID。
  • 若未检测到issue ID:询问"我未找到对应此分支的Linear issue。对应的issue ID是什么?"
  • 若Linear中未找到对应issue:发出警告,跳过Linear更新继续执行

1. Assess Completeness

1. 评估完成度

Before closing, check if the work looks done:
Check for uncommitted changes:
  • git status --porcelain
  • IF dirty working tree: show what's changed and ask: "You have uncommitted changes. Include them in the final commit?"
    • Yes → stage them
    • No, they're WIP for something else → stash them first
    • Actually I'm not done → abort finish-task
Check for incomplete markers:
  • Grep the diff for TODO, FIXME, HACK, XXX markers
  • IF found: "Found N incomplete markers in your changes:" Show each one with file and line. Ask: "Are these intentional (tech debt to track) or should you fix them first?"
    • Intentional → continue, note them in Linear comment
    • Fix first → abort, user fixes, re-runs /product:finish-task
Check test status (if test runner exists):
  • Look for test config (jest.config, vitest.config, playwright.config, etc.)
  • IF test runner found: "Want to run tests before finishing?"
    • Yes → run tests. IF failures: show them and ask "Fix or finish anyway?"
    • No → skip
    • No test config found → skip silently
关闭任务前,检查工作是否已完成:
检查未提交的变更:
  • git status --porcelain
  • 若工作树存在未提交变更:展示变更内容并询问: "你有未提交的变更。是否要将它们纳入最终提交?"
    • 是 → 暂存这些变更
    • 否,它们是其他工作的待完成内容 → 先暂存它们
    • 实际上我还没完成 → 终止finish-task流程
检查未完成标记:
  • 在diff中检索TODO、FIXME、HACK、XXX标记
  • 若找到:"在你的变更中发现了N个未完成标记:" 展示每个标记对应的文件和行号。 询问:"这些是 intentional(需要追踪的技术债务)还是你需要先修复它们?"
    • 是 intentional → 继续执行,在Linear评论中记录这些标记
    • 先修复 → 终止流程,用户修复后重新执行 /product:finish-task
检查测试状态(如果存在测试运行器):
  • 查找测试配置文件(jest.config、vitest.config、playwright.config等)
  • 若找到测试运行器:"是否要在完成任务前运行测试?"
    • 是 → 运行测试。若测试失败:展示失败内容并询问"修复问题还是直接完成?"
    • 否 → 跳过
    • 未找到测试配置 → 静默跳过

2. Review Changes

2. 审核变更

Show a clear summary of what changed:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 PRODUCT ► FINISH TASK
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Issue:  ENG-123 — Add user authentication flow
Branch: eng-123-add-auth-flow

Changes:
  5 files changed, 142 insertions, 23 deletions

  M src/middleware.ts
  A src/app/(auth)/login/page.tsx
  A src/components/auth-form.tsx
  M src/lib/utils.ts
  A src/tests/auth.test.ts
Run
git diff --stat
and
git diff
(summarize, don't dump the full diff).
清晰展示变更摘要:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 PRODUCT ► FINISH TASK
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Issue:  ENG-123 — Add user authentication flow
Branch: eng-123-add-auth-flow

Changes:
  5 files changed, 142 insertions, 23 deletions

  M src/middleware.ts
  A src/app/(auth)/login/page.tsx
  A src/components/auth-form.tsx
  M src/lib/utils.ts
  A src/tests/auth.test.ts
运行
git diff --stat
git diff
(做摘要展示,不要输出完整diff内容)。

3. Create Commit

3. 创建提交

Determine commit type:
  • IF argument provided (e.g., "fix") → use it
  • ELSE infer from changes:
    • New files + new functionality →
      feat
    • Bug fix / correction →
      fix
    • Only test files →
      test
    • Only docs/comments →
      docs
    • Restructuring without behavior change →
      refactor
    • Config/tooling →
      chore
  • If unsure, ask: "What type of change is this? feat / fix / refactor / other?"
Build commit message:
  • Format:
    {type}({issue-id}): {concise description}
  • Example:
    feat(ENG-123): add magic link authentication flow
  • Description should summarize the what, not list files
Stage and commit:
  • git add
    the relevant files (not blindly
    git add -A
    — exclude any unrelated changes)
  • Create the commit
  • Show the commit hash and message
确定提交类型:
  • 若提供了参数(例如"fix")→ 使用该参数
  • 否则从变更内容推断:
    • 新增文件+新增功能 →
      feat
    • 漏洞修复/内容修正 →
      fix
    • 仅测试文件变更 →
      test
    • 仅文档/注释变更 →
      docs
    • 无行为变更的代码重构 →
      refactor
    • 配置/工具变更 →
      chore
  • 若无法确定,询问:"本次变更的类型是什么?feat / fix / refactor / 其他?"
构建提交信息:
  • 格式:
    {type}({issue-id}): {concise description}
  • 示例:
    feat(ENG-123): add magic link authentication flow
  • 描述应总结变更内容,不要罗列文件
暂存并提交:
  • git add
    相关文件(不要盲目执行
    git add -A
    — 排除所有不相关的变更)
  • 创建提交
  • 展示提交哈希和提交信息

4. Update Linear

4. 更新Linear

  • linear issue update $ISSUE_ID -s "Done"
  • linear issue comment add $ISSUE_ID -b "$SUMMARY"
    • Summary should include: what was implemented, files changed, commit hash
    • If TODO markers were found in step 1, note them as follow-up items
Confirm: "Linear issue ENG-123 moved to Done with implementation summary"
  • linear issue update $ISSUE_ID -s "Done"
  • linear issue comment add $ISSUE_ID -b "$SUMMARY"
    • 摘要应包含:实现内容、变更文件、提交哈希
    • 若步骤1中发现了TODO标记,将它们记录为后续待办项
确认提示:"Linear issue ENG-123已移至Done状态并附带实现摘要"

5. Offer PR Creation

5. 提供PR创建选项

Ask: "Create a pull request?"
  • Yes →
    • Determine base branch (main/master/develop)
    • Draft PR title from commit message
    • Draft PR body with: summary, Linear issue link, what changed, test instructions
    • Create PR with
      gh pr create
    • Show the PR URL
  • No → skip
询问:"是否要创建拉取请求?"
  • 是 →
    • 确定目标分支(main/master/develop)
    • 从提交信息生成PR标题草稿
    • 生成PR正文草稿,包含:摘要、Linear issue链接、变更内容、测试说明
    • 使用
      gh pr create
      创建PR
    • 展示PR URL
  • 否 → 跳过

6. Route to Next Action

6. 跳转至下一步操作

Check what's next:
  • linear issue list -s unstarted --limit 5 $PROJECT_FLAG
    — any backlog?
  • linear issue list -s started --limit 5 $PROJECT_FLAG
    — any other in-progress?
Based on state:
  • IF other in-progress issues exist → "You still have N issues in progress. Resume one?"
  • IF unstarted issues exist → "Next highest priority in {project-name or "your backlog"}: ENG-456 — Description. Start it? (/product:start-task ENG-456)"
  • IF nothing → "Backlog is clear{" for " + project-name if scoped}. Nice work."
</process>
<success_criteria>
  • All changes reviewed before committing
  • Incomplete markers surfaced and user made a decision
  • Atomic commit with proper conventional commit message
  • Linear issue moved to Done with implementation summary
  • PR created if user requested
  • User knows what to work on next </success_criteria>
检查后续待办:
  • linear issue list -s unstarted --limit 5 $PROJECT_FLAG
    — 有没有待处理的backlog?
  • linear issue list -s started --limit 5 $PROJECT_FLAG
    — 有没有其他进行中的任务?
根据状态提示:
  • 若存在其他进行中的issue → "你还有N个进行中的issue。要恢复其中一个的工作吗?"
  • 若存在未开始的issue → "{项目名称 或 "你的backlog"}中最高优先级的下一个任务:ENG-456 — 任务描述。要开始吗?(/product:start-task ENG-456)"
  • 若没有待办 → "Backlog已清空{若有项目范围则追加" 对应项目:" + 项目名称}。干得漂亮。"
</process>
<success_criteria>
  • 提交前已审核所有变更
  • 未完成标记已透出且用户已做出决策
  • 带有规范约定式提交信息的原子提交
  • Linear issue已移至Done状态并附带实现摘要
  • 按用户要求创建PR
  • 用户知晓下一步工作内容 </success_criteria>