AGENT SKILL

CLI 子命令功能开发

bootstrap-feature

在向 openboot 添加新的 CLI 子命令或功能时使用。引导遵循标准模式:cobra 命令注册、runner 接线、archtest 感知以及测试放置。当用户说“添加命令”“新建子命令”“为 CLI 实现功能 X”,或开始在 internal/cli/ 目录下编辑时触发。

使用场景代码实现
License 许可
MIT
最近更新
2026-11-03
Stars
★ 278
Forks
14

01 前言 Front Matter

name
bootstrap-feature
description
Use when adding a new CLI subcommand or feature to openboot. Walks through the canonical pattern: cobra command registration, runner wiring, archtest awareness, and test placement. Trigger when the user says "add a command", "new subcommand", "implement feature X for the CLI", or starts editing under internal/cli/.

02 资源文件 6

03 SKILL.md 正文

Bootstrap a new openboot feature

This skill gives the canonical recipe for adding a new CLI command or feature to openboot without violating project invariants.

Step 1 — Where the code goes

Kind of thing Location
New CLI subcommand internal/cli/<verb>.go, register in internal/cli/root.go init()
Subprocess call (any binary) internal/system.RunCommand / RunCommandSilent — do not call exec.Command directly
HTTP call (any URL) internal/httputil.Do — handles 429 + Retry-After
Path under ~ os.UserHomeDir() — never os.Getenv("HOME"), never hardcode ~
User-visible output internal/ui.* helpers — never raw fmt.Println
Destructive action guarded by cfg.DryRun check
Error returned to caller wrapped: fmt.Errorf("context: %w", err)

These are enforced (or planned) by internal/archtest. The rule that covers each invariant is listed in AGENTS.md.

Step 2 — Cobra command skeleton

// internal/cli/myverb.go
package cli

import "github.com/spf13/cobra"

func newMyVerbCmd() *cobra.Command {
	var flag string
	cmd := &cobra.Command{
		Use:   "myverb [arg]",
		Short: "One-line description",
		Long:  "Longer description if useful.",
		Args:  cobra.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runMyVerb(cmd.Context(), args[0], flag)
		},
	}
	cmd.Flags().StringVar(&flag, "flag", "", "Description of the flag")
	return cmd
}

Register it in internal/cli/root.go:

rootCmd.AddCommand(newMyVerbCmd())

Step 3 — Runner interface for testability

If your feature shells out, use the Runner pattern so L1 tests can fake subprocess calls. Example from internal/brew/runner.go:

type Runner interface {
	Output(args ...string) ([]byte, error)
	CombinedOutput(args ...string) ([]byte, error)
	// ...
}

// realRunner uses exec.Command — this file is in execAllowedPaths.
type realRunner struct{}

func New() *Brew { return &Brew{r: &realRunner{}} }

Then in tests:

type fakeRunner struct { ... }
func (f *fakeRunner) Output(args ...string) ([]byte, error) { ... }

This is the pattern that lets the fake-runner half of L1 stay fast and hermetic.

Step 4 — Test placement

Scope Tier Build tag Where
Pure logic + fakes L1 none <pkg>/<feature>_test.go
Real subprocess in temp dir L1 none test/integration/<feature>_integration_test.go
Compiled binary, no installs L3 e2e test/e2e/...
Real installs on macOS L4 (VM) e2e,vm test/e2e/...

Default to faked-runner L1 unless the thing you're testing only exists when a real brew/git/npm is on the path — then add an integration test under test/integration/ (no build tag; it runs as part of L1).

Step 5 — Verify before committing

go vet ./...
make test-unit                  # ~75s, includes archtest + integration

If archtest fails with a new violation, fix the code rather than baselining — the baseline is for intentional exceptions and they require justification in the commit message.

Step 6 — Conventional commit

feat: add openboot myverb command for X

One thing per commit. If you also fixed an unrelated bug along the way, split it into a separate commit.

Common mistakes

  1. Calling exec.Command from the feature file — refactor through internal/system or add a Runner. archtest will catch this.
  2. Skipping cfg.DryRun check — destructive ops must be a no-op under --dry-run. Print "[DRY-RUN] Would X" instead of doing X.
  3. Hardcoding ~/ — always os.UserHomeDir() then filepath.Join.
  4. Raw fmt.Println — use ui.Info, ui.Success, ui.Warn, ui.Error.
  5. Forgetting to register the command in root.go — cobra silently does nothing if AddCommand is missed.

04 同仓库更多 Skills

openbootdotdev
openbootdotdev/openboot

拉取请求提交与发布

ship-pr

暂无简介

软件开发工程师代码仓库协作管理
★ 278
openbootdotdev
openbootdotdev/openboot

CLI 子命令功能开发

bootstrap-feature

暂无简介

软件开发工程师代码实现
★ 278
openbootdotdev
openbootdotdev/openboot

PR 代码规范审查

architecture-review

暂无简介

软件开发工程师代码审查
★ 278
openbootdotdev
openbootdotdev/openboot

PR 提交与合并发布

ship-pr

当用户完成编辑并希望通过拉取请求(PR)发布当前分支时使用——例如“开个 PR”“发布它”“发布这个”“提交 PR”“我们发出去吧”“合并它”“落地这个”“提 PR”“提个 PR”“提个 MR”等说法。只要用户表示某项变更已完成、应当合入默认分支,即使没有说出“PR”一词也应触发。针对任何设有强制审查门控的 GitHub 仓库,引导完成从分支到合并的完整流程——具体步骤及其规则位于技能正文中。不要在以下情形触发:对已有 PR 执行 `gh pr view` / 状态检查、用户希望创建但不合并的草稿 / WIP PR,或创建 release tag。

软件开发工程师代码仓库协作管理
★ 278
openbootdotdev
openbootdotdev/openboot

PR 代码规范审查

architecture-review

在审查 openboot 仓库中的 PR、分支或暂存的 diff 时使用。依据 AGENTS.md 中的项目不变量对变更进行审计——包括子进程使用规范、HTTP 包装器的使用、错误包装、dry-run 门控、UI 辅助函数的使用以及测试放置位置。当用户说“审查这个”“检查这个 PR”“审计这个 diff”,或询问某项变更是否遵循项目约定时触发。

软件开发工程师代码审查
★ 278