harness-moaiadk-patterns
The harness-moaiadk-patterns skill documents the architecture and delegation structure of moai-adk-go, a Go CLI tool with four integrated subsystems: CLI commands via Cobra, an embedded template system for project scaffolding, centralized configuration management, and bash hooks integrated with CI workflows. Use this reference when extending the moai binary's command set, modifying template artifacts, standardizing configuration defaults, or coordinating pipeline stages across quality gates and specialist agents.
git clone --depth 1 https://github.com/modu-ai/moai-adk /tmp/harness-moaiadk-patterns && cp -r /tmp/harness-moaiadk-patterns/.claude/skills/harness-moaiadk-patterns ~/.claude/skills/harness-moaiadk-patternsSKILL.md
# moai-adk-go Domain Patterns
## Architecture Quick Reference
moai-adk-go is a Go binary (`moai`) with four subsystems:
1. **CLI** (`internal/cli/*.go`, `cmd/moai/`) — Cobra commands: `init`,
`update`, `hook`, `build`, `glm`, `cc`, `cg`, `version`, `doctor`,
`spec`. Subcommand handlers read stdin JSON for hooks, emit structured
output for the orchestrator.
2. **Template system** (`internal/template/`) — `go:embed`-based scaffolding.
Source at `internal/template/templates/`, generated artifact at
`internal/template/embedded.go` (DO NOT EDIT). `make build` regenerates.
`TemplateContext` (`{{.GoBinPath}}` / `{{.HomeDir}}`) renders at `moai init`.
3. **Config** (`internal/config/`) — `defaults.go` (single source for
thresholds), `envkeys.go` (env-var constants), `TemplateContext` renderer.
4. **Hook + CI** (`.claude/hooks/moai/*.sh`, `.github/workflows/`) — bash
wrapper hooks calling `moai hook <event>`; CI guard enforces template
neutrality.
Plus the **SPEC lifecycle** (`.moai/specs/`) governing the project's own
development (plan→run→sync→Mx).
## Key Source Paths
| Subsystem | Path | Notes |
|-----------|------|-------|
| Cobra commands | `internal/cli/*.go` | wired from `cmd/moai/` |
| Template source | `internal/template/templates/**` | edit HERE first |
| Embedded assets | `internal/template/embedded.go` | generated, DO NOT EDIT |
| Config defaults | `internal/config/defaults.go` | threshold SSOT |
| Env constants | `internal/config/envkeys.go` | no hardcoded env names |
| SPEC docs | `.moai/specs/SPEC-*/` | spec/plan/acceptance/progress |
| Era classifier | `internal/spec/era.go` | `ClassifyEra()` H-1..H-6 |
| Hook scripts | `.claude/hooks/moai/*.sh` | bash only, no Python |
| CI workflows | `.github/workflows/*.yaml` | neutrality guard active |
| Harness agents | `.claude/agents/harness/*.md` | USER-OWNED (this skill) |
## Pipeline Specialist Delegation Map
This harness is a 4-stage pipeline; each specialist delegates to retained
agents (never archived, never replaces them):
```
CLI/Template ──→ quality ──→ workflow ──→ hook/CI
│ │ │ │
├─ manager-develop (tdd, backend)
├─ Explore (read-only)
├─ sync-auditor (4-dim scoring)
├─ sync-phase-quality-gate.sh (Stop hook)
├─ manager-spec (plan)
├─ manager-develop (run)
├─ manager-docs (sync)
├─ plan-auditor (audit)
├─ builder-harness (artifact_type=hook|command|plugin)
└─ Agent(general-purpose, model: opus, tools: ..., prompt: "...CI specialist...")
```
## Template-First Build Cycle
When adding/editing anything that ships to user projects:
1. Edit `internal/template/templates/<path>` FIRST.
2. Run `make build` → regenerates `internal/template/embedded.go`.
3. Sync to local: `moai update` (or manual copy).
4. Verify the local `.claude/` / `.moai/` reflects the template.
5. Run `go test ./internal/template/...` (neutrality audit included).
Never edit `.claude/` or `.moai/` directly without a template source. Never
hand-edit `embedded.go`.
## Namespace Separation Contract
Two namespaces, enforced by `moai update`:
| Namespace | Location | Owner | `moai update` behavior |
|-----------|----------|-------|------------------------|
| Template-managed | `internal/template/templates/**` → `.claude/agents/{core,expert,meta}/`, `moai-*` skills | MoAI-ADK distribution | Overwrites local on sync |
| User-owned (this harness) | `.claude/agents/harness/`, `my-harness-*` skills, `.moai/harness/` | Project developer | NEVER deleted/modified; backup before update |
The skill prefix is `my-harness-*` (Go enforcement today). The bare
`harness-*` doctrine is deferred to a future catch-up SPEC and has NO
protection yet — do NOT use bare `harness-` prefix.
## Common Workflows
### Add a template
1. Create file at `internal/template/templates/<path>`.
2. `make build`.
3. `moai update` (or test via `./moai init /tmp/test-project`).
4. `go test ./internal/template/... -run TestTemplateNeutralityAudit`.
### Add a hook
1. Write `.claude/hooks/moai/handle-<event>.sh` (bash, reads stdin JSON, calls
`moai hook <event>`).
2. Wire in `.claude/settings.json` with `"$CLAUDE_PROJECT_DIR/..."` quoting +
`timeout: 5`.
3. If the hook is template-distributable, add the wrapper template source AND
the settings.json entry to `internal/template/templates/`.
### Add an agent (harness specialist)
1. Create `.claude/agents/harness/<role>-specialist.md` with `name`,
trigger-shaped `description`, `skills:` array (companion skill), `tools:`
(CSV string).
2. Ensure the companion `my-harness-*` skill exists (else self-activation
smoke gate FAILs).
### Add a SPEC
1. `/moai plan "<description>"` → `manager-spec` authors plan-phase artifacts.
2. `plan-auditor` independent audit gate.
3. **Implementation Kickoff Approval** human gate (orchestrator runs
`AskUserQuestion`).
4. `/moai run SPEC-<ID>` → `manager-develop` (cycle_type per quality.yaml).
5. `/moai sync SPEC-<ID>` → `manager-docs`.
6. `sync-auditor` 4-dimension gate.
7. Optional Mx + 4-phase close (populate `sync_commit_sha` + `mx_commit_sha`).
## Cross-References
- CLAUDE.local.md §2 (Template-First Rule), §7 (hooks), §21 (dev-only commands)
- `.claude/rules/moai/development/agent-authoring.md` — agent frontmatter schema
- `.claude/rules/moai/development/skill-authoring.md` — skill frontmatter schema
- `.claude/rules/moai/workflow/archived-agent-rejection.md` §C — migration table
- `.claude/skills/moai-meta-harness/SKILL.md` § Namespace SeparationClaude Code upstream change tracker -> moai-adk update plan + docs sync workflow (dev-only). Tracks new CC release notes, classifies changes by impact tier, cross-references official docs, generates update plan at .moai/research/ or .moai/specs/, and synchronizes docs-site 4-locale + README. NOT distributed to user projects.
GitHub Workflow - Manage issues and review PRs with Agent Teams (dev-only). NOT distributed to user projects.
MoAI-ADK production release via Enhanced GitHub Flow (CLAUDE.local.md §18). Creates release/vX.Y.Z branch, version bump, CHANGELOG (bilingual), PR to main, merge commit (NOT squash), then scripts/release.sh for tag + GoReleaser. Hotfix support via --hotfix flag. All git operations delegated to manager-git. Quality failures escalate to expert-debug. NOT distributed to user projects (dev-only).
Run the 7-phase /moai brain ideation workflow to convert ideas into validated proposals
Identify and safely remove dead code with test verification
Scan codebase and generate architecture documentation in codemaps/
Analyze test coverage, identify gaps, and generate missing tests
Hybrid design workflow — Claude Design import (path A) or code-based brand design (path B)