feat: derive CLI commands and skill hint from a single registry#6
Merged
Merged
Conversation
The set of cc-session subcommands was hand-copied across three places (main.go doc comment, the dispatch switch, and printUsage), plus the SKILL.md cheat-sheet — so a rename like inject→inherit had to be mirrored by hand and silently rotted when missed. Introduce a command registry in cmd/cc-session/commands.go as the single source of truth. Dispatch and printUsage now derive from it, and a new `cc-session help` renders the intent→command cheat sheet while `cc-session help --argument-hint` emits the one-line hint string. SKILL.md adopts the /wt shape: an `argument-hint` frontmatter (so the input box shows the subcommands), a `## 路由` section that dispatches on $ARGUMENTS, and the static cheat-sheet table replaced by a live !`cc-session help` injection that always matches the installed binary. install.sh / install.ps1 stamp the argument-hint line from `cc-session help --argument-hint` at install time (awk temp-file + mv for BSD/GNU portability), falling back to the committed line when the binary is absent or the output is malformed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JwariBme7AbQxDciEKSPXt
The cheat sheet rendered by `cc-session help` was a fourth hand-copied command list living alongside the registry, and the struct doc comment claimed the registry was its single source of truth when it was not — reintroducing the exact drift this refactor set out to remove. - cheatSheetRow now references a registry command by name; the command string (`cc-session <name> <argHint>`) is derived via findCommand, and commandText() panics if the row points at a missing or hidden command, turning the `hidden` doc comment into an enforced invariant. - New TestCheatSheet_… asserts the cheat sheet covers exactly the non-hidden, hinted registry commands, so a new subcommand can't be added without a matching cheat-sheet row. - New TestSkillMD_… asserts SKILL.md's argument-hint frontmatter equals buildArgumentHint(), so registry changes that aren't mirrored into the committed SKILL.md fail the build instead of drifting silently. - printUsage computes column width from the longest command name so `benchmark` (9 chars) no longer breaks alignment. - Rename bool flag var argumentHint -> isArgumentHint per package convention. - Doc comments in commands.go rewritten to describe only what is true. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JwariBme7AbQxDciEKSPXt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
動機
cc-session的子命令清單原本手抄在 4 個地方(main.godoc comment、dispatch switch、printUsage()、SKILL.md速查表),inject→inherit這類改名得手動同步,漏了就靜默腐爛。同時/cc-session在輸入框沒有子命令提示。變更
cmd/cc-session/commands.gocommand registry,dispatch 與printUsage()改為從它衍生。cc-session help:印意圖→命令速查表;cc-session help --argument-hint印一行[list | inherit <id> | …]供 skill 使用。/wt結構:加argument-hint(輸入框提示子命令)、## 路由(依$ARGUMENTS分派)、把靜態速查表換成!`cc-session help`即時注入。cc-session help --argument-hint覆寫已安裝 SKILL.md 的該行(awk 暫存檔+mv,跨 BSD/GNU;binary 缺或輸出異常則保留原行不炸)。改指令名時只改 registry,
printUsage、help、argument-hint 全自動跟上。已知範圍
argument-hint是灰字提示,非互動補全——Claude Code 單一 command 內不支援參數級補全(打i不會補出inherit)。真正的子命令補全需把每個子命令拆成獨立 command(/cc-session:inherit),本 PR 不含此變更。驗證
go build ./.../go vet ./cmd/cc-session/go test ./cmd/cc-session全綠,gofmt乾淨cc-session help --argument-hint輸出與SKILL.md的 hint 逐字相同help、--argument-hint格式、inject隱藏別名仍可 dispatch🤖 Generated with Claude Code