qwen-code/docs/design/slash-command
易良 700620f4d0
feat(cli): add /commit slash command with AI-drafted commit messages (#10586)
* feat(cli): add /commit slash command with AI-drafted commit messages

Implements the #4000 redesign of the /commit command that was rejected
in #3935 for being a thin `git add -A && git commit` wrapper.

The command returns a SubmitPromptActionReturn: it injects a crafted
prompt and the model does all the work — gathering context (git status,
git diff HEAD, git log, branch), staging files selectively instead of
`git add -A`, drafting a multi-line message in the repo's commit style,
and running the commit. No diff parsing or staging logic in TypeScript.

The prompt contract encodes the safety guards from the design review:
no --amend without explicit request, never --no-verify, refuse obvious
secret files, skip empty commits; co-author attribution is explicit in
the commit message text.

Fixes #4000

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(cli): address review feedback on /commit command

- R1-1: add missing i18n key for description getter (en/zh/zh-TW)
- R1-2: rewrite Attribution section to reflect actual platform behavior
  (general.gitCoAuthor.commit appends Co-authored-by for inline -m/-am;
   no-op for heredoc/editor; do not add a second trailer)
- R1-4: add fallback bullet for unborn HEAD repos (git diff HEAD fails)
- R1-5: add /commit row to docs/users/features/commands.md
- R1-6: anchor safety-guard tests to directive polarity, not keywords
- R1-7: update roadmap.md to reflect /commit landed as built-in

* fix(cli): register /commit in the OpenTUI route table

The new built-in returns a submit_prompt result and registers in
BuiltinCommandLoader between /clear and /compress, but OPEN_TUI_COMMAND_ROUTES
never got the entry, so the parity suite failed with 'missing route for
/commit' and 'no route for /commit'. Declare it in loader order.

* fix(cli): align /commit prompt with platform attribution gates and repo-state guards

Address the outstanding review round:

- Attribution: name the real auto-append gates (config on, bash shell,
  plain inline -m/--message, no $() substitution) instead of claiming
  the trailer lands for any inline -m/-am; require post-commit
  verification via git log -1 --format=%B before claiming credit.
- Attribution: route user-named co-authors through a non-inline message
  on bash so the appended trailer cannot push them out of git's trailer
  block.
- Staging: require reading untracked file contents directly, since
  git diff HEAD never shows them and the secret check otherwise runs on
  filenames alone.
- Safety: stop on detached HEAD or in-progress merge/rebase/cherry-pick
  instead of committing unconditionally.
- Multi-line: recommend repeated -m flags, a form the trailer injector
  can rewrite, over ANSI-C or heredoc wrappers.
- prompts.ts: stop advertising /commit as the user-skill example now
  that the name is a built-in.

* fix(cli): reconcile the git index and restore the name-based secret floor in the /commit prompt

R3-1: `git commit` ships the whole index, so a file the user staged
before /commit ran — or one a directory pathspec swept in — was
committed even though the prompt promised to warn about secrets and
leave them out. Section 4 now requires a `git diff --cached
--name-status` check with `git restore --staged` as the remedy, section
2 names `git add <dir>` as a pathspec rather than a file list, and
section 1 points at `git status -uall` because the default collapses a
wholly-untracked directory to a single line.

R3-2: "the secrets rule below applies to file contents, not file names"
repealed the name basis issue 4000 asks for and, read together with
"read each untracked file directly", pulled .env / private-key contents
into the model context before the refusal. A file whose name marks it as
a secret is now refused by name without being opened; every other file
is still read before it is judged.

R3-3: the auto-append gate list read as exhaustive-and-sufficient but
omitted findAttributableCommitSegment's attributability requirement — a
backslash-continued multi-line command, one wrapped in `bash -c`, or one
redirected with `git -C` or an absolute `cd` is not rewritten. Those are
now named, and `git log -1 --format=%B` is stated as the authority.

Tests: commit-command.test.ts 13/13 pass (was 12). Each new clause was
removed in turn and confirmed to red the case that pins it.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Patrol-Run: qwen-pr-closeout/jmuis49v07v

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-09-27 05:51:07 +00:00
..
compare.md refactor(cli): replace slash command whitelist with capability-based filtering (Phase 1) (#3283) 2026-04-20 14:34:43 +08:00
phase1-technical-design.md refactor(cli): enforce utils leaf-layer dependency direction (#9146) (#9737) 2026-08-23 14:41:49 +00:00
phase2-technical-design.md feat(cli): Phase 2 — slash command multi-mode expansion, ACP fixes, and UX improvements (#3377) 2026-04-22 19:12:44 +08:00
phase3-technical-design.md refactor(cli): enforce utils leaf-layer dependency direction (#9146) (#9737) 2026-08-23 14:41:49 +00:00
roadmap.md feat(cli): add /commit slash command with AI-drafted commit messages (#10586) 2026-09-27 05:51:07 +00:00