Problem
The executor has 241 files with no structural guide for where to add a new command. Adding a command requires: (a) creating a cmd_*.go file, (b) finding and editing the central dispatch switch, and (c) knowing the correct context type. An AI code generator (or a new contributor) must read across multiple files to understand the pattern. This increases the cognitive load and the likelihood of missing a step.
Proposed solution
Replace the central dispatch switch with a registration pattern where each cmd_*.go file self-registers its handler via init(). A new command is then entirely contained in one file — no other file needs to change.
Proposed pattern:
// cmd_entities.go
func init() {
executor.Register(ast.KindCreateEntity, handleCreateEntity)
executor.Register(ast.KindAlterEntity, handleAlterEntity)
}
func handleCreateEntity(ctx *executor.ExecContext, stmt ast.Statement) error {
s := stmt.(*ast.CreateEntityStatement)
return ctx.Backend.DomainModel().CreateEntity(s.Name, ...)
}
// executor/registry.go
var handlers = map[ast.StatementKind]HandlerFunc{}
func Register(kind ast.StatementKind, fn HandlerFunc) {
handlers[kind] = fn
}
Implementation steps
- Add
executor/registry.go with Register() and the handler map
- Replace the central dispatch switch with a registry lookup
- Migrate existing
cmd_*.go files to register via init() — one file at a time, running tests after each
- Remove the dispatch switch from
executor.go
Expected outcome
Adding a new MDL command requires creating exactly one new file. No other file needs to change. The pattern is self-documenting — any existing cmd_*.go serves as a complete example.
See proposal: docs/11-proposals/PROPOSAL_agentic_architecture_improvements.md (Change 3)
Problem
The executor has 241 files with no structural guide for where to add a new command. Adding a command requires: (a) creating a
cmd_*.gofile, (b) finding and editing the central dispatch switch, and (c) knowing the correct context type. An AI code generator (or a new contributor) must read across multiple files to understand the pattern. This increases the cognitive load and the likelihood of missing a step.Proposed solution
Replace the central dispatch switch with a registration pattern where each
cmd_*.gofile self-registers its handler viainit(). A new command is then entirely contained in one file — no other file needs to change.Proposed pattern:
Implementation steps
executor/registry.gowithRegister()and the handler mapcmd_*.gofiles to register viainit()— one file at a time, running tests after eachexecutor.goExpected outcome
Adding a new MDL command requires creating exactly one new file. No other file needs to change. The pattern is self-documenting — any existing
cmd_*.goserves as a complete example.See proposal:
docs/11-proposals/PROPOSAL_agentic_architecture_improvements.md(Change 3)