x-cmd Advise Writing Guide
This is the live instruction for AI agents writing
adv/index.ymlfiles.
For the full spec, run
x advise spec show.
For rule-based verification, run
x advise spec lint.
Core Principles
| Principle | Rule |
|-----------|------|
| Options first | In all examples (synopsis, tldr, desc), options MUST precede arguments. x mod --opt arg ✅, x mod arg --opt ❌ |
| Root-level subcmds | Subcommands are defined at root, NOT wrapped under <subcmd>: |
| Options in <option> | Options/flags live under <option> (or <option:Category>), NOT flat with subcmds. Entry with <1>/… args = option, without = flag. No <flag> field |
| Preserve order | Never reorder subcmd aliases. c|cp|copy stays c|cp|copy |
| No builtin help | -h|--help is handled by code; do NOT declare it in advise |
| Efficiency modules | Only assert, is, str are efficiency modules. Mark with <meta>: <subcmd-help>: disable. All TLDR at root only. |
| YAML safety | Quote strings containing :, !, &, *, or leading - |
Field Quick Reference
<name>:
<modname>: # 唯一裸 key = 模块名,显示名挂其值下
zh: 中文名
en: English name
<synopsis>: # MODULE level only
- x <mod> [subcmd] [options]:
<desc>:
cn: |
Description.
en: |
Description.
<tip>: # List of tips, module or subcmd level
- cn: "Tip content"
en: "Tip content"
<tldr>: # At least 3 items (simple) or 8+ (complex)
- cmd: x <mod> <subcmd>
cn: "示例: description"
en: "Example: description"
<subcmd:Category>: # Display grouping only
- subcmd1
- subcmd2
# Subcommands at ROOT level - every plain key at a layer is a subcommand.
# Options/flags go inside the <option> container (sibling of subcmds):
subcmd1:
<desc>:
cn: ...
en: ...
<1>: # Positional arg
<desc>: ...
<exec>: ___x_cmd_advise__file
<option>:
--option|-o: # option (has <1> arg below)
<desc>: ...
<1>:
<desc>: ...
--verbose|-v: # flag (no <N> args)
<desc>: ...
Required fields: <name>, <synopsis>, <desc>, <tldr> (minimum 3).
Writing Priority
- Clarity over brevity — say what the command does fully, then trim noise
- Scenario-first TLDR — each example targets one real use case, not parameter permutations
- First TLDR = simplest — no format flags, no extra options; pure natural usage
- Format flags grouped early — show
--csv,--tsvonce each in early TLDRs, then drop them - Information density — experts first; AI and agents need to know the module's ceiling
Common Error Patterns
| Error | Fix |
|-------|-----|
| <subcmd>: wrapper | Define subcmds at root level |
| Options flat with - prefix (v0 style) | Move them under an <option>: container |
| Changed alias order | Keep original: c|cp|copy not c|copy|cp |
| <synopsis> in subcmd | Use <1>, <2>, <n> in subcmds; <synopsis> is module-only |
| Efficiency TLDR in subcmd | Move all TLDR to root for assert/is/str |
| Unquoted : in desc | Wrap in quotes: "Backend: value" |
| Declaring -h\|--help | Remove; handled by lib/main |
Workflow
1. Read the spec
x advise spec show # full spec in TTY
x advise spec show | cat # plain text for piping
2. Initialize template
x advise spec init # copies tmpl.mod.yml → adv/index.yml
3. Write / edit `adv/index.yml`
Follow the field order: <name> → <meta> → <synopsis> → <desc> → <tip> → <tldr> → <subcmd:Category> → subcmd definitions.
4. Lint and verify
# From module directory
x advise spec lint
# Or specify path
x advise spec lint --path /path/to/module
Lint generates advise.jso and renders help. If it passes, the advise is structurally valid.
5. Install to local x-cmd
x scotty mod install # installs adv/index.yml into x-cmd user directory
Efficiency Module Checklist
Only assert, is, str qualify. Check before marking:
- [ ]
<meta>: <subcmd-help>: disableis present - [ ] ALL TLDR at root level
- [ ] NO
<tldr>under any subcmd - [ ] Subcmds have only
<desc>(no options, no tldr)
Standard Module Examples
Study these for specific patterns:
| Module | Pattern |
|--------|---------|
| bwh | Multi-part advise with <ref> |
| line | Subcmd categories, _ suffix tip at module level |
| dbnomics | Scenario TLDR, auto mode, format flags |
| assert | Efficiency module |
| str | Efficiency module, pipe + arg dual input |
Rules (x rule integration)
rule/advise.rule.yml lives next to this spec. Key rules:
| Rule | Level | Check |
|------|-------|-------|
| ADV-syntax-indent | error | 2-space indent, no tabs |
| ADV-field-name-required | error | <name> has cn + en |
| ADV-field-tldr-min | error | ≥3 TLDR items |
| ADV-option-prefix | error | Options precede args in all examples |
| ADV-modify-order | error | Subcmd alias order unchanged |
| ADV-efficiency-tldr-root | error | Efficiency TLDR only at root |
Run rule checks after editing:
x rule check -r /path/to/advise/lib/spec/resource/rule/ adv/index.yml
Reference Commands
x advise spec show # display spec
x advise spec init # create tmpl.mod.yml
x advise spec lint # validate and render
x advise ls # list loaded advise files
x advise cat <name> # view advise.jso content
x advise which <name> # path to advise.jso
x advise preview --file <jso> --query "checkout " # preview completion candidates (query = words after the command name; trailing space = completing an empty word)
x advise preview --file <jso> --lang zh --query "checkout " --query "chec" # language + multiple queries