Skip to content

feat: derive CLI commands and skill hint from a single registry#6

Merged
Mapleeeeeeeeeee merged 2 commits into
mainfrom
feat/command-registry-skill-hint-sync
Jul 15, 2026
Merged

feat: derive CLI commands and skill hint from a single registry#6
Mapleeeeeeeeeee merged 2 commits into
mainfrom
feat/command-registry-skill-hint-sync

Conversation

@Mapleeeeeeeeeee

Copy link
Copy Markdown
Owner

動機

cc-session 的子命令清單原本手抄在 4 個地方(main.go doc comment、dispatch switch、printUsage()SKILL.md 速查表),inject→inherit 這類改名得手動同步,漏了就靜默腐爛。同時 /cc-session 在輸入框沒有子命令提示。

變更

  • CLI 單一真相來源:新增 cmd/cc-session/commands.go command registry,dispatch 與 printUsage() 改為從它衍生。
  • cc-session help:印意圖→命令速查表;cc-session help --argument-hint 印一行 [list | inherit <id> | …] 供 skill 使用。
  • SKILL.md 改成 /wt 結構:加 argument-hint(輸入框提示子命令)、## 路由(依 $ARGUMENTS 分派)、把靜態速查表換成 !`cc-session help` 即時注入。
  • install.sh / install.ps1 安裝時同步:跑 cc-session help --argument-hint 覆寫已安裝 SKILL.md 的該行(awk 暫存檔+mv,跨 BSD/GNU;binary 缺或輸出異常則保留原行不炸)。

改指令名時只改 registry,printUsagehelp、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 逐字相同
  • install.sh 同步:正常覆寫 ✓、binary 不存在保留原行 ✓
  • 新增測試涵蓋 help--argument-hint 格式、inject 隱藏別名仍可 dispatch

🤖 Generated with Claude Code

Mapleeeeeeeeeee and others added 2 commits July 15, 2026 10:51
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
@Mapleeeeeeeeeee
Mapleeeeeeeeeee merged commit 95712a4 into main Jul 15, 2026
2 of 3 checks passed
@Mapleeeeeeeeeee
Mapleeeeeeeeeee deleted the feat/command-registry-skill-hint-sync branch July 15, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant