Skip to content

Custom Engine: extract template-resolution into a leaf customengine package #50

@zpzjzj

Description

@zpzjzj

Background

Two near-identical token parsers exist for the \${X} / \${X:-d} / \${X?msg} syntax:

  • internal/agent/custom.go::resolveTemplateToken — run-time, against the rendered variable map.
  • internal/config/customengine.go::resolveEnvToken — config-load-time, strict mode.

They differ only in strictness and return signature. Bugs fixed in one are easy to miss in the other.

Independently, internal/config/CustomEngineConfig is now imported by both the config and agent packages. The agentkind leaf package (#PR24) already broke the factory dispatch cycle, but the config type itself still lives in internal/config, which means anything that needs the type today must depend on config.

Proposal

  1. Introduce internal/customengine as a new leaf package that owns:
    • CustomEngineConfig, CustomLocalConfig, CustomHTTPConfig, CustomHTTPFile types (moved out of internal/config/schema.go).
    • A shared ResolveToken(inner string, vars map[string]string, opts ResolveOpts) so both call sites use one parser.
  2. Re-export shims from internal/config for one release to avoid a hard break for any external importer.

Why this is a follow-up, not a blocker

Both parsers behave correctly today and are covered by tests. The duplication is a maintenance hazard, not a defect.

Origin

Raised during the self code-review of feat/custom-engine-local (code-quality finding #1 and architecture finding #2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions