| name | moai-harness-cli-template |
| description | CLI/Template domain knowledge for moai-adk-go covering cobra commands, go:embed template system, YAML config, and template rendering pipeline.
|
| license | Apache-2.0 |
| compatibility | Designed for Claude Code |
| allowed-tools | Read, Grep, Glob, Bash |
| user-invocable | false |
| metadata | {"version":"1.0.0","category":"domain","status":"active","updated":"2026-05-14","modularized":"false","tags":"cli, template, cobra, go:embed, config, yaml, moai-cli"} |
| progressive_disclosure | {"enabled":true,"level1_tokens":100,"level2_tokens":5000} |
| triggers | {"keywords":["cobra","command","template","embed","config","yaml","moai init","moai update","moai build","rendering","internal/cli","internal/template"],"agents":["moai-harness-cli-template-specialist","expert-backend"],"phases":["run"],"languages":["go"]} |
CLI/Template Domain Knowledge
Domain-specific knowledge for moai-adk-go's CLI and template system. Supplements expert-backend with project-specific patterns.
Quick Reference
Architecture Overview
moai binary (Go)
├── internal/cli/ ~50 cobra command files
├── internal/template/
│ ├── templates/ Source of truth for all templates
│ ├── embedded.go Auto-generated (go:embed)
│ ├── context.go TemplateContext with GoBinPath, HomeDir
│ └── renderer.go Template rendering engine
└── internal/config/ Configuration loading and defaults
Key Patterns
- Template-First Rule: New files under
.claude/ or .moai/ must be added to internal/template/templates/ first, then make build
- Embedded System:
//go:embed templates/* in embedded.go -- auto-generated, never edit
- Template Variables:
{{.GoBinPath}} (init-time absolute), {{.HomeDir}} (init-time absolute)
- Fallback Paths: Use
$HOME (not .HomeDir) in .sh.tmpl files for runtime flexibility
- 16-Language Neutrality: Templates treat all 16 supported languages equally -- no "PRIMARY" language
Build Cycle
vim internal/template/templates/.claude/skills/...
make build
go test ./internal/template/...
ls -la internal/template/embedded.go
Command Structure
Each cobra command lives in internal/cli/<command>.go with corresponding tests in <command>_test.go. Commands follow the pattern:
rootCmd in root.go with subcommands registered via init()
- Each command file:
var <cmd>Cmd = &cobra.Command{...} + func init() { rootCmd.AddCommand(...) }
Configuration System
- Main config:
.moai/config/config.yaml
- Sections:
.moai/config/sections/*.yaml (quality, language, user, workflow, harness, design)
- Priority: env vars > user config > template defaults
- Env var keys:
internal/config/envkeys.go (constants, never hardcode)
Implementation Guide
Adding a New Cobra Command
- Create
internal/cli/<command>.go with cobra command struct
- Register in
init() function
- Create
internal/cli/<command>_test.go using t.TempDir()
- If command modifies templates, add template file to
internal/template/templates/
- Run
make build if templates changed
- Run
go test ./internal/cli/... to verify
Adding a New Template File
- Add file to
internal/template/templates/<path>
- If file needs variable substitution, use
.tmpl extension
- Register passthrough tokens in
renderer.go if needed (e.g., $HOME)
- Run
make build to regenerate embedded.go
- Run
go test ./internal/template/...
Template Rendering Pipeline
TemplateContext{GoBinPath, HomeDir}
-> renderer.Render(templateContent, context)
-> Output file (variable substitution applied)
Reserved passthrough tokens (not substituted, passed through verbatim):
$HOME, $PATH, $CLAUDE_PROJECT_DIR
- Environment variable references in shell scripts
Error Wrapping Convention
if err != nil {
return fmt.Errorf("deploy template: %w", err)
}
if err != nil {
return fmt.Errorf("deploy template: " + err.Error())
}
Cross-References
- CLAUDE.local.md Section 2: Template-First Rule and file synchronization
- CLAUDE.local.md Section 8: Template Variable Strategy
.claude/rules/moai/development/coding-standards.md: Coding conventions
moai-foundation-cc skill: Claude Code authoring patterns
moai-foundation-core skill: SPEC system and TRUST 5