Heuristic:2aronS Duel Agents Reference Templates Match Code
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Maintainability |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Keep the shipped reference template (`duel-provider.json`) structurally identical to the object the patch builder (`buildOpenClawPatch`) produces, so the template doubles as a spec and a test fixture.
Description
The repo ships `integrations/openclaw/duel-provider.json` as a human-readable reference for what an OpenClaw provider entry should look like. `buildOpenClawPatch` in `packages/core/src/config.ts` constructs the same shape in code: a `models` block (with `mode: "merge"`, a `duel` provider keyed by `baseUrl`/`apiKey`/`api`/`models`), an `agents.defaults` block, and an `env` block holding `DUEL_PROXY_URL`. Because the two are kept in sync, the JSON file is simultaneously documentation (a user can copy it by hand), a spec (the patch builder must reproduce it), and a regression target (a test can diff the builder output against the template). The one deliberate difference is the API key: the template uses a placeholder (`${DUEL_API_KEY}`), and the builder emits that same placeholder — the key is never inlined into `openclaw.json`, only into the user's `.env`.
Usage
Use this heuristic when you ship a reference/example file alongside the code that generates the same structure — for example, a template JSON, a sample config, or a fixture. It is the right choice when the file is meant to be both human-readable and machine-generated, and you want to prevent drift between the two.
The Insight (Rule of Thumb)
- Action: Author the reference template by hand, then write the generator to reproduce it exactly; add a test that asserts equality (modulo the secret placeholder).
- Value: `duel-provider.json` and `buildOpenClawPatch(apiKey, proxyUrl)` produce the same object shape, with the key expressed as `${DUEL_API_KEY}` in both.
- Trade-off: A change to the generated shape now requires a matching edit to the template — but that is the point: the edit is forced, not optional, so drift is caught.
- Compatibility: Pair with Principle:2aronS_Duel_Agents_Secret_Isolation: the template and the builder agree that the key lives in `.env`, never in the JSON.
Reasoning
When a reference file and a generator can drift, the file becomes a lie — users copy it, the generator produces something subtly different, and the bug only shows up at runtime. Keeping them in sync turns the file into a contract: the generator is correct if and only if its output matches the file (excluding the secret), and a future change to the generator that breaks the template is a visible signal, not a silent regression. The placeholder convention (`${DUEL_API_KEY}`) is what makes the comparison safe: neither the template nor the generator contains the real key, so the file can be committed and diffed without leaking credentials.
Code Evidence
Builder output shape from `packages/core/src/config.ts:99-139`:
export function buildOpenClawPatch(apiKey, proxyUrl = getProxyUrl()) {
requireApiKey(apiKey);
return {
models: {
mode: "merge",
providers: {
duel: {
baseUrl: proxyUrl,
apiKey: "${DUEL_API_KEY}", // placeholder, never the real key
api: "openai-completions",
models: [ { id: "duel-auto", name: "Duel Auto", /* ... */ } ],
},
},
},
agents: { defaults: { model: { primary: "duel/duel-auto" }, /* ... */ } },
env: { DUEL_PROXY_URL: proxyUrl },
};
}
The shipped reference at `integrations/openclaw/duel-provider.json` mirrors the same `models`/`agents`/`env` keys, the same `duel-auto` model id, the same `${DUEL_API_KEY}` placeholder, and the same `mode: "merge"` — so the two are structurally identical and a diff between them (modulo the proxy URL) should be empty.