validateAgentSection function
The strict agent: section validator, shared by check, set and
the settings flow (issues #394/#680). Mirrors the private boot parser
in cli_config.dart (pinned by test): the section takes exactly
contextWindowCap (a positive integer at or above the compaction
reserve — a cap below 16384 must never soften that floor; a cap above
the catalog window is the #729 raise path and validates unchanged),
mode (the load preset default|pi|omp, validated by the shared
agentLoadModeValidationError rule), misuseBreaker (a boolean —
gh-1572 makes the emitter render the kill switch, so the mirror has
to accept it or fa config check false-fails on fa's own output) and
stuckTool (validated with the section's own strict parser, the same
one the boot parser applies).
The per-key checks live in _agentKeyValidators — the same
table-driven shape the section dispatch above uses — so the dispatch
function itself stays flat (the gh-1572 rework's two new keys pushed
the switch form over the repo's CRAP ratchet; the table cannot drift
the same way a switch can).
Implementation
void validateAgentSection(Object? node) {
if (node is! YamlMap) {
throw ConfigException('must be a map, got: $node');
}
for (final entry in node.entries) {
final validate = _agentKeyValidators['${entry.key}'];
if (validate == null) {
throw ConfigException('unknown "agent" key: ${entry.key}');
}
validate(entry.value);
}
}