feat(templates): Add local override support for role templates

Adds ability to override embedded role templates at town or rig level:
- Town: <townRoot>/templates/roles/<role>.md.tmpl
- Rig: <rigPath>/templates/roles/<role>.md.tmpl

Rig-level overrides take precedence over town-level.

This enables customizing polecat (or other role) behavior per-rig without
modifying gastown source, following the same 3-tier override pattern as
role configs.

New APIs:
- NewWithOverrides(townRoot, rigPath string) - loads templates with overrides
- HasRoleOverride(role string) bool - check if role has override
- RoleOverrideCount() int - count of loaded overrides

Implements sc-6ghhn

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nux
2026-01-22 12:12:35 -08:00
committed by John Ogle
parent 6be7fdd76c
commit 123d0b2bed
3 changed files with 249 additions and 17 deletions

View File

@@ -18,8 +18,14 @@ import (
// outputPrimeContext outputs the role-specific context using templates or fallback.
func outputPrimeContext(ctx RoleContext) error {
// Try to use templates first
tmpl, err := templates.New()
// Calculate rig path for template overrides
var rigPath string
if ctx.Rig != "" && ctx.TownRoot != "" {
rigPath = filepath.Join(ctx.TownRoot, ctx.Rig)
}
// Try to use templates with override support
tmpl, err := templates.NewWithOverrides(ctx.TownRoot, rigPath)
if err != nil {
// Fall back to hardcoded output if templates fail
return outputPrimeContextFallback(ctx)